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

NOTES

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

SEE ALSO

402       errno(1), err(3), error(3), perror(3), strerror(3)
403

COLOPHON

405       This page is part of release 5.10 of the Linux  man-pages  project.   A
406       description  of  the project, information about reporting bugs, and the
407       latest    version    of    this    page,    can     be     found     at
408       https://www.kernel.org/doc/man-pages/.
409
410
411
412                                  2020-11-01                          ERRNO(3)
Impressum