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 se‐
163                       quence".
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).   Can  also  be  caused  by exceeding the
213                       limit specified in /proc/sys/fs/nr_open.
214
215       EMLINK          Too many links (POSIX.1-2001).
216
217       EMSGSIZE        Message too long (POSIX.1-2001).
218
219       EMULTIHOP       Multihop attempted (POSIX.1-2001).
220
221       ENAMETOOLONG    Filename too long (POSIX.1-2001).
222
223       ENETDOWN        Network is down (POSIX.1-2001).
224
225       ENETRESET       Connection aborted by network (POSIX.1-2001).
226
227       ENETUNREACH     Network unreachable (POSIX.1-2001).
228
229       ENFILE          Too many  open  files  in  system  (POSIX.1-2001).   On
230                       Linux,  this  is  probably a result of encountering the
231                       /proc/sys/fs/file-max limit (see proc(5)).
232
233       ENOANO          No anode.
234
235       ENOBUFS         No buffer space available  (POSIX.1  (XSI  STREAMS  op‐
236                       tion)).
237
238       ENODATA         The  named attribute does not exist, or the process has
239                       no access to this attribute; see xattr(7).
240
241                       In POSIX.1-2001 (XSI STREAMS option),  this  error  was
242                       described  as  "No  message  is available on the STREAM
243                       head read queue".
244
245       ENODEV          No such device (POSIX.1-2001).
246
247       ENOENT          No such file or directory (POSIX.1-2001).
248
249                       Typically, this error results when a specified pathname
250                       does  not exist, or one of the components in the direc‐
251                       tory prefix of a pathname does not exist, or the speci‐
252                       fied pathname is a dangling symbolic link.
253
254       ENOEXEC         Exec format error (POSIX.1-2001).
255
256       ENOKEY          Required key not available.
257
258       ENOLCK          No locks available (POSIX.1-2001).
259
260       ENOLINK         Link has been severed (POSIX.1-2001).
261
262       ENOMEDIUM       No medium found.
263
264       ENOMEM          Not enough space/cannot allocate memory (POSIX.1-2001).
265
266       ENOMSG          No message of the desired type (POSIX.1-2001).
267
268       ENONET          Machine is not on the network.
269
270       ENOPKG          Package not installed.
271
272       ENOPROTOOPT     Protocol not available (POSIX.1-2001).
273
274       ENOSPC          No space left on device (POSIX.1-2001).
275
276       ENOSR           No STREAM resources (POSIX.1 (XSI STREAMS option)).
277
278       ENOSTR          Not a STREAM (POSIX.1 (XSI STREAMS option)).
279
280       ENOSYS          Function not implemented (POSIX.1-2001).
281
282       ENOTBLK         Block device required.
283
284       ENOTCONN        The socket is not connected (POSIX.1-2001).
285
286       ENOTDIR         Not a directory (POSIX.1-2001).
287
288       ENOTEMPTY       Directory not empty (POSIX.1-2001).
289
290       ENOTRECOVERABLE State not recoverable (POSIX.1-2008).
291
292       ENOTSOCK        Not a socket (POSIX.1-2001).
293
294       ENOTSUP         Operation not supported (POSIX.1-2001).
295
296       ENOTTY          Inappropriate I/O control operation (POSIX.1-2001).
297
298       ENOTUNIQ        Name not unique on network.
299
300       ENXIO           No such device or address (POSIX.1-2001).
301
302       EOPNOTSUPP      Operation not supported on socket (POSIX.1-2001).
303
304                       (ENOTSUP  and  EOPNOTSUPP have the same value on Linux,
305                       but according to POSIX.1 these error values  should  be
306                       distinct.)
307
308       EOVERFLOW       Value   too   large   to   be   stored   in  data  type
309                       (POSIX.1-2001).
310
311       EOWNERDEAD      Owner died (POSIX.1-2008).
312
313       EPERM           Operation not permitted (POSIX.1-2001).
314
315       EPFNOSUPPORT    Protocol family not supported.
316
317       EPIPE           Broken pipe (POSIX.1-2001).
318
319       EPROTO          Protocol error (POSIX.1-2001).
320
321       EPROTONOSUPPORT Protocol not supported (POSIX.1-2001).
322
323       EPROTOTYPE      Protocol wrong type for socket (POSIX.1-2001).
324
325       ERANGE          Result too large (POSIX.1, C99).
326
327       EREMCHG         Remote address changed.
328
329       EREMOTE         Object is remote.
330
331       EREMOTEIO       Remote I/O error.
332
333       ERESTART        Interrupted system call should be restarted.
334
335       ERFKILL         Operation not possible due to RF-kill.
336
337       EROFS           Read-only filesystem (POSIX.1-2001).
338
339       ESHUTDOWN       Cannot send after transport endpoint shutdown.
340
341       ESPIPE          Invalid seek (POSIX.1-2001).
342
343       ESOCKTNOSUPPORT Socket type not supported.
344
345       ESRCH           No such process (POSIX.1-2001).
346
347       ESTALE          Stale file handle (POSIX.1-2001).
348
349                       This error can occur for NFS and for other filesystems.
350
351       ESTRPIPE        Streams pipe error.
352
353       ETIME           Timer expired (POSIX.1 (XSI STREAMS option)).
354
355                       (POSIX.1 says "STREAM ioctl(2) timeout".)
356
357       ETIMEDOUT       Connection timed out (POSIX.1-2001).
358
359       ETOOMANYREFS    Too many references: cannot splice.
360
361       ETXTBSY         Text file busy (POSIX.1-2001).
362
363       EUCLEAN         Structure needs cleaning.
364
365       EUNATCH         Protocol driver not attached.
366
367       EUSERS          Too many users.
368
369       EWOULDBLOCK     Operation would block (may be  same  value  as  EAGAIN)
370                       (POSIX.1-2001).
371
372       EXDEV           Improper link (POSIX.1-2001).
373
374       EXFULL          Exchange full.
375

NOTES

377       A common mistake is to do
378
379           if (somecall() == -1) {
380               printf("somecall() failed\n");
381               if (errno == ...) { ... }
382           }
383
384       where  errno  no longer needs to have the value it had upon return from
385       somecall() (i.e., it may have been changed by the printf(3)).   If  the
386       value  of  errno  should be preserved across a library call, it must be
387       saved:
388
389           if (somecall() == -1) {
390               int errsv = errno;
391               printf("somecall() failed\n");
392               if (errsv == ...) { ... }
393           }
394
395       Note that the POSIX threads APIs do not set errno on  error.   Instead,
396       on  failure  they return an error number as the function result.  These
397       error numbers have the same meanings as the error numbers  returned  in
398       errno by other APIs.
399
400       On  some  ancient systems, <errno.h> was not present or did not declare
401       errno, so that it was necessary to declare errno manually (i.e., extern
402       int  errno).   Do not do this.  It long ago ceased to be necessary, and
403       it will cause problems with modern versions of the C library.
404

SEE ALSO

406       errno(1), err(3), error(3), perror(3), strerror(3)
407

COLOPHON

409       This page is part of release 5.12 of the Linux  man-pages  project.   A
410       description  of  the project, information about reporting bugs, and the
411       latest    version    of    this    page,    can     be     found     at
412       https://www.kernel.org/doc/man-pages/.
413
414
415
416                                  2021-03-22                          ERRNO(3)
Impressum