Scroll to navigation

ERRNO(3) Linux Programmer's Manual ERRNO(3)

NAME

errno - number of last error

SYNOPSIS

#include <errno.h>

DESCRIPTION

The <errno.h> header file defines the integer variable errno, which is set by system calls and some library functions in the event of an error to indicate what went wrong. Its value is significant only when the return value of the call indicated an error (i.e., -1 from most system calls; -1 or NULL from most library functions); a function that succeeds is allowed to change errno.

Valid error numbers are all nonzero; errno is never set to zero by any system call or library function.

For some system calls and library functions (e.g., getpriority(2)), -1 is a valid return on success. In such cases, a successful return can be distinguished from an error return by setting errno to zero before the call, and then, if the call returns a status that indicates that an error may have occurred, checking to see if errno has a nonzero value.

errno is defined by the ISO C standard to be a modifiable lvalue of type int, and must not be explicitly declared; errno may be a macro. errno is thread-local; setting it in one thread does not affect its value in any other thread.

All the error names specified by POSIX.1 must have distinct values, with the exception of EAGAIN and EWOULDBLOCK, which may be the same.

Below is a list of the symbolic error names that are defined on Linux. Some of these are marked POSIX.1, indicating that the name is defined by POSIX.1-2001, or C99, indicating that the name is defined by C99.

Argument list too long (POSIX.1)
Permission denied (POSIX.1)
Address already in use (POSIX.1)
Address not available (POSIX.1)
Address family not supported (POSIX.1)
Resource temporarily unavailable (may be the same value as EWOULDBLOCK) (POSIX.1)
Connection already in progress (POSIX.1)
Invalid exchange
Bad file descriptor (POSIX.1)
File descriptor in bad state
Bad message (POSIX.1)
Invalid request descriptor
Invalid request code
Invalid slot
Device or resource busy (POSIX.1)
Operation canceled (POSIX.1)
No child processes (POSIX.1)
Channel number out of range
Communication error on send
Connection aborted (POSIX.1)
Connection refused (POSIX.1)
Connection reset (POSIX.1)
Resource deadlock avoided (POSIX.1)
Synonym for EDEADLK
Destination address required (POSIX.1)
Mathematics argument out of domain of function (POSIX.1, C99)
Disk quota exceeded (POSIX.1)
File exists (POSIX.1)
Bad address (POSIX.1)
File too large (POSIX.1)
Host is down
Host is unreachable (POSIX.1)
Identifier removed (POSIX.1)
Illegal byte sequence (POSIX.1, C99)
Operation in progress (POSIX.1)
Interrupted function call (POSIX.1); see signal(7).
Invalid argument (POSIX.1)
Input/output error (POSIX.1)
Socket is connected (POSIX.1)
Is a directory (POSIX.1)
Is a named type file
Key has expired
Key was rejected by service
Key has been revoked
Level 2 halted
Level 2 not synchronized
Level 3 halted
Level 3 halted
Cannot access a needed shared library
Accessing a corrupted shared library
Attempting to link in too many shared libraries
lib section in a.out corrupted
Cannot exec a shared library directly
Too many levels of symbolic links (POSIX.1)
Wrong medium type
Too many open files (POSIX.1)
Too many links (POSIX.1)
Message too long (POSIX.1)
Multihop attempted (POSIX.1)
Filename too long (POSIX.1)
Network is down (POSIX.1)
Connection aborted by network (POSIX.1)
Network unreachable (POSIX.1)
Too many open files in system (POSIX.1)
No buffer space available (POSIX.1 (XSI STREAMS option))
No message is available on the STREAM head read queue (POSIX.1)
No such device (POSIX.1)
No such file or directory (POSIX.1)
Exec format error (POSIX.1)
Required key not available
No locks available (POSIX.1)
Link has been severed (POSIX.1)
No medium found
Not enough space (POSIX.1)
No message of the desired type (POSIX.1)
Machine is not on the network
Package not installed
Protocol not available (POSIX.1)
No space left on device (POSIX.1)
No STREAM resources (POSIX.1 (XSI STREAMS option))
Not a STREAM (POSIX.1 (XSI STREAMS option))
Function not implemented (POSIX.1)
Block device required
The socket is not connected (POSIX.1)
Not a directory (POSIX.1)
Directory not empty (POSIX.1)
Not a socket (POSIX.1)
Operation not supported (POSIX.1)
Inappropriate I/O control operation (POSIX.1)
Name not unique on network
No such device or address (POSIX.1)
Operation not supported on socket (POSIX.1)

(ENOTSUP and EOPNOTSUPP have the same value on Linux, but according to POSIX.1 these error values should be distinct.)

Value too large to be stored in data type (POSIX.1)
Operation not permitted (POSIX.1)
Protocol family not supported
Broken pipe (POSIX.1)
Protocol error (POSIX.1)
Protocol not supported (POSIX.1)
Protocol wrong type for socket (POSIX.1)
Result too large (POSIX.1, C99)
Remote address changed
Object is remote
Remote I/O error
Interrupted system call should be restarted
Read-only file system (POSIX.1)
Cannot send after transport endpoint shutdown
Invalid seek (POSIX.1)
Socket type not supported
No such process (POSIX.1)
Stale file handle (POSIX.1)

This error can occur for NFS and for other file systems

Streams pipe error
Timer expired (POSIX.1 (XSI STREAMS option))

(POSIX.1 says "STREAM ioctl(2) timeout")

Connection timed out (POSIX.1)
Text file busy (POSIX.1)
Structure needs cleaning
Protocol driver not attached
Too many users
Operation would block (may be same value as EAGAIN) (POSIX.1)
Improper link (POSIX.1)
Exchange full

NOTES

A common mistake is to do

if (somecall() == -1) {

printf("somecall() failed\n");
if (errno == ...) { ... } }

where errno no longer needs to have the value it had upon return from somecall() (i.e., it may have been changed by the printf(3)). 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 == ...) { ... } }

It was common in traditional C to declare errno manually (i.e., extern int errno) instead of including <errno.h>. Do not do this. It will not work with modern versions of the C library. However, on (very) old UNIX systems, there may be no <errno.h> and the declaration is needed.

SEE ALSO

err(3), error(3), perror(3), strerror(3)

COLOPHON

This page is part of release 3.53 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/.

2008-07-09