The integer
errno
is set by system calls (and some library functions) to indicate
what went wrong. Its value is significant only when the call
returned an error (usually -1), and a library function that does succeed
is allowed to change
errno .
Sometimes, when -1 is also a legal return value one has to zero
errno
before the call in order to detect possible errors.
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.
Valid error numbers are all non-zero; errno is never set to zero
by any library function. All the error names specified by POSIX.1
must have distinct values.
POSIX.1 (1996 edition) lists the following symbolic error names. Of
these, EDOM and ERANGE are in the ISO C standard. ISO C
Amendment 1 defines the additional error number EILSEQ for
coding errors in multibyte or wide characters.
E2BIG
EACCES
EAGAIN
Resource temporarily unavailable
EBADF
EBADMSG
EBUSY
ECANCELED
ECHILD
EDEADLK
Resource deadlock avoided
EDOM
EEXIST
EFAULT
EFBIG
EINPROGRESS
EINTR
Interrupted function call
EINVAL
EIO
EISDIR
EMFILE
EMLINK
EMSGSIZE
Inappropriate message buffer length
ENAMETOOLONG
ENFILE
Too many open files in system
ENODEV
ENOENT
No such file or directory
ENOEXEC
ENOLCK
ENOMEM
ENOSPC
ENOSYS
ENOTDIR
ENOTEMPTY
ENOTSUP
ENOTTY
Inappropriate I/O control operation
ENXIO
No such device or address
EPERM
EPIPE
ERANGE
EROFS
ESPIPE
ESRCH
ETIMEDOUT
EXDEV
Many other error numbers are returned by various Unix implementations.
System V returns ETXTBSY (Text file busy) if one tries to exec() a file
that is currently open for writing. Linux also returns this error
if one tries to have a file both memory mapped with VM_DENYWRITE
and open for writing.