C standard library (libc) |
---|
General topics |
Miscellaneous headers |
errno.h is a
header file in the
standard library of the
C programming language. It defines
macros for reporting and retrieving error conditions using the symbol errno
(short for "error number").
[1]
errno
acts like an integer variable. A value (the error number) is stored in errno
by certain
library functions when they detect errors. At program startup, the value stored is zero. Library functions store only values greater than zero. Any library function can alter the value stored before return, whether or not they detect errors.
[2] Most functions indicate that they detected an error by returning a special value, typically
NULL for functions that return
pointers, and -1 for functions that return integers. A few functions require the caller to preset errno
to zero and test it afterwards to see if an error was detected.
The errno
macro expands to an
lvalue with type int
, sometimes with the extern
and/or volatile
type specifiers depending upon the platform.
[3] Originally this was a static memory location, but macros are almost always used today to allow for
multi-threading, so that each thread will see its own
thread-local error number.
The header file also defines macros that expand to integer constants that represent the error codes. The C standard library only requires three to be defined: [2]
EDOM
sqrt(-1)
ERANGE
strtol("0xfffffffff", NULL, 0)
on systems with a 32-bit wide long
EILSEQ (Required since 1994 Amendment 1 to C89 standard) [4]
mbstowcs(buf, "\xff", 1)
on systems that use
UTF-8.POSIX compliant operating systems like AIX, Linux or Solaris include many other error values, many of which are used much more often than the above ones, such as EACCES for when a file cannot be opened for reading. [5] C++11 additionally defines many of the same values found within the POSIX specification. [6]
Traditionally, the first page of Unix system manuals, named intro(2), lists all errno.h macros, but this is not the case with Linux, where these macros are instead listed in the errno(3). [7]
An errno
can be translated to a descriptive string using
strerror (defined in
string.h) or a BSD extension called sys_errlist
. The translation can be printed directly to the
standard error stream using
perror (defined in
stdio.h). As strerror
in many Unix-like systems is not thread-safe, a thread-safe version strerror_r
is used, but conflicting definitions from POSIX and GNU makes it even less portable than the sys_errlist
table.
[8]
The
GNU C library (GLIBC) provides the additional
POSIX error values macros in the header file errno.h
.
[9] These are the descriptions of the macros provided by
strerror, excluding 41 and 58 as they are not in the
POSIX standard:
EPERM (1)
ENOENT (2)
ESRCH (3)
EINTR (4)
EIO (5)
ENXIO (6)
E2BIG (7)
ENOEXEC (8)
EBADF (9)
ECHILD (10)
EAGAIN (11)
ENOMEM (12)
EACCES (13)
EFAULT (14)
ENOTBLK (15)
EBUSY (16)
EEXIST (17)
EXDEV (18)
ENODEV (19)
ENOTDIR (20)
EISDIR (21)
EINVAL (22)
ENFILE (23)
EMFILE (24)
ENOTTY (25)
ETXTBSY (26)
EFBIG (27)
ENOSPC (28)
ESPIPE (29)
EROFS (30)
EMLINK (31)
EPIPE (32)
EDOM (33)
ERANGE (34)
EDEADLK (35)
ENAMETOOLONG (36)
ENOLCK (37)
ENOSYS (38)
ENOTEMPTY (39)
ELOOP (40)
ENOMSG (42)
EIDRM (43)
ECHRNG (44)
EL2NSYNC (45)
EL3HLT (46)
EL3RST (47)
ELNRNG (48)
EUNATCH (49)
ENOCSI (50)
EL2HLT (51)
EBADE (52)
EBADR (53)
EXFULL (54)
ENOANO (55)
EBADRQC (56)
EBADSLT (57)
EBFONT (59)
ENOSTR (60)
ENODATA (61)
ETIME (62)
ENOSR (63)
ENONET (64)
ENOPKG (65)
EREMOTE (66)
ENOLINK (67)
EADV (68)
ESRMNT (69)
ECOMM (70)
EPROTO (71)
EMULTIHOP (72)
EDOTDOT (73)
EBADMSG (74)
EOVERFLOW (75)
ENOTUNIQ (76)
EBADFD (77)
EREMCHG (78)
ELIBACC (79)
ELIBBAD (80)
ELIBSCN (81)
ELIBMAX (82)
ELIBEXEC (83)
EILSEQ (84)
ERESTART (85)
ESTRPIPE (86)
EUSERS (87)
ENOTSOCK (88)
EDESTADDRREQ (89)
EMSGSIZE (90)
EPROTOTYPE (91)
ENOPROTOOPT (92)
EPROTONOSUPPORT (93)
ESOCKTNOSUPPORT (94)
EOPNOTSUPP (95)
EPFNOSUPPORT (96)
EAFNOSUPPORT (97)
EADDRINUSE (98)
EADDRNOTAVAIL (99)
ENETDOWN (100)
ENETUNREACH (101)
ENETRESET (102)
ECONNABORTED (103)
ECONNRESET (104)
ENOBUFS (105)
EISCONN (106)
ENOTCONN (107)
ESHUTDOWN (108)
ETOOMANYREFS (109)
ETIMEDOUT (110)
ECONNREFUSED (111)
EHOSTDOWN (112)
EHOSTUNREACH (113)
EALREADY (114)
EINPROGRESS (115)
ESTALE (116)
EUCLEAN (117)
ENOTNAM (118)
ENAVAIL (119)
EISNAM (120)
EREMOTEIO (121)
EDQUOT (122)
ENOMEDIUM (123)
EMEDIUMTYPE (124)
ECANCELED (125)
ENOKEY (126)
EKEYEXPIRED (127)
EKEYREVOKED (128)
EKEYREJECTED (129)
EOWNERDEAD (130)
ENOTRECOVERABLE (131)
ERFKILL (132)
EHWPOISON (133)
C standard library (libc) |
---|
General topics |
Miscellaneous headers |
errno.h is a
header file in the
standard library of the
C programming language. It defines
macros for reporting and retrieving error conditions using the symbol errno
(short for "error number").
[1]
errno
acts like an integer variable. A value (the error number) is stored in errno
by certain
library functions when they detect errors. At program startup, the value stored is zero. Library functions store only values greater than zero. Any library function can alter the value stored before return, whether or not they detect errors.
[2] Most functions indicate that they detected an error by returning a special value, typically
NULL for functions that return
pointers, and -1 for functions that return integers. A few functions require the caller to preset errno
to zero and test it afterwards to see if an error was detected.
The errno
macro expands to an
lvalue with type int
, sometimes with the extern
and/or volatile
type specifiers depending upon the platform.
[3] Originally this was a static memory location, but macros are almost always used today to allow for
multi-threading, so that each thread will see its own
thread-local error number.
The header file also defines macros that expand to integer constants that represent the error codes. The C standard library only requires three to be defined: [2]
EDOM
sqrt(-1)
ERANGE
strtol("0xfffffffff", NULL, 0)
on systems with a 32-bit wide long
EILSEQ (Required since 1994 Amendment 1 to C89 standard) [4]
mbstowcs(buf, "\xff", 1)
on systems that use
UTF-8.POSIX compliant operating systems like AIX, Linux or Solaris include many other error values, many of which are used much more often than the above ones, such as EACCES for when a file cannot be opened for reading. [5] C++11 additionally defines many of the same values found within the POSIX specification. [6]
Traditionally, the first page of Unix system manuals, named intro(2), lists all errno.h macros, but this is not the case with Linux, where these macros are instead listed in the errno(3). [7]
An errno
can be translated to a descriptive string using
strerror (defined in
string.h) or a BSD extension called sys_errlist
. The translation can be printed directly to the
standard error stream using
perror (defined in
stdio.h). As strerror
in many Unix-like systems is not thread-safe, a thread-safe version strerror_r
is used, but conflicting definitions from POSIX and GNU makes it even less portable than the sys_errlist
table.
[8]
The
GNU C library (GLIBC) provides the additional
POSIX error values macros in the header file errno.h
.
[9] These are the descriptions of the macros provided by
strerror, excluding 41 and 58 as they are not in the
POSIX standard:
EPERM (1)
ENOENT (2)
ESRCH (3)
EINTR (4)
EIO (5)
ENXIO (6)
E2BIG (7)
ENOEXEC (8)
EBADF (9)
ECHILD (10)
EAGAIN (11)
ENOMEM (12)
EACCES (13)
EFAULT (14)
ENOTBLK (15)
EBUSY (16)
EEXIST (17)
EXDEV (18)
ENODEV (19)
ENOTDIR (20)
EISDIR (21)
EINVAL (22)
ENFILE (23)
EMFILE (24)
ENOTTY (25)
ETXTBSY (26)
EFBIG (27)
ENOSPC (28)
ESPIPE (29)
EROFS (30)
EMLINK (31)
EPIPE (32)
EDOM (33)
ERANGE (34)
EDEADLK (35)
ENAMETOOLONG (36)
ENOLCK (37)
ENOSYS (38)
ENOTEMPTY (39)
ELOOP (40)
ENOMSG (42)
EIDRM (43)
ECHRNG (44)
EL2NSYNC (45)
EL3HLT (46)
EL3RST (47)
ELNRNG (48)
EUNATCH (49)
ENOCSI (50)
EL2HLT (51)
EBADE (52)
EBADR (53)
EXFULL (54)
ENOANO (55)
EBADRQC (56)
EBADSLT (57)
EBFONT (59)
ENOSTR (60)
ENODATA (61)
ETIME (62)
ENOSR (63)
ENONET (64)
ENOPKG (65)
EREMOTE (66)
ENOLINK (67)
EADV (68)
ESRMNT (69)
ECOMM (70)
EPROTO (71)
EMULTIHOP (72)
EDOTDOT (73)
EBADMSG (74)
EOVERFLOW (75)
ENOTUNIQ (76)
EBADFD (77)
EREMCHG (78)
ELIBACC (79)
ELIBBAD (80)
ELIBSCN (81)
ELIBMAX (82)
ELIBEXEC (83)
EILSEQ (84)
ERESTART (85)
ESTRPIPE (86)
EUSERS (87)
ENOTSOCK (88)
EDESTADDRREQ (89)
EMSGSIZE (90)
EPROTOTYPE (91)
ENOPROTOOPT (92)
EPROTONOSUPPORT (93)
ESOCKTNOSUPPORT (94)
EOPNOTSUPP (95)
EPFNOSUPPORT (96)
EAFNOSUPPORT (97)
EADDRINUSE (98)
EADDRNOTAVAIL (99)
ENETDOWN (100)
ENETUNREACH (101)
ENETRESET (102)
ECONNABORTED (103)
ECONNRESET (104)
ENOBUFS (105)
EISCONN (106)
ENOTCONN (107)
ESHUTDOWN (108)
ETOOMANYREFS (109)
ETIMEDOUT (110)
ECONNREFUSED (111)
EHOSTDOWN (112)
EHOSTUNREACH (113)
EALREADY (114)
EINPROGRESS (115)
ESTALE (116)
EUCLEAN (117)
ENOTNAM (118)
ENAVAIL (119)
EISNAM (120)
EREMOTEIO (121)
EDQUOT (122)
ENOMEDIUM (123)
EMEDIUMTYPE (124)
ECANCELED (125)
ENOKEY (126)
EKEYEXPIRED (127)
EKEYREVOKED (128)
EKEYREJECTED (129)
EOWNERDEAD (130)
ENOTRECOVERABLE (131)
ERFKILL (132)
EHWPOISON (133)