man-pages/man3/errno.3.html
2021-03-31 01:06:50 +01:00

873 lines
16 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of ERRNO</TITLE>
</HEAD><BODY>
<H1>ERRNO</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2019-10-10<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
errno - number of last error
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<B>#include &lt;<A HREF="file:///usr/include/errno.h">errno.h</A>&gt;</B>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
The
<I>&lt;<A HREF="file:///usr/include/errno.h">errno.h</A>&gt;</I>
header file defines the integer variable
<I>errno</I>,
which is set by system calls and some library functions in the event
of an error to indicate what went wrong.
<A NAME="lbAE">&nbsp;</A>
<H3>errno</H3>
The value in
<I>errno</I>
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</I>
allowed to change
<I>errno</I>.
The value of
<I>errno</I>
is never set to zero by any system call or library function.
<P>
For some system calls and library functions (e.g.,
<B><A HREF="/cgi-bin/man/man2html?2+getpriority">getpriority</A></B>(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</I>
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</I>
has a nonzero value.
<P>
<I>errno</I>
is defined by the ISO C standard to be a modifiable lvalue
of type
<I>int</I>,
and must not be explicitly declared;
<I>errno</I>
may be a macro.
<I>errno</I>
is thread-local; setting it in one thread
does not affect its value in any other thread.
<A NAME="lbAF">&nbsp;</A>
<H3>Error numbers and names</H3>
Valid error numbers are all positive numbers.
The
<I>&lt;<A HREF="file:///usr/include/errno.h">errno.h</A>&gt;</I>
header file defines symbolic names for each
of the possible error numbers that may appear in
<I>errno</I>.
<P>
All the error names specified by POSIX.1
must have distinct values, with the exception of
<B>EAGAIN</B>
and
<B>EWOULDBLOCK</B>,
which may be the same.
On Linux, these two have the same value on all architectures.
<P>
The error numbers that correspond to each symbolic name
vary across UNIX systems,
and even across different architectures on Linux.
Therefore, numeric values are not included as part of the list of
error names below.
The
<B><A HREF="/cgi-bin/man/man2html?3+perror">perror</A></B>(3)
and
<B><A HREF="/cgi-bin/man/man2html?3+strerror">strerror</A></B>(3)
functions can be used to convert these names to
corresponding textual error messages.
<P>
On any particular Linux system,
one can obtain a list of all symbolic error names and
the corresponding error numbers using the
<B><A HREF="/cgi-bin/man/man2html?1+errno">errno</A></B>(1)
command (part of the
<I>moreutils</I>
package):
<P>
$ <B>errno -l</B>
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
...
<P>
The
<B><A HREF="/cgi-bin/man/man2html?1+errno">errno</A></B>(1)
command can also be used to look up individual error numbers and names,
and to search for errors using strings from the error description,
as in the following examples:
<P>
$ <B>errno 2</B>
ENOENT 2 No such file or directory
$ <B>errno ESRCH</B>
ESRCH 3 No such process
$ <B>errno -s permission</B>
EACCES 13 Permission denied
<P>
<A NAME="lbAG">&nbsp;</A>
<H3>List of error names</H3>
In the list of the symbolic error names below,
various names are marked as follows:
<DL COMPACT>
<DT id="1">*<DD>
<I>POSIX.1-2001</I>:
The name is defined by POSIX.1-2001,
and is defined in later POSIX.1 versions, unless otherwise indicated.
<DT id="2">*<DD>
<I>POSIX.1-2008</I>:
The name is defined in POSIX.1-2008,
but was not present in earlier POSIX.1 standards.
<DT id="3">*<DD>
<I>C99</I>:
The name is defined by C99.
Below is a list of the symbolic error names that are defined on Linux:
<DT id="4"><B>E2BIG</B>
<DD>
Argument list too long (POSIX.1-2001).
<DT id="5"><B>EACCES</B>
<DD>
Permission denied (POSIX.1-2001).
<DT id="6"><B>EADDRINUSE</B>
<DD>
Address already in use (POSIX.1-2001).
<DT id="7"><B>EADDRNOTAVAIL</B>
<DD>
Address not available (POSIX.1-2001).
<DT id="8"><B>EAFNOSUPPORT</B>
<DD>
Address family not supported (POSIX.1-2001).
<DT id="9"><B>EAGAIN</B>
<DD>
Resource temporarily unavailable (may be the same value as
<B>EWOULDBLOCK</B>)
(POSIX.1-2001).
<DT id="10"><B>EALREADY</B>
<DD>
Connection already in progress (POSIX.1-2001).
<DT id="11"><B>EBADE</B>
<DD>
Invalid exchange.
<DT id="12"><B>EBADF</B>
<DD>
Bad file descriptor (POSIX.1-2001).
<DT id="13"><B>EBADFD</B>
<DD>
File descriptor in bad state.
<DT id="14"><B>EBADMSG</B>
<DD>
Bad message (POSIX.1-2001).
<DT id="15"><B>EBADR</B>
<DD>
Invalid request descriptor.
<DT id="16"><B>EBADRQC</B>
<DD>
Invalid request code.
<DT id="17"><B>EBADSLT</B>
<DD>
Invalid slot.
<DT id="18"><B>EBUSY</B>
<DD>
Device or resource busy (POSIX.1-2001).
<DT id="19"><B>ECANCELED</B>
<DD>
Operation canceled (POSIX.1-2001).
<DT id="20"><B>ECHILD</B>
<DD>
No child processes (POSIX.1-2001).
<DT id="21"><B>ECHRNG</B>
<DD>
Channel number out of range.
<DT id="22"><B>ECOMM</B>
<DD>
Communication error on send.
<DT id="23"><B>ECONNABORTED</B>
<DD>
Connection aborted (POSIX.1-2001).
<DT id="24"><B>ECONNREFUSED</B>
<DD>
Connection refused (POSIX.1-2001).
<DT id="25"><B>ECONNRESET</B>
<DD>
Connection reset (POSIX.1-2001).
<DT id="26"><B>EDEADLK</B>
<DD>
Resource deadlock avoided (POSIX.1-2001).
<DT id="27"><B>EDEADLOCK</B>
<DD>
On most architectures, a synonym for
<B>EDEADLK</B>.
On some architectures (e.g., Linux MIPS, PowerPC, SPARC),
it is a separate error code &quot;File locking deadlock error&quot;.
<DT id="28"><B>EDESTADDRREQ</B>
<DD>
Destination address required (POSIX.1-2001).
<DT id="29"><B>EDOM</B>
<DD>
Mathematics argument out of domain of function (POSIX.1, C99).
<DT id="30"><B>EDQUOT</B>
<DD>
Disk quota exceeded (POSIX.1-2001).
<DT id="31"><B>EEXIST</B>
<DD>
File exists (POSIX.1-2001).
<DT id="32"><B>EFAULT</B>
<DD>
Bad address (POSIX.1-2001).
<DT id="33"><B>EFBIG</B>
<DD>
File too large (POSIX.1-2001).
<DT id="34"><B>EHOSTDOWN</B>
<DD>
Host is down.
<DT id="35"><B>EHOSTUNREACH</B>
<DD>
Host is unreachable (POSIX.1-2001).
<DT id="36"><B>EHWPOISON</B>
<DD>
Memory page has hardware error.
<DT id="37"><B>EIDRM</B>
<DD>
Identifier removed (POSIX.1-2001).
<DT id="38"><B>EILSEQ</B>
<DD>
Invalid or incomplete multibyte or wide character (POSIX.1, C99).
<DT id="39"><DD>
The text shown here is the glibc error description;
in POSIX.1, this error is described as &quot;Illegal byte sequence&quot;.
<DT id="40"><B>EINPROGRESS</B>
<DD>
Operation in progress (POSIX.1-2001).
<DT id="41"><B>EINTR</B>
<DD>
Interrupted function call (POSIX.1-2001); see
<B><A HREF="/cgi-bin/man/man2html?7+signal">signal</A></B>(7).
<DT id="42"><B>EINVAL</B>
<DD>
Invalid argument (POSIX.1-2001).
<DT id="43"><B>EIO</B>
<DD>
Input/output error (POSIX.1-2001).
<DT id="44"><B>EISCONN</B>
<DD>
Socket is connected (POSIX.1-2001).
<DT id="45"><B>EISDIR</B>
<DD>
Is a directory (POSIX.1-2001).
<DT id="46"><B>EISNAM</B>
<DD>
Is a named type file.
<DT id="47"><B>EKEYEXPIRED</B>
<DD>
Key has expired.
<DT id="48"><B>EKEYREJECTED</B>
<DD>
Key was rejected by service.
<DT id="49"><B>EKEYREVOKED</B>
<DD>
Key has been revoked.
<DT id="50"><B>EL2HLT</B>
<DD>
Level 2 halted.
<DT id="51"><B>EL2NSYNC</B>
<DD>
Level 2 not synchronized.
<DT id="52"><B>EL3HLT</B>
<DD>
Level 3 halted.
<DT id="53"><B>EL3RST</B>
<DD>
Level 3 reset.
<DT id="54"><B>ELIBACC</B>
<DD>
Cannot access a needed shared library.
<DT id="55"><B>ELIBBAD</B>
<DD>
Accessing a corrupted shared library.
<DT id="56"><B>ELIBMAX</B>
<DD>
Attempting to link in too many shared libraries.
<DT id="57"><B>ELIBSCN</B>
<DD>
.lib section in a.out corrupted
<DT id="58"><B>ELIBEXEC</B>
<DD>
Cannot exec a shared library directly.
<DT id="59"><B>ELNRANGE</B>
<DD>
Link number out of range.
<DT id="60"><B>ELOOP</B>
<DD>
Too many levels of symbolic links (POSIX.1-2001).
<DT id="61"><B>EMEDIUMTYPE</B>
<DD>
Wrong medium type.
<DT id="62"><B>EMFILE</B>
<DD>
Too many open files (POSIX.1-2001).
Commonly caused by exceeding the
<B>RLIMIT_NOFILE</B>
resource limit described in
<B><A HREF="/cgi-bin/man/man2html?2+getrlimit">getrlimit</A></B>(2).
<DT id="63"><B>EMLINK</B>
<DD>
Too many links (POSIX.1-2001).
<DT id="64"><B>EMSGSIZE</B>
<DD>
Message too long (POSIX.1-2001).
<DT id="65"><B>EMULTIHOP</B>
<DD>
Multihop attempted (POSIX.1-2001).
<DT id="66"><B>ENAMETOOLONG</B>
<DD>
Filename too long (POSIX.1-2001).
<DT id="67"><B>ENETDOWN</B>
<DD>
Network is down (POSIX.1-2001).
<DT id="68"><B>ENETRESET</B>
<DD>
Connection aborted by network (POSIX.1-2001).
<DT id="69"><B>ENETUNREACH</B>
<DD>
Network unreachable (POSIX.1-2001).
<DT id="70"><B>ENFILE</B>
<DD>
Too many open files in system (POSIX.1-2001).
On Linux, this is probably a result of encountering the
<I>/proc/sys/fs/file-max</I>
limit (see
<B><A HREF="/cgi-bin/man/man2html?5+proc">proc</A></B>(5)).
<DT id="71"><B>ENOANO</B>
<DD>
No anode.
<DT id="72"><B>ENOBUFS</B>
<DD>
No buffer space available (POSIX.1 (XSI STREAMS option)).
<DT id="73"><B>ENODATA</B>
<DD>
No message is available on the STREAM head read queue (POSIX.1-2001).
<DT id="74"><B>ENODEV</B>
<DD>
No such device (POSIX.1-2001).
<DT id="75"><B>ENOENT</B>
<DD>
No such file or directory (POSIX.1-2001).
<DT id="76"><DD>
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.
<DT id="77"><B>ENOEXEC</B>
<DD>
Exec format error (POSIX.1-2001).
<DT id="78"><B>ENOKEY</B>
<DD>
Required key not available.
<DT id="79"><B>ENOLCK</B>
<DD>
No locks available (POSIX.1-2001).
<DT id="80"><B>ENOLINK</B>
<DD>
Link has been severed (POSIX.1-2001).
<DT id="81"><B>ENOMEDIUM</B>
<DD>
No medium found.
<DT id="82"><B>ENOMEM</B>
<DD>
Not enough space/cannot allocate memory (POSIX.1-2001).
<DT id="83"><B>ENOMSG</B>
<DD>
No message of the desired type (POSIX.1-2001).
<DT id="84"><B>ENONET</B>
<DD>
Machine is not on the network.
<DT id="85"><B>ENOPKG</B>
<DD>
Package not installed.
<DT id="86"><B>ENOPROTOOPT</B>
<DD>
Protocol not available (POSIX.1-2001).
<DT id="87"><B>ENOSPC</B>
<DD>
No space left on device (POSIX.1-2001).
<DT id="88"><B>ENOSR</B>
<DD>
No STREAM resources (POSIX.1 (XSI STREAMS option)).
<DT id="89"><B>ENOSTR</B>
<DD>
Not a STREAM (POSIX.1 (XSI STREAMS option)).
<DT id="90"><B>ENOSYS</B>
<DD>
Function not implemented (POSIX.1-2001).
<DT id="91"><B>ENOTBLK</B>
<DD>
Block device required.
<DT id="92"><B>ENOTCONN</B>
<DD>
The socket is not connected (POSIX.1-2001).
<DT id="93"><B>ENOTDIR</B>
<DD>
Not a directory (POSIX.1-2001).
<DT id="94"><B>ENOTEMPTY</B>
<DD>
Directory not empty (POSIX.1-2001).
<DT id="95"><B>ENOTRECOVERABLE</B>
<DD>
State not recoverable (POSIX.1-2008).
<DT id="96"><B>ENOTSOCK</B>
<DD>
Not a socket (POSIX.1-2001).
<DT id="97"><B>ENOTSUP</B>
<DD>
Operation not supported (POSIX.1-2001).
<DT id="98"><B>ENOTTY</B>
<DD>
Inappropriate I/O control operation (POSIX.1-2001).
<DT id="99"><B>ENOTUNIQ</B>
<DD>
Name not unique on network.
<DT id="100"><B>ENXIO</B>
<DD>
No such device or address (POSIX.1-2001).
<DT id="101"><B>EOPNOTSUPP</B>
<DD>
Operation not supported on socket (POSIX.1-2001).
<DT id="102"><DD>
(<B>ENOTSUP</B>
and
<B>EOPNOTSUPP</B>
have the same value on Linux, but
according to POSIX.1 these error values should be distinct.)
<DT id="103"><B>EOVERFLOW</B>
<DD>
Value too large to be stored in data type (POSIX.1-2001).
<DT id="104"><B>EOWNERDEAD</B>
<DD>
Owner died (POSIX.1-2008).
<DT id="105"><B>EPERM</B>
<DD>
Operation not permitted (POSIX.1-2001).
<DT id="106"><B>EPFNOSUPPORT</B>
<DD>
Protocol family not supported.
<DT id="107"><B>EPIPE</B>
<DD>
Broken pipe (POSIX.1-2001).
<DT id="108"><B>EPROTO</B>
<DD>
Protocol error (POSIX.1-2001).
<DT id="109"><B>EPROTONOSUPPORT</B>
<DD>
Protocol not supported (POSIX.1-2001).
<DT id="110"><B>EPROTOTYPE</B>
<DD>
Protocol wrong type for socket (POSIX.1-2001).
<DT id="111"><B>ERANGE</B>
<DD>
Result too large (POSIX.1, C99).
<DT id="112"><B>EREMCHG</B>
<DD>
Remote address changed.
<DT id="113"><B>EREMOTE</B>
<DD>
Object is remote.
<DT id="114"><B>EREMOTEIO</B>
<DD>
Remote I/O error.
<DT id="115"><B>ERESTART</B>
<DD>
Interrupted system call should be restarted.
<DT id="116"><B>ERFKILL</B>
<DD>
Operation not possible due to RF-kill.
<DT id="117"><B>EROFS</B>
<DD>
Read-only filesystem (POSIX.1-2001).
<DT id="118"><B>ESHUTDOWN</B>
<DD>
Cannot send after transport endpoint shutdown.
<DT id="119"><B>ESPIPE</B>
<DD>
Invalid seek (POSIX.1-2001).
<DT id="120"><B>ESOCKTNOSUPPORT</B>
<DD>
Socket type not supported.
<DT id="121"><B>ESRCH</B>
<DD>
No such process (POSIX.1-2001).
<DT id="122"><B>ESTALE</B>
<DD>
Stale file handle (POSIX.1-2001).
<DT id="123"><DD>
This error can occur for NFS and for other filesystems.
<DT id="124"><B>ESTRPIPE</B>
<DD>
Streams pipe error.
<DT id="125"><B>ETIME</B>
<DD>
Timer expired
(POSIX.1 (XSI STREAMS option)).
<DT id="126"><DD>
(POSIX.1 says &quot;STREAM
<B><A HREF="/cgi-bin/man/man2html?2+ioctl">ioctl</A></B>(2)
timeout&quot;.)
<DT id="127"><B>ETIMEDOUT</B>
<DD>
Connection timed out (POSIX.1-2001).
<DT id="128"><B>ETOOMANYREFS</B>
<DD>
Too many references: cannot splice.
<DT id="129"><B>ETXTBSY</B>
<DD>
Text file busy (POSIX.1-2001).
<DT id="130"><B>EUCLEAN</B>
<DD>
Structure needs cleaning.
<DT id="131"><B>EUNATCH</B>
<DD>
Protocol driver not attached.
<DT id="132"><B>EUSERS</B>
<DD>
Too many users.
<DT id="133"><B>EWOULDBLOCK</B>
<DD>
Operation would block (may be same value as
<B>EAGAIN</B>)
(POSIX.1-2001).
<DT id="134"><B>EXDEV</B>
<DD>
Improper link (POSIX.1-2001).
<DT id="135"><B>EXFULL</B>
<DD>
Exchange full.
</DL>
<A NAME="lbAH">&nbsp;</A>
<H2>NOTES</H2>
A common mistake is to do
<P>
if (somecall() == -1) {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;somecall()&nbsp;failed\n&quot;);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(errno&nbsp;==&nbsp;...)&nbsp;{&nbsp;...&nbsp;}
}
<P>
where
<I>errno</I>
no longer needs to have the value it had upon return from
<I>somecall</I>()
(i.e., it may have been changed by the
<B><A HREF="/cgi-bin/man/man2html?3+printf">printf</A></B>(3)).
If the value of
<I>errno</I>
should be preserved across a library call, it must be saved:
<P>
if (somecall() == -1) {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;errsv&nbsp;=&nbsp;errno;
<BR>&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;somecall()&nbsp;failed\n&quot;);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(errsv&nbsp;==&nbsp;...)&nbsp;{&nbsp;...&nbsp;}
}
<P>
On some ancient systems,
<I>&lt;<A HREF="file:///usr/include/errno.h">errno.h</A>&gt;</I>
was not present or did not declare
<I>errno</I>,
so that it was necessary to declare
<I>errno</I>
manually
(i.e.,
<I>extern int errno</I>).
<B>Do not do this</B>.
It long ago ceased to be necessary,
and it will cause problems with modern versions of the C library.
<A NAME="lbAI">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?1+errno">errno</A></B>(1),
<B><A HREF="/cgi-bin/man/man2html?3+err">err</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+error">error</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+perror">perror</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+strerror">strerror</A></B>(3)
<A NAME="lbAJ">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="136"><A HREF="#lbAB">NAME</A><DD>
<DT id="137"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="138"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DL>
<DT id="139"><A HREF="#lbAE">errno</A><DD>
<DT id="140"><A HREF="#lbAF">Error numbers and names</A><DD>
<DT id="141"><A HREF="#lbAG">List of error names</A><DD>
</DL>
<DT id="142"><A HREF="#lbAH">NOTES</A><DD>
<DT id="143"><A HREF="#lbAI">SEE ALSO</A><DD>
<DT id="144"><A HREF="#lbAJ">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:39 GMT, March 31, 2021
</BODY>
</HTML>