1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
|
.\" Copyright (c) 1996 Andries Brouwer (aeb@cwi.nl)
.\"
.\" SPDX-License-Identifier: GPL-2.0-or-later
.\"
.\" 5 Oct 2002, Modified by Michael Kerrisk <mtk.manpages@gmail.com>
.\" Updated for POSIX.1 2001
.\" 2004-12-17 Martin Schulze <joey@infodrom.org>, mtk
.\" Removed errno declaration prototype, added notes
.\" 2006-02-09 Kurt Wall, mtk
.\" Added non-POSIX errors
.\"
.TH errno 3 2022-12-04 "Linux man-pages 6.04"
.SH NAME
errno \- number of last error
.SH LIBRARY
Standard C library
.RI ( libc ", " \-lc )
.SH SYNOPSIS
.nf
.B #include <errno.h>
.\".PP
.\".BI "extern int " errno ;
.fi
.SH DESCRIPTION
The
.I <errno.h>
header file defines the integer variable
.IR errno ,
which is set by system calls and some library functions in the event
of an error to indicate what went wrong.
.\"
.SS errno
The value in
.I errno
is significant only when the return value of
the call indicated an error
(i.e., \-1 from most system calls;
\-1 or NULL from most library functions);
a function that succeeds
.I is
allowed to change
.IR errno .
The value of
.I errno
is never set to zero by any system call or library function.
.PP
For some system calls and library functions (e.g.,
.BR getpriority (2)),
\-1 is a valid return on success.
In such cases, a successful return can be distinguished from an error
return by setting
.I errno
to zero before the call, and then,
if the call returns a status that indicates that an error
may have occurred, checking to see if
.I errno
has a nonzero value.
.PP
.I errno
is defined by the ISO C standard to be a modifiable lvalue
of type
.IR int ,
and must not be explicitly declared;
.I errno
may be a macro.
.I errno
is thread-local; setting it in one thread
does not affect its value in any other thread.
.\"
.SS Error numbers and names
Valid error numbers are all positive numbers.
The
.I <errno.h>
header file defines symbolic names for each
of the possible error numbers that may appear in
.IR errno .
.PP
All the error names specified by POSIX.1
must have distinct values, with the exception of
.B EAGAIN
and
.BR EWOULDBLOCK ,
which may be the same.
On Linux, these two have the same value on all architectures.
.PP
The error numbers that correspond to each symbolic name
vary across UNIX systems,
and even across different architectures on Linux.
Therefore, numeric values are not included as part of the list of
error names below.
The
.BR perror (3)
and
.BR strerror (3)
functions can be used to convert these names to
corresponding textual error messages.
.PP
On any particular Linux system,
one can obtain a list of all symbolic error names and
the corresponding error numbers using the
.BR errno (1)
command (part of the
.I moreutils
package):
.PP
.in +4n
.EX
$ \fBerrno \-l\fP
EPERM 1 Operation not permitted
ENOENT 2 No such file or directory
ESRCH 3 No such process
EINTR 4 Interrupted system call
EIO 5 Input/output error
\&...
.EE
.in
.PP
The
.BR errno (1)
command can also be used to look up individual error numbers and names,
and to search for errors using strings from the error description,
as in the following examples:
.PP
.in +4n
.EX
$ \fBerrno 2\fP
ENOENT 2 No such file or directory
$ \fBerrno ESRCH\fP
ESRCH 3 No such process
$ \fBerrno \-s permission\fP
EACCES 13 Permission denied
.EE
.in
.\".PP
.\" POSIX.1 (2001 edition) lists the following symbolic error names. Of
.\" these, \fBEDOM\fP and \fBERANGE\fP are in the ISO C standard. ISO C
.\" Amendment 1 defines the additional error number \fBEILSEQ\fP for
.\" coding errors in multibyte or wide characters.
.\"
.SS List of error names
In the list of the symbolic error names below,
various names are marked as follows:
.TP
.I POSIX.1-2001
The name is defined by POSIX.1-2001,
and is defined in later POSIX.1 versions, unless otherwise indicated.
.TP
.I POSIX.1-2008
The name is defined in POSIX.1-2008,
but was not present in earlier POSIX.1 standards.
.TP
.I C99
The name is defined by C99.
.PP
Below is a list of the symbolic error names that are defined on Linux:
.TP 16
.B E2BIG
Argument list too long (POSIX.1-2001).
.TP
.B EACCES
Permission denied (POSIX.1-2001).
.TP
.B EADDRINUSE
Address already in use (POSIX.1-2001).
.TP
.B EADDRNOTAVAIL
Address not available (POSIX.1-2001).
.\" EADV is only an error on HURD(?)
.TP
.B EAFNOSUPPORT
Address family not supported (POSIX.1-2001).
.TP
.B EAGAIN
Resource temporarily unavailable (may be the same value as
.BR EWOULDBLOCK )
(POSIX.1-2001).
.TP
.B EALREADY
Connection already in progress (POSIX.1-2001).
.TP
.B EBADE
Invalid exchange.
.TP
.B EBADF
Bad file descriptor (POSIX.1-2001).
.TP
.B EBADFD
File descriptor in bad state.
.TP
.B EBADMSG
Bad message (POSIX.1-2001).
.TP
.B EBADR
Invalid request descriptor.
.TP
.B EBADRQC
Invalid request code.
.TP
.B EBADSLT
Invalid slot.
.\" EBFONT is defined but appears not to be used by kernel or glibc.
.TP
.B EBUSY
Device or resource busy (POSIX.1-2001).
.TP
.B ECANCELED
Operation canceled (POSIX.1-2001).
.TP
.B ECHILD
No child processes (POSIX.1-2001).
.TP
.B ECHRNG
Channel number out of range.
.TP
.B ECOMM
Communication error on send.
.TP
.B ECONNABORTED
Connection aborted (POSIX.1-2001).
.TP
.B ECONNREFUSED
Connection refused (POSIX.1-2001).
.TP
.B ECONNRESET
Connection reset (POSIX.1-2001).
.TP
.B EDEADLK
Resource deadlock avoided (POSIX.1-2001).
.TP
.B EDEADLOCK
On most architectures, a synonym for
.BR EDEADLK .
On some architectures (e.g., Linux MIPS, PowerPC, SPARC),
it is a separate error code "File locking deadlock error".
.TP
.B EDESTADDRREQ
Destination address required (POSIX.1-2001).
.TP
.B EDOM
Mathematics argument out of domain of function (POSIX.1, C99).
.\" EDOTDOT is defined but appears to be unused
.TP
.B EDQUOT
.\" POSIX just says "Reserved"
Disk quota exceeded (POSIX.1-2001).
.TP
.B EEXIST
File exists (POSIX.1-2001).
.TP
.B EFAULT
Bad address (POSIX.1-2001).
.TP
.B EFBIG
File too large (POSIX.1-2001).
.TP
.B EHOSTDOWN
Host is down.
.TP
.B EHOSTUNREACH
Host is unreachable (POSIX.1-2001).
.TP
.B EHWPOISON
Memory page has hardware error.
.TP
.B EIDRM
Identifier removed (POSIX.1-2001).
.TP
.B EILSEQ
Invalid or incomplete multibyte or wide character (POSIX.1, C99).
.IP
The text shown here is the glibc error description;
in POSIX.1, this error is described as "Illegal byte sequence".
.TP
.B EINPROGRESS
Operation in progress (POSIX.1-2001).
.TP
.B EINTR
Interrupted function call (POSIX.1-2001); see
.BR signal (7).
.TP
.B EINVAL
Invalid argument (POSIX.1-2001).
.TP
.B EIO
Input/output error (POSIX.1-2001).
.TP
.B EISCONN
Socket is connected (POSIX.1-2001).
.TP
.B EISDIR
Is a directory (POSIX.1-2001).
.TP
.B EISNAM
Is a named type file.
.TP
.B EKEYEXPIRED
Key has expired.
.TP
.B EKEYREJECTED
Key was rejected by service.
.TP
.B EKEYREVOKED
Key has been revoked.
.TP
.B EL2HLT
Level 2 halted.
.TP
.B EL2NSYNC
Level 2 not synchronized.
.TP
.B EL3HLT
Level 3 halted.
.TP
.B EL3RST
Level 3 reset.
.TP
.B ELIBACC
Cannot access a needed shared library.
.TP
.B ELIBBAD
Accessing a corrupted shared library.
.TP
.B ELIBMAX
Attempting to link in too many shared libraries.
.TP
.B ELIBSCN
\&.lib section in a.out corrupted
.TP
.B ELIBEXEC
Cannot exec a shared library directly.
.TP
.B ELNRNG
.\" ELNRNG appears to be used by a few drivers
Link number out of range.
.TP
.B ELOOP
Too many levels of symbolic links (POSIX.1-2001).
.TP
.B EMEDIUMTYPE
Wrong medium type.
.TP
.B EMFILE
Too many open files (POSIX.1-2001).
Commonly caused by exceeding the
.B RLIMIT_NOFILE
resource limit described in
.BR getrlimit (2).
Can also be caused by exceeding the limit specified in
.IR /proc/sys/fs/nr_open .
.TP
.B EMLINK
Too many links (POSIX.1-2001).
.TP
.B EMSGSIZE
Message too long (POSIX.1-2001).
.TP
.B EMULTIHOP
.\" POSIX says "Reserved"
Multihop attempted (POSIX.1-2001).
.TP
.B ENAMETOOLONG
Filename too long (POSIX.1-2001).
.\" ENAVAIL is defined, but appears not to be used
.TP
.B ENETDOWN
Network is down (POSIX.1-2001).
.TP
.B ENETRESET
Connection aborted by network (POSIX.1-2001).
.TP
.B ENETUNREACH
Network unreachable (POSIX.1-2001).
.TP
.B ENFILE
Too many open files in system (POSIX.1-2001).
On Linux, this is probably a result of encountering the
.I /proc/sys/fs/file\-max
limit (see
.BR proc (5)).
.TP
.B ENOANO
.\" ENOANO appears to be used by a few drivers
No anode.
.TP
.B ENOBUFS
No buffer space available (POSIX.1 (XSI STREAMS option)).
.\" ENOCSI is defined but appears to be unused.
.TP
.B ENODATA
The named attribute does not exist,
or the process has no access to this attribute; see
.BR xattr (7).
.IP
In POSIX.1-2001 (XSI STREAMS option),
this error was described as
"No message is available on the STREAM head read queue".
.TP
.B ENODEV
No such device (POSIX.1-2001).
.TP
.B ENOENT
No such file or directory (POSIX.1-2001).
.IP
Typically, this error results when a specified pathname does not exist,
or one of the components in the directory prefix of a pathname does not exist,
or the specified pathname is a dangling symbolic link.
.TP
.B ENOEXEC
Exec format error (POSIX.1-2001).
.TP
.B ENOKEY
Required key not available.
.TP
.B ENOLCK
No locks available (POSIX.1-2001).
.TP
.B ENOLINK
.\" POSIX says "Reserved"
Link has been severed (POSIX.1-2001).
.TP
.B ENOMEDIUM
No medium found.
.TP
.B ENOMEM
Not enough space/cannot allocate memory (POSIX.1-2001).
.TP
.B ENOMSG
No message of the desired type (POSIX.1-2001).
.TP
.B ENONET
Machine is not on the network.
.TP
.B ENOPKG
Package not installed.
.TP
.B ENOPROTOOPT
Protocol not available (POSIX.1-2001).
.TP
.B ENOSPC
No space left on device (POSIX.1-2001).
.TP
.B ENOSR
No STREAM resources (POSIX.1 (XSI STREAMS option)).
.TP
.B ENOSTR
Not a STREAM (POSIX.1 (XSI STREAMS option)).
.TP
.B ENOSYS
Function not implemented (POSIX.1-2001).
.TP
.B ENOTBLK
Block device required.
.TP
.B ENOTCONN
The socket is not connected (POSIX.1-2001).
.TP
.B ENOTDIR
Not a directory (POSIX.1-2001).
.TP
.B ENOTEMPTY
Directory not empty (POSIX.1-2001).
.\" ENOTNAM is defined but appears to be unused.
.TP
.B ENOTRECOVERABLE
State not recoverable (POSIX.1-2008).
.TP
.B ENOTSOCK
Not a socket (POSIX.1-2001).
.TP
.B ENOTSUP
Operation not supported (POSIX.1-2001).
.TP
.B ENOTTY
Inappropriate I/O control operation (POSIX.1-2001).
.TP
.B ENOTUNIQ
Name not unique on network.
.TP
.B ENXIO
No such device or address (POSIX.1-2001).
.TP
.B EOPNOTSUPP
Operation not supported on socket (POSIX.1-2001).
.IP
.RB ( ENOTSUP
and
.B EOPNOTSUPP
have the same value on Linux, but
according to POSIX.1 these error values should be distinct.)
.TP
.B EOVERFLOW
Value too large to be stored in data type (POSIX.1-2001).
.TP
.B EOWNERDEAD
.\" Used at least by the user-space side of rubost mutexes
Owner died (POSIX.1-2008).
.TP
.B EPERM
Operation not permitted (POSIX.1-2001).
.TP
.B EPFNOSUPPORT
Protocol family not supported.
.TP
.B EPIPE
Broken pipe (POSIX.1-2001).
.TP
.B EPROTO
Protocol error (POSIX.1-2001).
.TP
.B EPROTONOSUPPORT
Protocol not supported (POSIX.1-2001).
.TP
.B EPROTOTYPE
Protocol wrong type for socket (POSIX.1-2001).
.TP
.B ERANGE
Result too large (POSIX.1, C99).
.TP
.B EREMCHG
Remote address changed.
.TP
.B EREMOTE
Object is remote.
.TP
.B EREMOTEIO
Remote I/O error.
.TP
.B ERESTART
Interrupted system call should be restarted.
.TP
.B ERFKILL
.\" ERFKILL appears to be used by various drivers
Operation not possible due to RF-kill.
.TP
.B EROFS
Read-only filesystem (POSIX.1-2001).
.TP
.B ESHUTDOWN
Cannot send after transport endpoint shutdown.
.TP
.B ESPIPE
Invalid seek (POSIX.1-2001).
.TP
.B ESOCKTNOSUPPORT
Socket type not supported.
.TP
.B ESRCH
No such process (POSIX.1-2001).
.\" ESRMNT is defined but appears not to be used
.TP
.B ESTALE
Stale file handle (POSIX.1-2001).
.IP
This error can occur for NFS and for other filesystems.
.TP
.B ESTRPIPE
Streams pipe error.
.TP
.B ETIME
Timer expired
(POSIX.1 (XSI STREAMS option)).
.IP
(POSIX.1 says "STREAM
.BR ioctl (2)
timeout".)
.TP
.B ETIMEDOUT
Connection timed out (POSIX.1-2001).
.TP
.B ETOOMANYREFS
.\" ETOOMANYREFS seems to be used in net/unix/af_unix.c
Too many references: cannot splice.
.TP
.B ETXTBSY
Text file busy (POSIX.1-2001).
.TP
.B EUCLEAN
Structure needs cleaning.
.TP
.B EUNATCH
Protocol driver not attached.
.TP
.B EUSERS
Too many users.
.TP
.B EWOULDBLOCK
Operation would block (may be same value as
.BR EAGAIN )
(POSIX.1-2001).
.TP
.B EXDEV
Invalid cross-device link (POSIX.1-2001).
.TP
.B EXFULL
Exchange full.
.SH NOTES
A common mistake is to do
.PP
.in +4n
.EX
if (somecall() == \-1) {
printf("somecall() failed\en");
if (errno == ...) { ... }
}
.EE
.in
.PP
where
.I errno
no longer needs to have the value it had upon return from
.IR somecall ()
(i.e., it may have been changed by the
.BR printf (3)).
If the value of
.I errno
should be preserved across a library call, it must be saved:
.PP
.in +4n
.EX
if (somecall() == \-1) {
int errsv = errno;
printf("somecall() failed\en");
if (errsv == ...) { ... }
}
.EE
.in
.PP
Note that the POSIX threads APIs do
.I not
set
.I errno
on error.
Instead, on failure they return an error number as the function result.
These error numbers have the same meanings as the error numbers returned in
.I errno
by other APIs.
.PP
On some ancient systems,
.I <errno.h>
was not present or did not declare
.IR errno ,
so that it was necessary to declare
.I errno
manually
(i.e.,
.IR "extern int errno" ).
.BR "Do not do this" .
It long ago ceased to be necessary,
and it will cause problems with modern versions of the C library.
.SH SEE ALSO
.BR errno (1), \" In the moreutils package
.BR err (3),
.BR error (3),
.BR perror (3),
.BR strerror (3)
|