Manual - Section 3: errno

Linux Online Man Pages for openSUSE 11.2 "Emerald"

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 non-zero; 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 non-zero 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.

E2BIG

Argument list too long (POSIX.1)

EACCES

Permission denied (POSIX.1)

EADDRINUSE

Address already in use (POSIX.1)

EADDRNOTAVAIL

Address not available (POSIX.1)

EAFNOSUPPORT

Address family not supported (POSIX.1)

EAGAIN

Resource temporarily unavailable (may be the same value as
EWOULDBLOCK) (POSIX.1)

NOTES

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:

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.