1errno(3)                   Library Functions Manual                   errno(3)
2
3
4

NAME

6       errno - number of last error
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <errno.h>
13

DESCRIPTION

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

NOTES

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

SEE ALSO

411       errno(1), err(3), error(3), perror(3), strerror(3)
412
413
414
415Linux man-pages 6.04              2022-12-04                          errno(3)
Impressum