Errno.h

Header file for C programs From Wikipedia, the free encyclopedia

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 form 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]

EDOMA parameter was outside a function's domain, e.g. sqrt(-1)
ERANGEA result outside a function's range, e.g. strtol("0xfffffffff", NULL, 0) on systems with a 32-bit wide long
EILSEQ(Required since 1994 Amendment 1 to C89 standard)[4]
Illegal byte sequence, e.g. 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]

POSIX errors

Summarize
Perspective

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.

More information Symbol, Value ...
SymbolValue[10]Description
EPERM1Operation not permitted
ENOENT2No such file or directory
ESRCH3No such process
EINTR4Interrupted system call
EIO5Input/output error
ENXIO6No such device or address
E2BIG7Argument list too long
ENOEXEC8Exec format error
EBADF9Bad file descriptor
ECHILD10No child processes
EAGAIN11Resource temporarily unavailable
ENOMEM12Cannot allocate memory
EACCES13Permission denied
EFAULT14Bad address
ENOTBLK15Block device required
EBUSY16Device or resource busy
EEXIST17File exists
EXDEV18Invalid cross-device link
ENODEV19No such device
ENOTDIR20Not a directory
EISDIR21Is a directory
EINVAL22Invalid argument
ENFILE23Too many open files in system
EMFILE24Too many open files
ENOTTY25Inappropriate ioctl for device
ETXTBSY26Text file busy
EFBIG27File too large
ENOSPC28No space left on device
ESPIPE29Illegal seek
EROFS30Read-only file system
EMLINK31Too many links
EPIPE32Broken pipe
EDOM33Numerical argument out of domain
ERANGE34Numerical result out of range
EDEADLK35Resource deadlock avoided
ENAMETOOLONG36File name too long
ENOLCK37No locks available
ENOSYS38Function not implemented
ENOTEMPTY39Directory not empty
ELOOP40Too many levels of symbolic links
ENOMSG42No message of desired type
EIDRM43Identifier removed
ECHRNG44Channel number out of range
EL2NSYNC45Level 2 not synchronized
EL3HLT46Level 3 halted
EL3RST47Level 3 reset
ELNRNG48Link number out of range
EUNATCH49Protocol driver not attached
ENOCSI50No CSI structure available
EL2HLT51Level 2 halted
EBADE52Invalid exchange
EBADR53Invalid request descriptor
EXFULL54Exchange full
ENOANO55No anode
EBADRQC56Invalid request code
EBADSLT57Invalid slot
EBFONT59Bad font file format
ENOSTR60Device not a stream
ENODATA61No data available
ETIME62Timer expired
ENOSR63Out of streams resources
ENONET64Machine is not on the network
ENOPKG65Package not installed
EREMOTE66Object is remote
ENOLINK67Link has been severed
EADV68Advertise error
ESRMNT69Srmount error
ECOMM70Communication error on send
EPROTO71Protocol error
EMULTIHOP72Multihop attempted
EDOTDOT73RFS specific error
EBADMSG74Bad message
EOVERFLOW75Value too large for defined data type
ENOTUNIQ76Name not unique on network
EBADFD77File descriptor in bad state
EREMCHG78Remote address changed
ELIBACC79Can not access a needed shared library
ELIBBAD80Accessing a corrupted shared library
ELIBSCN81.lib section in a.out corrupted
ELIBMAX82Attempting to link in too many shared libraries
ELIBEXEC83Cannot exec a shared library directly
EILSEQ84Invalid or incomplete multibyte or wide character
ERESTART85Interrupted system call should be restarted
ESTRPIPE86Streams pipe error
EUSERS87Too many users
ENOTSOCK88Socket operation on non-socket
EDESTADDRREQ89Destination address required
EMSGSIZE90Message too long
EPROTOTYPE91Protocol wrong type for socket
ENOPROTOOPT92Protocol not available
EPROTONOSUPPORT93Protocol not supported
ESOCKTNOSUPPORT94Socket type not supported
EOPNOTSUPP95Operation not supported
EPFNOSUPPORT96Protocol family not supported
EAFNOSUPPORT97Address family not supported by protocol
EADDRINUSE98Address already in use
EADDRNOTAVAIL99Cannot assign requested address
ENETDOWN100Network is down
ENETUNREACH101Network is unreachable
ENETRESET102Network dropped connection on reset
ECONNABORTED103Software caused connection abort
ECONNRESET104Connection reset by peer
ENOBUFS105No buffer space available
EISCONN106Transport endpoint is already connected
ENOTCONN107Transport endpoint is not connected
ESHUTDOWN108Cannot send after transport endpoint shutdown
ETOOMANYREFS109Too many references: cannot splice
ETIMEDOUT110Connection timed out
ECONNREFUSED111Connection refused
EHOSTDOWN112Host is down
EHOSTUNREACH113No route to host
EALREADY114Operation already in progress
EINPROGRESS115Operation now in progress
ESTALE116Stale file handle
EUCLEAN117Structure needs cleaning
ENOTNAM118Not a XENIX named type file
ENAVAIL119No XENIX semaphores available
EISNAM120Is a named type file
EREMOTEIO121Remote I/O error
EDQUOT122Disk quota exceeded
ENOMEDIUM123No medium found
EMEDIUMTYPE124Wrong medium type
ECANCELED125Operation canceled
ENOKEY126Required key not available
EKEYEXPIRED127Key has expired
EKEYREVOKED128Key has been revoked
EKEYREJECTED129Key was rejected by service
EOWNERDEAD130Owner died
ENOTRECOVERABLE131State not recoverable
ERFKILL132Operation not possible due to RF-kill
EHWPOISON133Memory page has hardware error
ENOTSUP134Not supported parameter or option
ENOMEDIUM135Missing media
EILSEQ138Invalid multibyte sequence
EOVERFLOW139Value too large
ECANCELED140Asynchrononous operation stopped before normal completion
ENOTRECOVERABLE141State not recoverable
EOWNERDEAD142Previous owner died
ESTRPIPE143Streams pipe error
Close

The macro names and meanings for error codes are defined in the POSIX Standards definition however the numeric values are NOT, though by convention the values appear to be the same across different versions of Unix.[citation needed] Programs should not rely on specific numeric values and should test code using the macro names specified in the ERRORS section of the man page of the associated function. For source code readability and portability the use of the standard macro names in code is highly recommended.[11][12]

See also

References

Bibliography

Loading related searches...

Wikiwand - on

Seamless Wikipedia browsing. On steroids.