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.
83
84       Below is a list of the symbolic error names that are defined on Linux:
85
86       E2BIG           Argument list too long (POSIX.1-2001).
87
88       EACCES          Permission denied (POSIX.1-2001).
89
90       EADDRINUSE      Address already in use (POSIX.1-2001).
91
92       EADDRNOTAVAIL   Address not available (POSIX.1-2001).
93
94       EAFNOSUPPORT    Address family not supported (POSIX.1-2001).
95
96       EAGAIN          Resource temporarily unavailable (may be the same value
97                       as EWOULDBLOCK) (POSIX.1-2001).
98
99       EALREADY        Connection already in progress (POSIX.1-2001).
100
101       EBADE           Invalid exchange.
102
103       EBADF           Bad file descriptor (POSIX.1-2001).
104
105       EBADFD          File descriptor in bad state.
106
107       EBADMSG         Bad message (POSIX.1-2001).
108
109       EBADR           Invalid request descriptor.
110
111       EBADRQC         Invalid request code.
112
113       EBADSLT         Invalid slot.
114
115       EBUSY           Device or resource busy (POSIX.1-2001).
116
117       ECANCELED       Operation canceled (POSIX.1-2001).
118
119       ECHILD          No child processes (POSIX.1-2001).
120
121       ECHRNG          Channel number out of range.
122
123       ECOMM           Communication error on send.
124
125       ECONNABORTED    Connection aborted (POSIX.1-2001).
126
127       ECONNREFUSED    Connection refused (POSIX.1-2001).
128
129       ECONNRESET      Connection reset (POSIX.1-2001).
130
131       EDEADLK         Resource deadlock avoided (POSIX.1-2001).
132
133       EDEADLOCK       On most architectures, a synonym for EDEADLK.  On  some
134                       architectures (e.g., Linux MIPS, PowerPC, SPARC), it is
135                       a separate error code "File locking deadlock error".
136
137       EDESTADDRREQ    Destination address required (POSIX.1-2001).
138
139       EDOM            Mathematics  argument  out  of   domain   of   function
140                       (POSIX.1, C99).
141
142       EDQUOT          Disk quota exceeded (POSIX.1-2001).
143
144       EEXIST          File exists (POSIX.1-2001).
145
146       EFAULT          Bad address (POSIX.1-2001).
147
148       EFBIG           File too large (POSIX.1-2001).
149
150       EHOSTDOWN       Host is down.
151
152       EHOSTUNREACH    Host is unreachable (POSIX.1-2001).
153
154       EHWPOISON       Memory page has hardware error.
155
156       EIDRM           Identifier removed (POSIX.1-2001).
157
158       EILSEQ          Invalid  or  incomplete  multibyte  or  wide  character
159                       (POSIX.1, C99).
160
161                       The text shown here is the glibc error description;  in
162                       POSIX.1,  this  error  is  described  as  "Illegal byte
163                       sequence".
164
165       EINPROGRESS     Operation in progress (POSIX.1-2001).
166
167       EINTR           Interrupted  function  call  (POSIX.1-2001);  see  sig‐
168                       nal(7).
169
170       EINVAL          Invalid argument (POSIX.1-2001).
171
172       EIO             Input/output error (POSIX.1-2001).
173
174       EISCONN         Socket is connected (POSIX.1-2001).
175
176       EISDIR          Is a directory (POSIX.1-2001).
177
178       EISNAM          Is a named type file.
179
180       EKEYEXPIRED     Key has expired.
181
182       EKEYREJECTED    Key was rejected by service.
183
184       EKEYREVOKED     Key has been revoked.
185
186       EL2HLT          Level 2 halted.
187
188       EL2NSYNC        Level 2 not synchronized.
189
190       EL3HLT          Level 3 halted.
191
192       EL3RST          Level 3 reset.
193
194       ELIBACC         Cannot access a needed shared library.
195
196       ELIBBAD         Accessing a corrupted shared library.
197
198       ELIBMAX         Attempting to link in too many shared libraries.
199
200       ELIBSCN         .lib section in a.out corrupted
201
202       ELIBEXEC        Cannot exec a shared library directly.
203
204       ELNRANGE        Link number out of range.
205
206       ELOOP           Too many levels of symbolic links (POSIX.1-2001).
207
208       EMEDIUMTYPE     Wrong medium type.
209
210       EMFILE          Too many open files (POSIX.1-2001).  Commonly caused by
211                       exceeding the RLIMIT_NOFILE resource limit described in
212                       getrlimit(2).
213
214       EMLINK          Too many links (POSIX.1-2001).
215
216       EMSGSIZE        Message too long (POSIX.1-2001).
217
218       EMULTIHOP       Multihop attempted (POSIX.1-2001).
219
220       ENAMETOOLONG    Filename too long (POSIX.1-2001).
221
222       ENETDOWN        Network is down (POSIX.1-2001).
223
224       ENETRESET       Connection aborted by network (POSIX.1-2001).
225
226       ENETUNREACH     Network unreachable (POSIX.1-2001).
227
228       ENFILE          Too  many  open  files  in  system  (POSIX.1-2001).  On
229                       Linux, this is probably a result  of  encountering  the
230                       /proc/sys/fs/file-max limit (see proc(5)).
231
232       ENOANO          No anode.
233
234       ENOBUFS         No   buffer   space  available  (POSIX.1  (XSI  STREAMS
235                       option)).
236
237       ENODATA         No message is available on the STREAM head  read  queue
238                       (POSIX.1-2001).
239
240       ENODEV          No such device (POSIX.1-2001).
241
242       ENOENT          No such file or directory (POSIX.1-2001).
243
244                       Typically, this error results when a specified pathname
245                       does not exist, or one of the components in the  direc‐
246                       tory prefix of a pathname does not exist, or the speci‐
247                       fied pathname is a dangling symbolic link.
248
249       ENOEXEC         Exec format error (POSIX.1-2001).
250
251       ENOKEY          Required key not available.
252
253       ENOLCK          No locks available (POSIX.1-2001).
254
255       ENOLINK         Link has been severed (POSIX.1-2001).
256
257       ENOMEDIUM       No medium found.
258
259       ENOMEM          Not enough space/cannot allocate memory (POSIX.1-2001).
260
261       ENOMSG          No message of the desired type (POSIX.1-2001).
262
263       ENONET          Machine is not on the network.
264
265       ENOPKG          Package not installed.
266
267       ENOPROTOOPT     Protocol not available (POSIX.1-2001).
268
269       ENOSPC          No space left on device (POSIX.1-2001).
270
271       ENOSR           No STREAM resources (POSIX.1 (XSI STREAMS option)).
272
273       ENOSTR          Not a STREAM (POSIX.1 (XSI STREAMS option)).
274
275       ENOSYS          Function not implemented (POSIX.1-2001).
276
277       ENOTBLK         Block device required.
278
279       ENOTCONN        The socket is not connected (POSIX.1-2001).
280
281       ENOTDIR         Not a directory (POSIX.1-2001).
282
283       ENOTEMPTY       Directory not empty (POSIX.1-2001).
284
285       ENOTRECOVERABLE State not recoverable (POSIX.1-2008).
286
287       ENOTSOCK        Not a socket (POSIX.1-2001).
288
289       ENOTSUP         Operation not supported (POSIX.1-2001).
290
291       ENOTTY          Inappropriate I/O control operation (POSIX.1-2001).
292
293       ENOTUNIQ        Name not unique on network.
294
295       ENXIO           No such device or address (POSIX.1-2001).
296
297       EOPNOTSUPP      Operation not supported on socket (POSIX.1-2001).
298
299                       (ENOTSUP and EOPNOTSUPP have the same value  on  Linux,
300                       but  according  to POSIX.1 these error values should be
301                       distinct.)
302
303       EOVERFLOW       Value  too  large   to   be   stored   in   data   type
304                       (POSIX.1-2001).
305
306       EOWNERDEAD      Owner died (POSIX.1-2008).
307
308       EPERM           Operation not permitted (POSIX.1-2001).
309
310       EPFNOSUPPORT    Protocol family not supported.
311
312       EPIPE           Broken pipe (POSIX.1-2001).
313
314       EPROTO          Protocol error (POSIX.1-2001).
315
316       EPROTONOSUPPORT Protocol not supported (POSIX.1-2001).
317
318       EPROTOTYPE      Protocol wrong type for socket (POSIX.1-2001).
319
320       ERANGE          Result too large (POSIX.1, C99).
321
322       EREMCHG         Remote address changed.
323
324       EREMOTE         Object is remote.
325
326       EREMOTEIO       Remote I/O error.
327
328       ERESTART        Interrupted system call should be restarted.
329
330       ERFKILL         Operation not possible due to RF-kill.
331
332       EROFS           Read-only filesystem (POSIX.1-2001).
333
334       ESHUTDOWN       Cannot send after transport endpoint shutdown.
335
336       ESPIPE          Invalid seek (POSIX.1-2001).
337
338       ESOCKTNOSUPPORT Socket type not supported.
339
340       ESRCH           No such process (POSIX.1-2001).
341
342       ESTALE          Stale file handle (POSIX.1-2001).
343
344                       This error can occur for NFS and for other filesystems.
345
346       ESTRPIPE        Streams pipe error.
347
348       ETIME           Timer expired (POSIX.1 (XSI STREAMS option)).
349
350                       (POSIX.1 says "STREAM ioctl(2) timeout".)
351
352       ETIMEDOUT       Connection timed out (POSIX.1-2001).
353
354       ETOOMANYREFS    Too many references: cannot splice.
355
356       ETXTBSY         Text file busy (POSIX.1-2001).
357
358       EUCLEAN         Structure needs cleaning.
359
360       EUNATCH         Protocol driver not attached.
361
362       EUSERS          Too many users.
363
364       EWOULDBLOCK     Operation  would  block  (may  be same value as EAGAIN)
365                       (POSIX.1-2001).
366
367       EXDEV           Improper link (POSIX.1-2001).
368
369       EXFULL          Exchange full.
370

NOTES

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

SEE ALSO

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

COLOPHON

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