Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Errno.h
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Header file for C programs}} {{C Standard Library}} {{lowercase|title=errno.h}} '''errno.h''' is a [[header file]] in the [[C standard library|standard library]] of the [[C (programming language)|C programming language]]. It defines [[Macro (computer science)|macro]]s for reporting and retrieving error conditions using the symbol <code>errno</code> (short form for "error number").<ref name=C11>International Standard for Programming Language C (C11), ISO/IEC 9899:2011, p. 205</ref> <code>errno</code> acts like an integer variable. A value (the error number) is stored in <code>errno</code> by certain [[library function]]s 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 pointer|NULL]] for functions that return [[Pointer (computer programming)|pointer]]s, and -1 for functions that return integers. A few functions require the caller to preset <code>errno</code> to zero and test it afterwards to see if an error was detected. The <code>errno</code> macro expands to an [[Value (computer science)|lvalue]] with type <code>int</code>, sometimes with the <code>extern</code> and/or <code>volatile</code> type specifiers depending upon the platform.<ref>{{cite web |url=https://www.gnu.org/software/libc/manual/html_node/Checking-for-Errors.html |title=Checking for Errors |date=2014-02-08 |website=The GNU C Library (glibc) |publisher=GNU Project |access-date=2014-06-25}}</ref> Originally this was a static memory location, but macros are almost always used today to allow for [[Multithreading (software)|multi-threading]], so that each thread will see its own [[Thread-local storage|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 /> {|class="wikitable" |- | {{tt|EDOM}} || A parameter was outside a function's domain, e.g. {{Code|lang=c|sqrt(-1)}} |- | {{tt|ERANGE}} || A result outside a function's range, e.g. {{Code|lang=c|strtol("0xfffffffff", NULL, 0)}} on systems with a 32-bit wide <code>long</code> |- | {{tt|EILSEQ}} || <small>(Required since 1994 Amendment 1 to C89 standard)</small><ref>{{cite web|url=http://www.lysator.liu.se/c/na1.html|title=A brief description of Normative Addendum 1|access-date=2013-09-12}}</ref><br/>Illegal byte sequence, e.g. {{Code|lang=c|mbstowcs(buf, "\xff", 1)}} on systems that use [[UTF-8]]. |} [[POSIX]] compliant [[operating system]]s like [[AIX]], [[Linux]] or [[Solaris (operating system)|Solaris]] include many other error values, many of which are used much more often than the above ones, such as {{tt|EACCES}} for when a file cannot be opened for reading.<ref>{{man|bd|errno.h|SUS|system error numbers}}</ref> [[C++11]] additionally defines many of the same values found within the POSIX specification.<ref>{{cite web |url=http://en.cppreference.com/w/cpp/error/errno_macros |title=Error numbers - cppreference.com |access-date=2015-05-08 }}</ref> Traditionally, the first page of [[man page|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).{{sfn|Stevens|Rago|2013|p=14}} An {{code|errno}} can be translated to a descriptive string using [[strerror]] (defined in [[string.h]]) or a BSD extension called {{code|sys_errlist}}. The translation can be printed directly to the [[standard error stream]] using [[perror]] (defined in [[stdio.h]]). As {{code|strerror}} in many Unix-like systems is not thread-safe, a thread-safe version {{code|strerror_r}} is used, but conflicting definitions from POSIX and GNU makes it even less portable than the {{code|sys_errlist}} table.<ref>{{cite web |last1=McCabe |first1=Colin |title=The problem with strerror |url=http://www.club.cc.cmu.edu/~cmccabe/blog_strerror.html |website=www.club.cc.cmu.edu}}</ref> == POSIX errors == The [[Glibc|GNU C library]] (GLIBC) provides the additional [[POSIX]] error values macros in the header file {{Code|errno.h}}.<ref>{{Cite web |title=Error Codes (The GNU C Library) |url=https://www.gnu.org/software/libc/manual/html_node/Error-Codes.html |date=Mar 29, 2025| access-date=Apr 5, 2025 |website=www.gnu.org}}</ref> These are the descriptions of the macros provided by [[strerror]]. {| class="wikitable sortable" |- ! Symbol !! Value<ref>{{cite web |author=<!-- not stated --> |title=Debugging: POSIX errors |url=https://docs.particle.io/reference/device-os/api/debugging/posix-errors/ |website=particle.io |access-date=Apr 5, 2025 }}</ref> !! Description |- | {{tt|EPERM}} || 1 || Operation not permitted |- | {{tt|ENOENT}} || 2 || No such file or directory |- | {{tt|ESRCH}} || 3 || No such process |- | {{tt|EINTR}} || 4 || Interrupted system call |- | {{tt|EIO}} || 5 || Input/output error |- | {{tt|ENXIO}} || 6 || No such device or address |- | {{tt|E2BIG}} || 7 || Argument list too long |- | {{tt|ENOEXEC}} || 8 || Exec format error |- | {{tt|EBADF}} || 9 || Bad file descriptor |- | {{tt|ECHILD}} || 10 || No child processes |- | {{tt|EAGAIN}} || 11 || Resource temporarily unavailable |- | {{tt|ENOMEM}} || 12 || Cannot allocate memory |- | {{tt|EACCES}} || 13 || Permission denied |- | {{tt|EFAULT}} || 14 || Bad address |- | {{tt|ENOTBLK}} || 15 || Block device required |- | {{tt|EBUSY}} || 16 || Device or resource busy |- | {{tt|EEXIST}} || 17 || File exists |- | {{tt|EXDEV}} || 18 || Invalid cross-device link |- | {{tt|ENODEV}} || 19 || No such device |- | {{tt|ENOTDIR}} || 20 || Not a directory |- | {{tt|EISDIR}} || 21 || Is a directory |- | {{tt|EINVAL}} || 22 || Invalid argument |- | {{tt|ENFILE}} || 23 || Too many open files in system |- | {{tt|EMFILE}} || 24 || Too many open files |- | {{tt|ENOTTY}} || 25 || Inappropriate ioctl for device |- | {{tt|ETXTBSY}} || 26 || Text file busy |- | {{tt|EFBIG}} || 27 || File too large |- | {{tt|ENOSPC}} || 28 || No space left on device |- | {{tt|ESPIPE}} || 29 || Illegal seek |- | {{tt|EROFS}} || 30 || Read-only file system |- | {{tt|EMLINK}} || 31 || Too many links |- | {{tt|EPIPE}} || 32 || Broken pipe |- | {{tt|EDOM}} || 33 || Numerical argument out of domain |- | {{tt|ERANGE}} || 34 || Numerical result out of range |- | {{tt|EDEADLK}} || 35 || Resource deadlock avoided |- | {{tt|ENAMETOOLONG}} || 36 || File name too long |- | {{tt|ENOLCK}} || 37 || No locks available |- | {{tt|ENOSYS}} || 38 || Function not implemented |- | {{tt|ENOTEMPTY}} || 39 || Directory not empty |- | {{tt|ELOOP}} || 40 || Too many levels of symbolic links |- | {{tt|ENOMSG}} || 42 || No message of desired type |- | {{tt|EIDRM}} || 43 || Identifier removed |- | {{tt|ECHRNG}} || 44 || Channel number out of range |- | {{tt|EL2NSYNC}} || 45 || Level 2 not synchronized |- | {{tt|EL3HLT}} || 46 || Level 3 halted |- | {{tt|EL3RST}} || 47 || Level 3 reset |- | {{tt|ELNRNG}} || 48 || Link number out of range |- | {{tt|EUNATCH}} || 49 || Protocol driver not attached |- | {{tt|ENOCSI}} || 50 || No CSI structure available |- | {{tt|EL2HLT}} || 51 || Level 2 halted |- | {{tt|EBADE}} || 52 || Invalid exchange |- | {{tt|EBADR}} || 53 || Invalid request descriptor |- | {{tt|EXFULL}} || 54 || Exchange full |- | {{tt|ENOANO}} || 55 || No anode |- | {{tt|EBADRQC}} || 56 || Invalid request code |- | {{tt|EBADSLT}} || 57 || Invalid slot |- | {{tt|EBFONT}} || 59 || Bad font file format |- | {{tt|ENOSTR}} || 60 || Device not a stream |- | {{tt|ENODATA}} || 61 || No data available |- | {{tt|ETIME}} || 62 || Timer expired |- | {{tt|ENOSR}} || 63 || Out of streams resources |- | {{tt|ENONET}} || 64 || Machine is not on the network |- | {{tt|ENOPKG}} || 65 || Package not installed |- | {{tt|EREMOTE}} || 66 || Object is remote |- | {{tt|ENOLINK}} || 67 || Link has been severed |- | {{tt|EADV}} || 68 || Advertise error |- | {{tt|ESRMNT}} || 69 || Srmount error |- | {{tt|ECOMM}} || 70 || Communication error on send |- | {{tt|EPROTO}} || 71 || Protocol error |- | {{tt|EMULTIHOP}} || 72 || Multihop attempted |- | {{tt|EDOTDOT}} || 73 || RFS specific error |- | {{tt|EBADMSG}} || 74 || Bad message |- | {{tt|EOVERFLOW}} || 75 || Value too large for defined data type |- | {{tt|ENOTUNIQ}} || 76 || Name not unique on network |- | {{tt|EBADFD}} || 77 || File descriptor in bad state |- | {{tt|EREMCHG}} || 78 || Remote address changed |- | {{tt|ELIBACC}} || 79 || Can not access a needed shared library |- | {{tt|ELIBBAD}} || 80 || Accessing a corrupted shared library |- | {{tt|ELIBSCN}} || 81 || .lib section in a.out corrupted |- | {{tt|ELIBMAX}} || 82 || Attempting to link in too many shared libraries |- | {{tt|ELIBEXEC}} || 83 || Cannot exec a shared library directly |- | {{tt|EILSEQ}} || 84 || Invalid or incomplete multibyte or wide character |- | {{tt|ERESTART}} || 85 || Interrupted system call should be restarted |- | {{tt|ESTRPIPE}} || 86 || Streams pipe error |- | {{tt|EUSERS}} || 87 || Too many users |- | {{tt|ENOTSOCK}} || 88 || Socket operation on non-socket |- | {{tt|EDESTADDRREQ}} || 89 || Destination address required |- | {{tt|EMSGSIZE}} || 90 || Message too long |- | {{tt|EPROTOTYPE}} || 91 || Protocol wrong type for socket |- | {{tt|ENOPROTOOPT}} || 92 || Protocol not available |- | {{tt|EPROTONOSUPPORT}} || 93 || Protocol not supported |- | {{tt|ESOCKTNOSUPPORT}} || 94 || Socket type not supported |- | {{tt|EOPNOTSUPP}} || 95 || Operation not supported |- | {{tt|EPFNOSUPPORT}} || 96 || Protocol family not supported |- | {{tt|EAFNOSUPPORT}} || 97 || Address family not supported by protocol |- | {{tt|EADDRINUSE}} || 98 || Address already in use |- | {{tt|EADDRNOTAVAIL}} || 99 || Cannot assign requested address |- | {{tt|ENETDOWN}} || 100 || Network is down |- | {{tt|ENETUNREACH}} || 101 || Network is unreachable |- | {{tt|ENETRESET}} || 102 || Network dropped connection on reset |- | {{tt|ECONNABORTED}} || 103 || Software caused connection abort |- | {{tt|ECONNRESET}} || 104 || Connection reset by peer |- | {{tt|ENOBUFS}} || 105 || No buffer space available |- | {{tt|EISCONN}} || 106 || Transport endpoint is already connected |- | {{tt|ENOTCONN}} || 107 || Transport endpoint is not connected |- | {{tt|ESHUTDOWN}} || 108 || Cannot send after transport endpoint shutdown |- | {{tt|ETOOMANYREFS}} || 109 || Too many references: cannot splice |- | {{tt|ETIMEDOUT}} || 110 || Connection timed out |- | {{tt|ECONNREFUSED}} || 111 || Connection refused |- | {{tt|EHOSTDOWN}} || 112 || Host is down |- | {{tt|EHOSTUNREACH}} || 113 || No route to host |- | {{tt|EALREADY}} || 114 || Operation already in progress |- | {{tt|EINPROGRESS}} || 115 || Operation now in progress |- | {{tt|ESTALE}} || 116 || Stale file handle |- | {{tt|EUCLEAN}} || 117 || Structure needs cleaning |- | {{tt|ENOTNAM}} || 118 || Not a XENIX named type file |- | {{tt|ENAVAIL}} || 119 || No XENIX semaphores available |- | {{tt|EISNAM}} || 120 || Is a named type file |- | {{tt|EREMOTEIO}} || 121 || Remote I/O error |- | {{tt|EDQUOT}} || 122 || Disk quota exceeded |- | {{tt|ENOMEDIUM}} || 123 || No medium found |- | {{tt|EMEDIUMTYPE}} || 124 || Wrong medium type |- | {{tt|ECANCELED}} || 125 || Operation canceled |- | {{tt|ENOKEY}} || 126 || Required key not available |- | {{tt|EKEYEXPIRED}} || 127 || Key has expired |- | {{tt|EKEYREVOKED}} || 128 || Key has been revoked |- | {{tt|EKEYREJECTED}} || 129 || Key was rejected by service |- | {{tt|EOWNERDEAD}} || 130 || Owner died |- | {{tt|ENOTRECOVERABLE}} || 131 || State not recoverable |- | {{tt|ERFKILL}} || 132 || Operation not possible due to RF-kill |- | {{tt|EHWPOISON}} || 133 || Memory page has hardware error |- | {{tt|ENOTSUP}} || 134 || Not supported parameter or option |- | {{tt|ENOMEDIUM}} || 135 || Missing media |- | {{tt|EILSEQ}} || 138 || Invalid multibyte sequence |- | {{tt|EOVERFLOW}} || 139 || Value too large |- | {{tt|ECANCELED}} || 140 || Asynchrononous operation stopped before normal completion |- | {{tt|ENOTRECOVERABLE}} || 141 || State not recoverable |- | {{tt|EOWNERDEAD}} || 142 || Previous owner died |- | {{tt|ESTRPIPE}} || 143 || Streams pipe error |} The macro names and meanings for error codes are defined in the [https://pubs.opengroup.org/onlinepubs/9799919799/ 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|date=April 2025}} 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|code readability]] and [[Software portability| portability]] the use of the standard macro names in code is highly recommended.<ref>{{cite web |author=<!-- not stated --> |date=Jan 26, 2025 |title=Checking for Errors |url=https://www.gnu.org/software/libc/manual/html_node/Checking-for-Errors.html |website=gnu.org |publisher=Free Software Foundation |access-date=Apr 6, 2025}} </ref><ref>{{cite book|arxiv=2401.10422 |doi=10.1145/3597503.3623323 |chapter=Semantic Analysis of Macro Usage for Portability |title=Proceedings of the IEEE/ACM 46th International Conference on Software Engineering |date=2024 |last1=Pappas |first1=Brent |last2=Gazzillo |first2=Paul |pages=1β12 |isbn=979-8-4007-0217-4 }} </ref> <!--The recommendation is generic, not specific but does refer extensively to porting kernel routines where error code macros are likely to be found in large numbers. --> == See also == * [[perror]] * [[strerror]] ==References== {{reflist}} == Bibliography == *{{cite book |first1=W. Richard |last1=Stevens |first2=Stephen A.|last2=Rago |title=Advanced Programming in the UNIX Environment|date=May 24, 2013 |publisher=[[Addison-Wesley Professional]] |isbn=978-0321637734 |edition=Third |url=http://www.kohala.com/start/apue.html |access-date=27 February 2015 }} ==External links== *{{man|2|intro|FreeBSD}} *{{man|3|errno|Linux}} *[https://www.gnu.org/software/libc/manual/html_node/Error-Codes.html#index-ENOBUFS-117 GNU C library manual: Error codes] *[https://nuetzlich.net/errno.html Lists of errno values on Linux, both numeric and symbolic] [[Category:C standard library headers]] [[Category:POSIX error codes| ]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:C Standard Library
(
edit
)
Template:Citation needed
(
edit
)
Template:Cite book
(
edit
)
Template:Cite web
(
edit
)
Template:Code
(
edit
)
Template:Lowercase
(
edit
)
Template:Man
(
edit
)
Template:Reflist
(
edit
)
Template:Sfn
(
edit
)
Template:Short description
(
edit
)
Template:Tt
(
edit
)