man-pages/man3/errno.3

535 lines
10 KiB
Groff

.\" Copyright (c) 1996 Andries Brouwer (aeb@cwi.nl)
.\"
.\" %%%LICENSE_START(GPLv2+_DOC_FULL)
.\" This is free documentation; you can redistribute it and/or
.\" modify it under the terms of the GNU General Public License as
.\" published by the Free Software Foundation; either version 2 of
.\" the License, or (at your option) any later version.
.\"
.\" The GNU General Public License's references to "object code"
.\" and "executables" are to be interpreted as the output of any
.\" document formatting or typesetting system, including
.\" intermediate and printed output.
.\"
.\" This manual is distributed in the hope that it will be useful,
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
.\" GNU General Public License for more details.
.\"
.\" You should have received a copy of the GNU General Public
.\" License along with this manual; if not, see
.\" <http://www.gnu.org/licenses/>.
.\" %%%LICENSE_END
.\"
.\" 5 Oct 2002, Modified by Michael Kerrisk <mtk.manpages@gmail.com>
.\" Updated for POSIX.1 2001
.\" 2004-12-17 Martin Schulze <joey@infodrom.org>, mtk
.\" Removed errno declaration prototype, added notes
.\" 2006-02-09 Kurt Wall, mtk
.\" Added non-POSIX errors
.\"
.TH ERRNO 3 2008-07-09 "" "Linux Programmer's Manual"
.SH NAME
errno \- number of last error
.SH SYNOPSIS
.B #include <errno.h>
.\".sp
.\".BI "extern int " errno ;
.SH DESCRIPTION
The
.I <errno.h>
header file defines the integer variable
.IR 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
.I is
allowed to change
.IR errno .
Valid error numbers are all nonzero; \fIerrno\fP is never set to zero
by any system call or library function.
For some system calls and library functions (e.g.,
.BR getpriority (2)),
\-1 is a valid return on success.
In such cases, a successful return can be distinguished from an error
return by setting
.I 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
.I errno
has a nonzero value.
\fIerrno\fP is defined by the ISO C standard to be a modifiable lvalue
of type \fIint\fP, and must not be explicitly declared; \fIerrno\fP
may be a macro.
\fIerrno\fP 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
.B EAGAIN
and
.BR EWOULDBLOCK ,
which may be the same.
.\" The following is now
.\" POSIX.1 (2001 edition) lists the following symbolic error names. Of
.\" these, \fBEDOM\fP and \fBERANGE\fP are in the ISO C standard. ISO C
.\" Amendment 1 defines the additional error number \fBEILSEQ\fP for
.\" coding errors in multibyte or wide characters.
.\"
Below is a list of the symbolic error names that are defined on Linux.
Some of these are marked
.IR POSIX.1 ,
indicating that the name is defined by POSIX.1-2001, or
.IR C99 ,
indicating that the name is defined by C99.
.TP 16
.B E2BIG
Argument list too long (POSIX.1)
.TP
.B EACCES
Permission denied (POSIX.1)
.TP
.B EADDRINUSE
Address already in use (POSIX.1)
.TP
.B EADDRNOTAVAIL
Address not available (POSIX.1)
.\" EADV is only an error on HURD(?)
.TP
.B EAFNOSUPPORT
Address family not supported (POSIX.1)
.TP
.B EAGAIN
Resource temporarily unavailable (may be the same value as
.BR EWOULDBLOCK )
(POSIX.1)
.TP
.B EALREADY
Connection already in progress (POSIX.1)
.TP
.B EBADE
Invalid exchange
.TP
.B EBADF
Bad file descriptor (POSIX.1)
.TP
.B EBADFD
File descriptor in bad state
.TP
.B EBADMSG
Bad message (POSIX.1)
.TP
.B EBADR
Invalid request descriptor
.TP
.B EBADRQC
Invalid request code
.TP
.B EBADSLT
Invalid slot
.\" EBFONT is defined but appears not to be used by kernel or glibc.
.TP
.B EBUSY
Device or resource busy (POSIX.1)
.TP
.B ECANCELED
Operation canceled (POSIX.1)
.TP
.B ECHILD
No child processes (POSIX.1)
.TP
.B ECHRNG
Channel number out of range
.TP
.B ECOMM
Communication error on send
.TP
.B ECONNABORTED
Connection aborted (POSIX.1)
.TP
.B ECONNREFUSED
Connection refused (POSIX.1)
.TP
.B ECONNRESET
Connection reset (POSIX.1)
.TP
.B EDEADLK
Resource deadlock avoided (POSIX.1)
.TP
.B EDEADLOCK
Synonym for
.B EDEADLK
.TP
.B EDESTADDRREQ
Destination address required (POSIX.1)
.TP
.B EDOM
Mathematics argument out of domain of function (POSIX.1, C99)
.\" EDOTDOT is defined but appears to be unused
.TP
.B EDQUOT
.\" POSIX just says "Reserved"
Disk quota exceeded (POSIX.1)
.TP
.B EEXIST
File exists (POSIX.1)
.TP
.B EFAULT
Bad address (POSIX.1)
.TP
.B EFBIG
File too large (POSIX.1)
.TP
.B EHOSTDOWN
Host is down
.TP
.B EHOSTUNREACH
Host is unreachable (POSIX.1)
.TP
.B EIDRM
Identifier removed (POSIX.1)
.TP
.B EILSEQ
Illegal byte sequence (POSIX.1, C99)
.TP
.B EINPROGRESS
Operation in progress (POSIX.1)
.TP
.B EINTR
Interrupted function call (POSIX.1); see
.BR signal (7).
.TP
.B EINVAL
Invalid argument (POSIX.1)
.TP
.B EIO
Input/output error (POSIX.1)
.TP
.B EISCONN
Socket is connected (POSIX.1)
.TP
.B EISDIR
Is a directory (POSIX.1)
.TP
.B EISNAM
Is a named type file
.TP
.B EKEYEXPIRED
Key has expired
.TP
.B EKEYREJECTED
Key was rejected by service
.TP
.B EKEYREVOKED
Key has been revoked
.TP
.B EL2HLT
Level 2 halted
.TP
.B EL2NSYNC
Level 2 not synchronized
.TP
.B EL3HLT
Level 3 halted
.TP
.B EL3RST
Level 3 halted
.TP
.B ELIBACC
Cannot access a needed shared library
.TP
.B ELIBBAD
Accessing a corrupted shared library
.TP
.B ELIBMAX
Attempting to link in too many shared libraries
.TP
.B ELIBSCN
lib section in a.out corrupted
.TP
.B ELIBEXEC
Cannot exec a shared library directly
.TP
.B ELOOP
Too many levels of symbolic links (POSIX.1)
.\" ELNRNG is defined but appears to be unused
.TP
.B EMEDIUMTYPE
Wrong medium type
.TP
.B EMFILE
Too many open files (POSIX.1)
.TP
.B EMLINK
Too many links (POSIX.1)
.TP
.B EMSGSIZE
Message too long (POSIX.1)
.TP
.B EMULTIHOP
.\" POSIX says "Reserved"
Multihop attempted (POSIX.1)
.TP
.B ENAMETOOLONG
Filename too long (POSIX.1)
.\" ENAVAIL is defined, but appears not to be used
.TP
.B ENETDOWN
Network is down (POSIX.1)
.TP
.B ENETRESET
Connection aborted by network (POSIX.1)
.TP
.B ENETUNREACH
Network unreachable (POSIX.1)
.TP
.B ENFILE
Too many open files in system (POSIX.1)
.\" ENOANO is defined but appears to be unused.
.TP
.B ENOBUFS
No buffer space available (POSIX.1 (XSI STREAMS option))
.\" ENOCSI is defined but appears to be unused.
.TP
.B ENODATA
No message is available on the STREAM head read queue (POSIX.1)
.TP
.B ENODEV
No such device (POSIX.1)
.TP
.B ENOENT
No such file or directory (POSIX.1)
.TP
.B ENOEXEC
Exec format error (POSIX.1)
.TP
.B ENOKEY
Required key not available
.TP
.B ENOLCK
No locks available (POSIX.1)
.TP
.B ENOLINK
.\" POSIX says "Reserved"
Link has been severed (POSIX.1)
.TP
.B ENOMEDIUM
No medium found
.TP
.B ENOMEM
Not enough space (POSIX.1)
.TP
.B ENOMSG
No message of the desired type (POSIX.1)
.TP
.B ENONET
Machine is not on the network
.TP
.B ENOPKG
Package not installed
.TP
.B ENOPROTOOPT
Protocol not available (POSIX.1)
.TP
.B ENOSPC
No space left on device (POSIX.1)
.TP
.B ENOSR
No STREAM resources (POSIX.1 (XSI STREAMS option))
.TP
.B ENOSTR
Not a STREAM (POSIX.1 (XSI STREAMS option))
.TP
.B ENOSYS
Function not implemented (POSIX.1)
.TP
.B ENOTBLK
Block device required
.TP
.B ENOTCONN
The socket is not connected (POSIX.1)
.TP
.B ENOTDIR
Not a directory (POSIX.1)
.TP
.B ENOTEMPTY
Directory not empty (POSIX.1)
.\" ENOTNAM is defined but appears to be unused.
.TP
.B ENOTSOCK
Not a socket (POSIX.1)
.TP
.B ENOTSUP
Operation not supported (POSIX.1)
.TP
.B ENOTTY
Inappropriate I/O control operation (POSIX.1)
.TP
.B ENOTUNIQ
Name not unique on network
.TP
.B ENXIO
No such device or address (POSIX.1)
.TP
.B EOPNOTSUPP
Operation not supported on socket (POSIX.1)
.sp
.RB ( ENOTSUP
and
.B EOPNOTSUPP
have the same value on Linux, but
according to POSIX.1 these error values should be distinct.)
.TP
.B EOVERFLOW
Value too large to be stored in data type (POSIX.1)
.TP
.B EPERM
Operation not permitted (POSIX.1)
.TP
.B EPFNOSUPPORT
Protocol family not supported
.TP
.B EPIPE
Broken pipe (POSIX.1)
.TP
.B EPROTO
Protocol error (POSIX.1)
.TP
.B EPROTONOSUPPORT
Protocol not supported (POSIX.1)
.TP
.B EPROTOTYPE
Protocol wrong type for socket (POSIX.1)
.TP
.B ERANGE
Result too large (POSIX.1, C99)
.TP
.B EREMCHG
Remote address changed
.TP
.B EREMOTE
Object is remote
.TP
.B EREMOTEIO
Remote I/O error
.TP
.B ERESTART
Interrupted system call should be restarted
.TP
.B EROFS
Read-only file system (POSIX.1)
.TP
.B ESHUTDOWN
Cannot send after transport endpoint shutdown
.TP
.B ESPIPE
Invalid seek (POSIX.1)
.TP
.B ESOCKTNOSUPPORT
Socket type not supported
.TP
.B ESRCH
No such process (POSIX.1)
.\" ESRMNT is defined but appears not to be used
.TP
.B ESTALE
Stale file handle (POSIX.1)
.sp
This error can occur for NFS and for other file systems
.TP
.B ESTRPIPE
Streams pipe error
.TP
.B ETIME
Timer expired
(POSIX.1 (XSI STREAMS option))
.sp
(POSIX.1 says "STREAM
.BR ioctl (2)
timeout")
.TP
.B ETIMEDOUT
Connection timed out (POSIX.1)
.\" ETOOMANYREFS is defined, but appears not to be used.
.TP
.B ETXTBSY
Text file busy (POSIX.1)
.TP
.B EUCLEAN
Structure needs cleaning
.TP
.B EUNATCH
Protocol driver not attached
.TP
.B EUSERS
Too many users
.TP
.B EWOULDBLOCK
Operation would block (may be same value as
.BR EAGAIN )
(POSIX.1)
.TP
.B EXDEV
Improper link (POSIX.1)
.TP
.B EXFULL
Exchange full
.SH NOTES
A common mistake is to do
.in +4n
.nf
if (somecall() == \-1) {
printf("somecall() failed\en");
if (errno == ...) { ... }
}
.fi
.in
where
.I errno
no longer needs to have the value it had upon return from
.IR somecall ()
(i.e., it may have been changed by the
.BR printf (3)).
If the value of
.I errno
should be preserved across a library call, it must be saved:
.in +4n
.nf
if (somecall() == \-1) {
int errsv = errno;
printf("somecall() failed\en");
if (errsv == ...) { ... }
}
.fi
.in
.PP
It was common in traditional C to declare
.I errno
manually
(i.e.,
.IR "extern int errno" )
instead of including
.IR <errno.h> .
.BR "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
.I <errno.h>
and the declaration is needed.
.SH SEE ALSO
.BR err (3),
.BR error (3),
.BR perror (3),
.BR strerror (3)