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 errno to zero before the call,
  • then, if the call returns a status that indicates an error may have occurred, check whether errno has 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 as EWOULDBLOCK) (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 for EDEADLK. 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); see signal(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 corrupted
  • ELIBEXEC โ€” 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 the RLIMIT_NOFILE resource limit described in getrlimit(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-max limit (see proc(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; see xattr(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".
    • (ENOTSUP and EOPNOTSUPP have 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 as EAGAIN) (POSIX.1-2001). note that "may be same value as EAGAIN", 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
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms