errno(3)
๐ errno โ number of last error ๐
okay bestie, sit down, hydrate, because we're about to talk about the single most relatable integer in all of C: errno. ๐ซถ This is the page for errno(3), out of the Library Functions Manual, and yes it is long, but you're gonna eat it up, I promise. โจ
๐ธ NAME ๐ธ
errno โ number of last error ๐
๐ LIBRARY ๐
Standard C library (libc, -lc) ๐ฆ
โจ SYNOPSIS โจ
#include <errno.h>
๐ DESCRIPTION ๐
So the <errno.h> header file defines this integer variable called errno, and the whole vibe is: when a system call or some library function hits an error, it sets errno to tell you what went wrong. It's like the error-coded group chat notification of the C world. ๐ญ
๐ errno (the variable itself, she's the main character)
Here's the thing that trips everyone up, so listen: the value in errno is only significant when the return value of the call indicated an error. Like, -1 from most system calls, or -1 or NULL from most library functions. A function that succeeds is fully allowed to change errno (rude, but legal ๐). And errno is never set to zero by any system call or library function. Never. She does not do that. ๐ซ
Now for the cursed ones: some system calls and library functions (looking at you, getpriority(2)) can return -1 on success. Iconic chaos. So how do you tell a success from an error in that case? You play the game:
- set
errnoto zero before the call, - then, if the call returns a status that indicates an error may have occurred, check whether
errnohas a nonzero value.
That's the move. That's the whole trick. โจ
Also important, no cap: errno is defined by the ISO C standard to be a modifiable lvalue of type int, and you must not explicitly declare it โ because errno may be a macro. And she's thread-local: setting it in one thread does not affect its value in any other thread. She does not gossip between threads. ๐
๐ฆ Error numbers and names
Valid error numbers are all positive numbers. The <errno.h> header file defines symbolic names for each of the possible error numbers that may show up in errno. ๐
All the error names specified by POSIX.1 must have distinct values โ with one exception: EAGAIN and EWOULDBLOCK, which may be the same. On Linux, these two have the same value on all architectures. (Twins. Same value, different names. Obsessed. ๐)
The error numbers that correspond to each symbolic name vary across UNIX systems, and even across different architectures on Linux. So the numbers are not included in the list below, periodt. If you need to turn these names into textual error messages, that's what perror(3) and strerror(3) are for. ๐ซถ
On any particular Linux system, you can get a list of all symbolic error names and their corresponding error numbers with the errno(1) command (part of the moreutils package):
$ errno -l;
EPERM 1 Operation not permitted
ENOENT 2 No such file or directory
ESRCH 3 No such process
EINTR 4 Interrupted system call
EIO 5 Input/output error
...
And the errno(1) command is also lowkey a lookup queen โ she can look up individual error numbers and names, and even search using strings from the error description, like this:
$ errno 2;
ENOENT 2 No such file or directory
$ errno ESRCH;
ESRCH 3 No such process
$ errno -s permission;
EACCES 13 Permission denied
๐ List of error names
In the list of symbolic error names below, some names get marked, so here's the legend:
- POSIX.1-2001 โ The name is defined by POSIX.1-2001, and is defined in later POSIX.1 versions, unless otherwise indicated.
- POSIX.1-2008 โ The name is defined in POSIX.1-2008, but was not present in earlier POSIX.1 standards.
- C99 โ The name is defined by C99.
And below is the list of the symbolic error names that are defined on Linux. Buckle up, she's long, but every single one is here. ๐
E2BIGโ Argument list too long (POSIX.1-2001).EACCESโ Permission denied (POSIX.1-2001).EADDRINUSEโ Address already in use (POSIX.1-2001).EADDRNOTAVAILโ Address not available (POSIX.1-2001).EAFNOSUPPORTโ Address family not supported (POSIX.1-2001).EAGAINโ Resource temporarily unavailable (may be the same value asEWOULDBLOCK) (POSIX.1-2001).EALREADYโ Connection already in progress (POSIX.1-2001).EBADEโ Invalid exchange.EBADFโ Bad file descriptor (POSIX.1-2001).EBADFDโ File descriptor in bad state.EBADMSGโ Bad message (POSIX.1-2001).EBADRโ Invalid request descriptor.EBADRQCโ Invalid request code.EBADSLTโ Invalid slot.EBUSYโ Device or resource busy (POSIX.1-2001).ECANCELEDโ Operation canceled (POSIX.1-2001).ECHILDโ No child processes (POSIX.1-2001).ECHRNGโ Channel number out of range.ECOMMโ Communication error on send.ECONNABORTEDโ Connection aborted (POSIX.1-2001).ECONNREFUSEDโ Connection refused (POSIX.1-2001).ECONNRESETโ Connection reset (POSIX.1-2001).EDEADLKโ Resource deadlock avoided (POSIX.1-2001).EDEADLOCKโ On most architectures, a synonym forEDEADLK. On some architectures (e.g., Linux MIPS, PowerPC, SPARC), it is a separate error code "File locking deadlock error".EDESTADDRREQโ Destination address required (POSIX.1-2001).EDOMโ Mathematics argument out of domain of function (POSIX.1, C99).EDQUOTโ Disk quota exceeded (POSIX.1-2001).EEXISTโ File exists (POSIX.1-2001).EFAULTโ Bad address (POSIX.1-2001).EFBIGโ File too large (POSIX.1-2001).EHOSTDOWNโ Host is down.EHOSTUNREACHโ Host is unreachable (POSIX.1-2001).EHWPOISONโ Memory page has hardware error.EIDRMโ Identifier removed (POSIX.1-2001).EILSEQโ Invalid or incomplete multibyte or wide character (POSIX.1, C99).- The text shown here is the glibc error description; in POSIX.1, this error is described as "Illegal byte sequence".
EINPROGRESSโ Operation in progress (POSIX.1-2001).EINTRโ Interrupted function call (POSIX.1-2001); seesignal(7).EINVALโ Invalid argument (POSIX.1-2001).EIOโ Input/output error (POSIX.1-2001).EISCONNโ Socket is connected (POSIX.1-2001).EISDIRโ Is a directory (POSIX.1-2001).EISNAMโ Is a named type file.EKEYEXPIREDโ Key has expired.EKEYREJECTEDโ Key was rejected by service.EKEYREVOKEDโ Key has been revoked.EL2HLTโ Level 2 halted.EL2NSYNCโ Level 2 not synchronized.EL3HLTโ Level 3 halted.EL3RSTโ Level 3 reset.ELIBACCโ Cannot access a needed shared library.ELIBBADโ Accessing a corrupted shared library.ELIBMAXโ Attempting to link in too many shared libraries.ELIBSCNโ .lib section in a.out corruptedELIBEXECโ Cannot exec a shared library directly.ELNRNGโ Link number out of range.ELOOPโ Too many levels of symbolic links (POSIX.1-2001).EMEDIUMTYPEโ Wrong medium type.EMFILEโ Too many open files (POSIX.1-2001). Commonly caused by exceeding theRLIMIT_NOFILEresource limit described ingetrlimit(2). Can also be caused by exceeding the limit specified in/proc/sys/fs/nr_open.EMLINKโ Too many links (POSIX.1-2001).EMSGSIZEโ Message too long (POSIX.1-2001).EMULTIHOPโ Multihop attempted (POSIX.1-2001).ENAMETOOLONGโ Filename too long (POSIX.1-2001).ENETDOWNโ Network is down (POSIX.1-2001).ENETRESETโ Connection aborted by network (POSIX.1-2001).ENETUNREACHโ Network unreachable (POSIX.1-2001).ENFILEโ Too many open files in system (POSIX.1-2001). On Linux, this is probably a result of encountering the/proc/sys/fs/file-maxlimit (seeproc(5)).ENOANOโ No anode.ENOBUFSโ No buffer space available (POSIX.1 (XSI STREAMS option)).ENODATAโ The named attribute does not exist, or the process has no access to this attribute; seexattr(7).- In POSIX.1-2001 (XSI STREAMS option), this error was described as "No message is available on the STREAM head read queue".
ENODEVโ No such device (POSIX.1-2001).ENOENTโ No such file or directory (POSIX.1-2001).- Typically, this error results when a specified pathname does not exist, or one of the components in the directory prefix of a pathname does not exist, or the specified pathname is a dangling symbolic link.
ENOEXECโ Exec format error (POSIX.1-2001).ENOKEYโ Required key not available.ENOLCKโ No locks available (POSIX.1-2001).ENOLINKโ Link has been severed (POSIX.1-2001).ENOMEDIUMโ No medium found.ENOMEMโ Not enough space/cannot allocate memory (POSIX.1-2001).ENOMSGโ No message of the desired type (POSIX.1-2001).ENONETโ Machine is not on the network.ENOPKGโ Package not installed.ENOPROTOOPTโ Protocol not available (POSIX.1-2001).ENOSPCโ No space left on device (POSIX.1-2001).ENOSRโ No STREAM resources (POSIX.1 (XSI STREAMS option)).ENOSTRโ Not a STREAM (POSIX.1 (XSI STREAMS option)).ENOSYSโ Function not implemented (POSIX.1-2001).ENOTBLKโ Block device required.ENOTCONNโ The socket is not connected (POSIX.1-2001).ENOTDIRโ Not a directory (POSIX.1-2001).ENOTEMPTYโ Directory not empty (POSIX.1-2001).ENOTRECOVERABLEโ State not recoverable (POSIX.1-2008).ENOTSOCKโ Not a socket (POSIX.1-2001).ENOTSUPโ Operation not supported (POSIX.1-2001).ENOTTYโ Inappropriate I/O control operation (POSIX.1-2001).ENOTUNIQโ Name not unique on network.ENXIOโ No such device or address (POSIX.1-2001).EOPNOTSUPPโ Operation not supported (POSIX.1-2001). According to POSIX.1 this is "Operation not supported on socket", but on Linux it effectively means just "Operation not supported".- (
ENOTSUPandEOPNOTSUPPhave the same value on Linux.)
- (
EOVERFLOWโ Value too large to be stored in data type (POSIX.1-2001).EOWNERDEADโ Owner died (POSIX.1-2008).EPERMโ Operation not permitted (POSIX.1-2001).EPFNOSUPPORTโ Protocol family not supported.EPIPEโ Broken pipe (POSIX.1-2001).EPROTOโ Protocol error (POSIX.1-2001).EPROTONOSUPPORTโ Protocol not supported (POSIX.1-2001).EPROTOTYPEโ Protocol wrong type for socket (POSIX.1-2001).ERANGEโ Result too large (POSIX.1, C99).EREMCHGโ Remote address changed.EREMOTEโ Object is remote.EREMOTEIOโ Remote I/O error.ERESTARTโ Interrupted system call should be restarted.ERFKILLโ Operation not possible due to RF-kill.EROFSโ Read-only filesystem (POSIX.1-2001).ESHUTDOWNโ Cannot send after transport endpoint shutdown.ESPIPEโ invalid seek ๐ (POSIX.1-2001). yeah bestie, you tried to seek on a pipe, she said no.ESOCKTNOSUPPORTโ socket type not supported. that kind of socket? not a thing here, sorry babe.ESRCHโ no such process (POSIX.1-2001). the process is giving ghost, fr fr.ESTALEโ stale file handle (POSIX.1-2001).
okay so this one can happen with NFS and also with other filesystems. she's expired, not coming back, move on. โจ
ESTRPIPEโ streams pipe error.ETIMEโ timer expired (POSIX.1 (XSI STREAMS option)).
(POSIX.1 says "STREAM ioctl(2) timeout".) ๐ฐ๏ธ
ETIMEDOUTโ connection timed out (POSIX.1-2001). we waited, she never showed. ๐ETOOMANYREFSโ too many references: cannot splice. iconic amount of references tbh, just too many.ETXTBSYโ text file busy (POSIX.1-2001). she's booked, do not disturb ๐ซEUCLEANโ structure needs cleaning. the structural equivalent of a self-care day ๐งผEUNATCHโ protocol driver not attached.EUSERSโ too many users. the function said "pls, no more people" ๐ญEWOULDBLOCKโ operation would block (may be same value asEAGAIN) (POSIX.1-2001). note that "may be same value asEAGAIN", so don't go assuming, check it.EXDEVโ invalid cross-device link (POSIX.1-2001). different devices? that link is not linking, bestie.EXFULLโ exchange full. no room at the inn ๐
๐ NOTES ๐
okay so here's the mistake literally everyone makes and honestly it's the villain origin story of so many bugs. a common mistake is doing this:
if (somecall() == -1) {
printf("somecall() failed\n");
if (errno == ...) { ...; }
}
and the problem is that by the time you get there, errno no longer needs to have the value it had when somecall() returned โ i.e., it may have been changed by the printf(3). she got overwritten. so if the value of errno should be preserved across a library call, it must be saved:
if (somecall() == -1) {
int errsv = errno;
printf("somecall() failed\n");
if (errsv == ...) { ...; }
}
see how we snooped it into errsv first? that's the move. save the girl before she gets replaced. ๐ซถ
also, heads up: the POSIX threads APIs do not set errno on error. nope. instead, on failure they return an error number as the function result. and those error numbers? same meanings as the error numbers returned in errno by other APIs. so don't go staring at errno waiting for pthreads to fill it in โ she's not participating in that conversation. โจ
and finally, a lil history lesson for the girlies: on some ancient systems, <errno.h> was not present, or didn't declare errno at all, which meant you had to declare errno manually, like literally:
extern int errno
do not do this. it long ago ceased to be necessary, and it will cause problems with modern versions of the C library. so like, respectfully, don't. ๐
๐ SEE ALSO ๐
and that's the whole page bestie, you ate it ๐ this was Linux man-pages 6.20, dated 2026-05-28 โ go forth and check your error codes responsibly ๐โจ๐ฆ
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: GPL-2.0-or-later
- Copyright 1996, Andries E. Brouwer <aeb@cwi.nl>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms