Errno.h

Revision as of 00:52, 15 May 2025 by imported>Headbomb (Altered template type. Add: isbn, pages, date, title, chapter, doi, authors 1-2. | Use this tool. Report bugs. | #UCB_Gadget)
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

Template:Short description Template:C Standard Library Template:Lowercase 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").<ref name=C11>International Standard for Programming Language C (C11), ISO/IEC 9899:2011, p. 205</ref>

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.<ref name=C99>International Standard for Programming Language C (C99), ISO/IEC 9899:1999, p. 186</ref> 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.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> 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:<ref name=C99 />

Template:Tt A parameter was outside a function's domain, e.g. <syntaxhighlight lang="c" class="" style="" inline="1">sqrt(-1)</syntaxhighlight>
Template:Tt A result outside a function's range, e.g. <syntaxhighlight lang="c" class="" style="" inline="1">strtol("0xfffffffff", NULL, 0)</syntaxhighlight> on systems with a 32-bit wide long
Template:Tt citation CitationClass=web

}}</ref>
Illegal byte sequence, e.g. <syntaxhighlight lang="c" class="" style="" inline="1">mbstowcs(buf, "\xff", 1)</syntaxhighlight> 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 Template:Tt for when a file cannot be opened for reading.<ref>Template:Man</ref> C++11 additionally defines many of the same values found within the POSIX specification.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

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).Template:Sfn

An <syntaxhighlight lang="text" class="" style="" inline="1">errno</syntaxhighlight> can be translated to a descriptive string using strerror (defined in string.h) or a BSD extension called <syntaxhighlight lang="text" class="" style="" inline="1">sys_errlist</syntaxhighlight>. The translation can be printed directly to the standard error stream using perror (defined in stdio.h). As <syntaxhighlight lang="text" class="" style="" inline="1">strerror</syntaxhighlight> in many Unix-like systems is not thread-safe, a thread-safe version <syntaxhighlight lang="text" class="" style="" inline="1">strerror_r</syntaxhighlight> is used, but conflicting definitions from POSIX and GNU makes it even less portable than the <syntaxhighlight lang="text" class="" style="" inline="1">sys_errlist</syntaxhighlight> table.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

POSIX errorsEdit

The GNU C library (GLIBC) provides the additional POSIX error values macros in the header file <syntaxhighlight lang="text" class="" style="" inline="1">errno.h</syntaxhighlight>.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> These are the descriptions of the macros provided by strerror.

Symbol citation CitationClass=web

}}</ref> !! Description

Template:Tt 1 Operation not permitted
Template:Tt 2 No such file or directory
Template:Tt 3 No such process
Template:Tt 4 Interrupted system call
Template:Tt 5 Input/output error
Template:Tt 6 No such device or address
Template:Tt 7 Argument list too long
Template:Tt 8 Exec format error
Template:Tt 9 Bad file descriptor
Template:Tt 10 No child processes
Template:Tt 11 Resource temporarily unavailable
Template:Tt 12 Cannot allocate memory
Template:Tt 13 Permission denied
Template:Tt 14 Bad address
Template:Tt 15 Block device required
Template:Tt 16 Device or resource busy
Template:Tt 17 File exists
Template:Tt 18 Invalid cross-device link
Template:Tt 19 No such device
Template:Tt 20 Not a directory
Template:Tt 21 Is a directory
Template:Tt 22 Invalid argument
Template:Tt 23 Too many open files in system
Template:Tt 24 Too many open files
Template:Tt 25 Inappropriate ioctl for device
Template:Tt 26 Text file busy
Template:Tt 27 File too large
Template:Tt 28 No space left on device
Template:Tt 29 Illegal seek
Template:Tt 30 Read-only file system
Template:Tt 31 Too many links
Template:Tt 32 Broken pipe
Template:Tt 33 Numerical argument out of domain
Template:Tt 34 Numerical result out of range
Template:Tt 35 Resource deadlock avoided
Template:Tt 36 File name too long
Template:Tt 37 No locks available
Template:Tt 38 Function not implemented
Template:Tt 39 Directory not empty
Template:Tt 40 Too many levels of symbolic links
Template:Tt 42 No message of desired type
Template:Tt 43 Identifier removed
Template:Tt 44 Channel number out of range
Template:Tt 45 Level 2 not synchronized
Template:Tt 46 Level 3 halted
Template:Tt 47 Level 3 reset
Template:Tt 48 Link number out of range
Template:Tt 49 Protocol driver not attached
Template:Tt 50 No CSI structure available
Template:Tt 51 Level 2 halted
Template:Tt 52 Invalid exchange
Template:Tt 53 Invalid request descriptor
Template:Tt 54 Exchange full
Template:Tt 55 No anode
Template:Tt 56 Invalid request code
Template:Tt 57 Invalid slot
Template:Tt 59 Bad font file format
Template:Tt 60 Device not a stream
Template:Tt 61 No data available
Template:Tt 62 Timer expired
Template:Tt 63 Out of streams resources
Template:Tt 64 Machine is not on the network
Template:Tt 65 Package not installed
Template:Tt 66 Object is remote
Template:Tt 67 Link has been severed
Template:Tt 68 Advertise error
Template:Tt 69 Srmount error
Template:Tt 70 Communication error on send
Template:Tt 71 Protocol error
Template:Tt 72 Multihop attempted
Template:Tt 73 RFS specific error
Template:Tt 74 Bad message
Template:Tt 75 Value too large for defined data type
Template:Tt 76 Name not unique on network
Template:Tt 77 File descriptor in bad state
Template:Tt 78 Remote address changed
Template:Tt 79 Can not access a needed shared library
Template:Tt 80 Accessing a corrupted shared library
Template:Tt 81 .lib section in a.out corrupted
Template:Tt 82 Attempting to link in too many shared libraries
Template:Tt 83 Cannot exec a shared library directly
Template:Tt 84 Invalid or incomplete multibyte or wide character
Template:Tt 85 Interrupted system call should be restarted
Template:Tt 86 Streams pipe error
Template:Tt 87 Too many users
Template:Tt 88 Socket operation on non-socket
Template:Tt 89 Destination address required
Template:Tt 90 Message too long
Template:Tt 91 Protocol wrong type for socket
Template:Tt 92 Protocol not available
Template:Tt 93 Protocol not supported
Template:Tt 94 Socket type not supported
Template:Tt 95 Operation not supported
Template:Tt 96 Protocol family not supported
Template:Tt 97 Address family not supported by protocol
Template:Tt 98 Address already in use
Template:Tt 99 Cannot assign requested address
Template:Tt 100 Network is down
Template:Tt 101 Network is unreachable
Template:Tt 102 Network dropped connection on reset
Template:Tt 103 Software caused connection abort
Template:Tt 104 Connection reset by peer
Template:Tt 105 No buffer space available
Template:Tt 106 Transport endpoint is already connected
Template:Tt 107 Transport endpoint is not connected
Template:Tt 108 Cannot send after transport endpoint shutdown
Template:Tt 109 Too many references: cannot splice
Template:Tt 110 Connection timed out
Template:Tt 111 Connection refused
Template:Tt 112 Host is down
Template:Tt 113 No route to host
Template:Tt 114 Operation already in progress
Template:Tt 115 Operation now in progress
Template:Tt 116 Stale file handle
Template:Tt 117 Structure needs cleaning
Template:Tt 118 Not a XENIX named type file
Template:Tt 119 No XENIX semaphores available
Template:Tt 120 Is a named type file
Template:Tt 121 Remote I/O error
Template:Tt 122 Disk quota exceeded
Template:Tt 123 No medium found
Template:Tt 124 Wrong medium type
Template:Tt 125 Operation canceled
Template:Tt 126 Required key not available
Template:Tt 127 Key has expired
Template:Tt 128 Key has been revoked
Template:Tt 129 Key was rejected by service
Template:Tt 130 Owner died
Template:Tt 131 State not recoverable
Template:Tt 132 Operation not possible due to RF-kill
Template:Tt 133 Memory page has hardware error
Template:Tt 134 Not supported parameter or option
Template:Tt 135 Missing media
Template:Tt 138 Invalid multibyte sequence
Template:Tt 139 Value too large
Template:Tt 140 Asynchrononous operation stopped before normal completion
Template:Tt 141 State not recoverable
Template:Tt 142 Previous owner died
Template:Tt 143 Streams pipe error

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.Template: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.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }} </ref><ref>Template:Cite book </ref>

See alsoEdit

ReferencesEdit

Template:Reflist

BibliographyEdit

External linksEdit