1ERRNO(3)                   Linux Programmer's Manual                  ERRNO(3)
2
3
4

NAME

6       errno - number of last error
7

SYNOPSIS

9       #include <errno.h>
10

DESCRIPTION

12       The  <errno.h> header file defines the integer variable errno, which is
13       set by system calls and some library functions in the event of an error
14       to indicate what went wrong.
15
16   errno
17       The  value  in  errno  is significant only when the return value of the
18       call indicated an error (i.e., -1 from most system calls;  -1  or  NULL
19       from  most  library  functions); a function that succeeds is allowed to
20       change errno.  The value of errno is never set to zero  by  any  system
21       call or library function.
22
23       For  some system calls and library functions (e.g., getpriority(2)), -1
24       is a valid return on success.  In such cases, a successful  return  can
25       be  distinguished  from an error return by setting errno to zero before
26       the call, and then, if the call returns a status that indicates that an
27       error may have occurred, checking to see if errno has a nonzero value.
28
29       errno  is  defined  by  the ISO C standard to be a modifiable lvalue of
30       type int, and must not be explicitly declared; errno may  be  a  macro.
31       errno  is  thread-local;  setting  it in one thread does not affect its
32       value in any other thread.
33
34   Error numbers and names
35       Valid error numbers are all positive  numbers.   The  <errno.h>  header
36       file defines symbolic names for each of the possible error numbers that
37       may appear in errno.
38
39       All the error names specified by POSIX.1  must  have  distinct  values,
40       with  the  exception  of EAGAIN and EWOULDBLOCK, which may be the same.
41       On Linux, these two have the same value on all architectures.
42
43       The error numbers that correspond to each  symbolic  name  vary  across
44       UNIX systems, and even across different architectures on Linux.  There‐
45       fore, numeric values are not included as part  of  the  list  of  error
46       names  below.   The  perror(3) and strerror(3) functions can be used to
47       convert these names to corresponding textual error messages.
48
49       On any particular Linux system, one can obtain a list of  all  symbolic
50       error names and the corresponding error numbers using the errno(1) com‐
51       mand (part of the moreutils package):
52
53           $ errno -l
54           EPERM 1 Operation not permitted
55           ENOENT 2 No such file or directory
56           ESRCH 3 No such process
57           EINTR 4 Interrupted system call
58           EIO 5 Input/output error
59           ...
60
61       The errno(1) command can also be used to look up individual error  num‐
62       bers  and  names, and to search for errors using strings from the error
63       description, as in the following examples:
64
65           $ errno 2
66           ENOENT 2 No such file or directory
67           $ errno ESRCH
68           ESRCH 3 No such process
69           $ errno -s permission
70           EACCES 13 Permission denied
71
72   List of error names
73       In the list of the symbolic error names below, various names are marked
74       as follows:
75
76       *  POSIX.1-2001: The name is defined by POSIX.1-2001, and is defined in
77          later POSIX.1 versions, unless otherwise indicated.
78
79       *  POSIX.1-2008: The name is  defined  in  POSIX.1-2008,  but  was  not
80          present in earlier POSIX.1 standards.
81
82       *  C99:  The  name  is defined by C99.  Below is a list of the symbolic
83          error names that are defined on Linux:
84
85       E2BIG           Argument list too long (POSIX.1-2001).
86
87       EACCES          Permission denied (POSIX.1-2001).
88
89       EADDRINUSE      Address already in use (POSIX.1-2001).
90
91       EADDRNOTAVAIL   Address not available (POSIX.1-2001).
92
93       EAFNOSUPPORT    Address family not supported (POSIX.1-2001).
94
95       EAGAIN          Resource temporarily unavailable (may be the same value
96                       as EWOULDBLOCK) (POSIX.1-2001).
97
98       EALREADY        Connection already in progress (POSIX.1-2001).
99
100       EBADE           Invalid exchange.
101
102       EBADF           Bad file descriptor (POSIX.1-2001).
103
104       EBADFD          File descriptor in bad state.
105
106       EBADMSG         Bad message (POSIX.1-2001).
107
108       EBADR           Invalid request descriptor.
109
110       EBADRQC         Invalid request code.
111
112       EBADSLT         Invalid slot.
113
114       EBUSY           Device or resource busy (POSIX.1-2001).
115
116       ECANCELED       Operation canceled (POSIX.1-2001).
117
118       ECHILD          No child processes (POSIX.1-2001).
119
120       ECHRNG          Channel number out of range.
121
122       ECOMM           Communication error on send.
123
124       ECONNABORTED    Connection aborted (POSIX.1-2001).
125
126       ECONNREFUSED    Connection refused (POSIX.1-2001).
127
128       ECONNRESET      Connection reset (POSIX.1-2001).
129
130       EDEADLK         Resource deadlock avoided (POSIX.1-2001).
131
132       EDEADLOCK       On  most architectures, a synonym for EDEADLK.  On some
133                       architectures (e.g., Linux MIPS, PowerPC, SPARC), it is
134                       a separate error code "File locking deadlock error".
135
136       EDESTADDRREQ    Destination address required (POSIX.1-2001).
137
138       EDOM            Mathematics   argument   out   of  domain  of  function
139                       (POSIX.1, C99).
140
141       EDQUOT          Disk quota exceeded (POSIX.1-2001).
142
143       EEXIST          File exists (POSIX.1-2001).
144
145       EFAULT          Bad address (POSIX.1-2001).
146
147       EFBIG           File too large (POSIX.1-2001).
148
149       EHOSTDOWN       Host is down.
150
151       EHOSTUNREACH    Host is unreachable (POSIX.1-2001).
152
153       EHWPOISON       Memory page has hardware error.
154
155       EIDRM           Identifier removed (POSIX.1-2001).
156
157       EILSEQ          Invalid  or  incomplete  multibyte  or  wide  character
158                       (POSIX.1, C99).
159
160                       The  text shown here is the glibc error description; in
161                       POSIX.1, this  error  is  described  as  "Illegal  byte
162                       sequence".
163
164       EINPROGRESS     Operation in progress (POSIX.1-2001).
165
166       EINTR           Interrupted  function  call  (POSIX.1-2001);  see  sig‐
167                       nal(7).
168
169       EINVAL          Invalid argument (POSIX.1-2001).
170
171       EIO             Input/output error (POSIX.1-2001).
172
173       EISCONN         Socket is connected (POSIX.1-2001).
174
175       EISDIR          Is a directory (POSIX.1-2001).
176
177       EISNAM          Is a named type file.
178
179       EKEYEXPIRED     Key has expired.
180
181       EKEYREJECTED    Key was rejected by service.
182
183       EKEYREVOKED     Key has been revoked.
184
185       EL2HLT          Level 2 halted.
186
187       EL2NSYNC        Level 2 not synchronized.
188
189       EL3HLT          Level 3 halted.
190
191       EL3RST          Level 3 reset.
192
193       ELIBACC         Cannot access a needed shared library.
194
195       ELIBBAD         Accessing a corrupted shared library.
196
197       ELIBMAX         Attempting to link in too many shared libraries.
198
199       ELIBSCN         .lib section in a.out corrupted
200
201       ELIBEXEC        Cannot exec a shared library directly.
202
203       ELNRANGE        Link number out of range.
204
205       ELOOP           Too many levels of symbolic links (POSIX.1-2001).
206
207       EMEDIUMTYPE     Wrong medium type.
208
209       EMFILE          Too many open files (POSIX.1-2001).  Commonly caused by
210                       exceeding the RLIMIT_NOFILE resource limit described in
211                       getrlimit(2).
212
213       EMLINK          Too many links (POSIX.1-2001).
214
215       EMSGSIZE        Message too long (POSIX.1-2001).
216
217       EMULTIHOP       Multihop attempted (POSIX.1-2001).
218
219       ENAMETOOLONG    Filename too long (POSIX.1-2001).
220
221       ENETDOWN        Network is down (POSIX.1-2001).
222
223       ENETRESET       Connection aborted by network (POSIX.1-2001).
224
225       ENETUNREACH     Network unreachable (POSIX.1-2001).
226
227       ENFILE          Too many  open  files  in  system  (POSIX.1-2001).   On
228                       Linux,  this  is  probably a result of encountering the
229                       /proc/sys/fs/file-max limit (see proc(5)).
230
231       ENOANO          No anode.
232
233       ENOBUFS         No  buffer  space  available  (POSIX.1   (XSI   STREAMS
234                       option)).
235
236       ENODATA         No  message  is available on the STREAM head read queue
237                       (POSIX.1-2001).
238
239       ENODEV          No such device (POSIX.1-2001).
240
241       ENOENT          No such file or directory (POSIX.1-2001).
242
243                       Typically, this error results when a specified pathname
244                       does  not exist, or one of the components in the direc‐
245                       tory prefix of a pathname does not exist, or the speci‐
246                       fied pathname is a dangling symbolic link.
247
248       ENOEXEC         Exec format error (POSIX.1-2001).
249
250       ENOKEY          Required key not available.
251
252       ENOLCK          No locks available (POSIX.1-2001).
253
254       ENOLINK         Link has been severed (POSIX.1-2001).
255
256       ENOMEDIUM       No medium found.
257
258       ENOMEM          Not enough space/cannot allocate memory (POSIX.1-2001).
259
260       ENOMSG          No message of the desired type (POSIX.1-2001).
261
262       ENONET          Machine is not on the network.
263
264       ENOPKG          Package not installed.
265
266       ENOPROTOOPT     Protocol not available (POSIX.1-2001).
267
268       ENOSPC          No space left on device (POSIX.1-2001).
269
270       ENOSR           No STREAM resources (POSIX.1 (XSI STREAMS option)).
271
272       ENOSTR          Not a STREAM (POSIX.1 (XSI STREAMS option)).
273
274       ENOSYS          Function not implemented (POSIX.1-2001).
275
276       ENOTBLK         Block device required.
277
278       ENOTCONN        The socket is not connected (POSIX.1-2001).
279
280       ENOTDIR         Not a directory (POSIX.1-2001).
281
282       ENOTEMPTY       Directory not empty (POSIX.1-2001).
283
284       ENOTRECOVERABLE State not recoverable (POSIX.1-2008).
285
286       ENOTSOCK        Not a socket (POSIX.1-2001).
287
288       ENOTSUP         Operation not supported (POSIX.1-2001).
289
290       ENOTTY          Inappropriate I/O control operation (POSIX.1-2001).
291
292       ENOTUNIQ        Name not unique on network.
293
294       ENXIO           No such device or address (POSIX.1-2001).
295
296       EOPNOTSUPP      Operation not supported on socket (POSIX.1-2001).
297
298                       (ENOTSUP  and  EOPNOTSUPP have the same value on Linux,
299                       but according to POSIX.1 these error values  should  be
300                       distinct.)
301
302       EOVERFLOW       Value   too   large   to   be   stored   in  data  type
303                       (POSIX.1-2001).
304
305       EOWNERDEAD      Owner died (POSIX.1-2008).
306
307       EPERM           Operation not permitted (POSIX.1-2001).
308
309       EPFNOSUPPORT    Protocol family not supported.
310
311       EPIPE           Broken pipe (POSIX.1-2001).
312
313       EPROTO          Protocol error (POSIX.1-2001).
314
315       EPROTONOSUPPORT Protocol not supported (POSIX.1-2001).
316
317       EPROTOTYPE      Protocol wrong type for socket (POSIX.1-2001).
318
319       ERANGE          Result too large (POSIX.1, C99).
320
321       EREMCHG         Remote address changed.
322
323       EREMOTE         Object is remote.
324
325       EREMOTEIO       Remote I/O error.
326
327       ERESTART        Interrupted system call should be restarted.
328
329       ERFKILL         Operation not possible due to RF-kill.
330
331       EROFS           Read-only filesystem (POSIX.1-2001).
332
333       ESHUTDOWN       Cannot send after transport endpoint shutdown.
334
335       ESPIPE          Invalid seek (POSIX.1-2001).
336
337       ESOCKTNOSUPPORT Socket type not supported.
338
339       ESRCH           No such process (POSIX.1-2001).
340
341       ESTALE          Stale file handle (POSIX.1-2001).
342
343                       This error can occur for NFS and for other filesystems.
344
345       ESTRPIPE        Streams pipe error.
346
347       ETIME           Timer expired (POSIX.1 (XSI STREAMS option)).
348
349                       (POSIX.1 says "STREAM ioctl(2) timeout".)
350
351       ETIMEDOUT       Connection timed out (POSIX.1-2001).
352
353       ETOOMANYREFS    Too many references: cannot splice.
354
355       ETXTBSY         Text file busy (POSIX.1-2001).
356
357       EUCLEAN         Structure needs cleaning.
358
359       EUNATCH         Protocol driver not attached.
360
361       EUSERS          Too many users.
362
363       EWOULDBLOCK     Operation would block (may be  same  value  as  EAGAIN)
364                       (POSIX.1-2001).
365
366       EXDEV           Improper link (POSIX.1-2001).
367
368       EXFULL          Exchange full.
369

NOTES

371       A common mistake is to do
372
373           if (somecall() == -1) {
374               printf("somecall() failed\n");
375               if (errno == ...) { ... }
376           }
377
378       where  errno  no longer needs to have the value it had upon return from
379       somecall() (i.e., it may have been changed by the printf(3)).   If  the
380       value  of  errno  should be preserved across a library call, it must be
381       saved:
382
383           if (somecall() == -1) {
384               int errsv = errno;
385               printf("somecall() failed\n");
386               if (errsv == ...) { ... }
387           }
388
389       On some ancient systems, <errno.h> was not present or did  not  declare
390       errno, so that it was necessary to declare errno manually (i.e., extern
391       int errno).  Do not do this.  It long ago ceased to be  necessary,  and
392       it will cause problems with modern versions of the C library.
393

SEE ALSO

395       errno(1), err(3), error(3), perror(3), strerror(3)
396

COLOPHON

398       This  page  is  part of release 5.04 of the Linux man-pages project.  A
399       description of the project, information about reporting bugs,  and  the
400       latest     version     of     this    page,    can    be    found    at
401       https://www.kernel.org/doc/man-pages/.
402
403
404
405                                  2019-10-10                          ERRNO(3)
Impressum