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
|
.\" Copyright (c) 1996 Andries Brouwer (aeb@cwi.nl)
.\"
.\" This is free documentation; you can redistribute it and/or
.\" modify it under the terms of the GNU General Public License as
.\" published by the Free Software Foundation; either version 2 of
.\" the License, or (at your option) any later version.
.\"
.\" The GNU General Public License's references to "object code"
.\" and "executables" are to be interpreted as the output of any
.\" document formatting or typesetting system, including
.\" intermediate and printed output.
.\"
.\" This manual is distributed in the hope that it will be useful,
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
.\" GNU General Public License for more details.
.\"
.\" You should have received a copy of the GNU General Public
.\" License along with this manual; if not, write to the Free
.\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111,
.\" USA.
.\"
.\" 5 Oct 2002, Modified by Michael Kerrisk <mtk-manpages@gmx.net>
.\" 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 2006-02-09 "" "Library functions"
.SH NAME
errno \- number of last error
.SH SYNOPSIS
.B #include <errno.h>
.\".sp
.\".BI "extern int " errno ;
.SH DESCRIPTION
The
.I <errno.h>
header file defines the integer variable
.BR errno ,
which is set by system calls and some library functions in the event
of an error to indicate what went wrong.
Its value is significant only when the call
returned an error (usually \-1), and a function that does succeed
is allowed to change
.BR errno .
Sometimes, when \-1 is also a valid successful return value
one has to zero
.B errno
before the call in order to detect possible errors.
\fBerrno\fR is defined by the ISO C standard to be a modifiable lvalue
of type \fIint\fR, and must not be explicitly declared; \fBerrno\fR
may be a macro. \fBerrno\fR is thread-local; setting it in one thread
does not affect its value in any other thread.
Valid error numbers are all non-zero; \fBerrno\fR is never set to zero
by any library function. 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.
.\" The following is now
.\" POSIX.1 (2001 edition) lists the following symbolic error names. Of
.\" these, \fBEDOM\fR and \fBERANGE\fR are in the ISO C standard. ISO C
.\" Amendment 1 defines the additional error number \fBEILSEQ\fR for
.\" coding errors in multibyte or wide characters.
.\"
Below is a list of the symbolic error names that are defined on Linux.
Some of these are marked
.IR POSIX.1 ,
indicating that the name is defined by POSIX.1-2001, or
.IR C99 ,
indicating that the name is defined by C99.
.TP
.BR E2BIG
Argument list too long (POSIX.1)
.TP
.BR EACCES
Permission denied (POSIX.1)
.TP
.BR EADDRINUSE
Address already in use (POSIX.1)
.TP
.BR EADDRNOTAVAIL
Address not available (POSIX.1)
.\" EADV is only an error on HURD(?)
.TP
.BR EAFNOSUPPORT
Address family not supported (POSIX.1)
.TP
.BR EAGAIN
Resource temporarily unavailable (may be the same value as
.BR EWOULDBLOCK )
(POSIX.1)
.TP
.BR EALREADY
Connection already in progress (POSIX.1)
.TP
.BR EBADE
Invalid exchange
.TP
.BR EBADF
Bad file descriptor (POSIX.1)
.TP
.BR EBADFD
File descriptor in bad state
.TP
.BR EBADMSG
Bad message (POSIX.1)
.TP
.BR EBADR
Invalid request descriptor
.TP
.BR EBADRQC
Invalid request code
.TP
.BR EBADSLT
Invalid slot
.\" EBFONT is defined but appears not to be used by kernel or glibc.
.TP
.BR EBUSY
Device or resource busy (POSIX.1)
.TP
.BR ECANCELED
Operation canceled (POSIX.1)
.TP
.BR ECHILD
No child processes (POSIX.1)
.TP
.B ECHRNG
Channel number out of range
.TP
.B ECOMM
Communication error on send
.TP
.BR ECONNABORTED
Connection aborted (POSIX.1)
.TP
.BR ECONNREFUSED
Connection refused (POSIX.1)
.TP
.BR ECONNRESET
Connection reset (POSIX.1)
.TP
.BR EDEADLK
Resource deadlock avoided (POSIX.1)
.TP
.BR EDEADLOCK
Synonym for
.B EDEADLK
.TP
.BR EDESTADDRREQ
Destination address required (POSIX.1)
.TP
.BR EDOM
Mathematics argument out of domain of function (POSIX.1, C99)
.\" EDOTDOT is defined but appears to be unused
.TP
.BR EDQUOT
.\" POSIX just says "Reserved"
Disk quota exceeded (POSIX.1)
.TP
.BR EEXIST
File exists (POSIX.1)
.TP
.BR EFAULT
Bad address (POSIX.1)
.TP
.BR EFBIG
File too large (POSIX.1)
.TP
.BR EHOSTDOWN
Host is down
.TP
.BR EHOSTUNREACH
Host is unreachable (POSIX.1)
.TP
.BR EIDRM
Identifier removed (POSIX.1)
.TP
.BR EILSEQ
Illegal byte sequence (POSIX.1, C99)
.TP
.BR EINPROGRESS
Operation in progress (POSIX.1)
.TP
.BR EINTR
Interrupted function call (POSIX.1)
.TP
.BR EINVAL
Invalid argument (POSIX.1)
.TP
.BR EIO
Input/output error (POSIX.1)
.TP
.BR EISCONN
Socket is connected (POSIX.1)
.TP
.BR EISDIR
Is a directory (POSIX.1)
.TP
.BR EISNAM
Is a named type file
.TP
.BR EKEYEXPIRED
Key has expired
.TP
.BR EKEYREJECTED
Key was rejected by service
.TP
.BR 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 halted
.TP
.BR ELIBACC
Cannot access a needed shared library
.TP
.BR ELIBBAD
Accessing a corrupted shared library
.TP
.BR ELIBMAX
Attempting to link in too many shared libraries
.TP
.BR ELIBSCN
lib section in a.out corrupted
.TP
.BR ELIBEXEC
Cannot exec a shared library directly
.TP
.BR ELOOP
Too many levels of symbolic links (POSIX.1)
.\" ELNRNG is defined but appears to be unused
.TP
.BR EMEDIUMTYPE
Wrong medium type
.TP
.BR EMFILE
Too many open files (POSIX.1)
.TP
.BR EMLINK
Too many links (POSIX.1)
.TP
.BR EMSGSIZE
Message too long (POSIX.1)
.TP
.BR EMULTIHOP
.\" POSIX says "Reserved"
Multihop attempted (POSIX.1)
.TP
.BR ENAMETOOLONG
Filename too long (POSIX.1)
.\" ENAVAIL is defined, but appears not to be used
.TP
.BR ENETDOWN
Network is down (POSIX.1)
.TP
.BR ENETRESET
Connection aborted by network (POSIX.1)
.TP
.BR ENETUNREACH
Network unreachable (POSIX.1)
.TP
.BR ENFILE
Too many open files in system (POSIX.1)
.\" ENOANO is defined but appears to be unused.
.TP
.BR ENOBUFS
No buffer space available (POSIX.1 (XSI STREAMS option))
.\" ENOCSI is defined but appears to be unused.
.TP
.BR ENODATA
No message is available on the STREAM head read queue (POSIX.1)
.TP
.BR ENODEV
No such device (POSIX.1)
.TP
.BR ENOENT
No such file or directory (POSIX.1)
.TP
.BR ENOEXEC
Exec format error (POSIX.1)
.TP
.BR ENOKEY
Required key not available
.TP
.BR ENOLCK
No locks available (POSIX.1)
.TP
.BR ENOLINK
.\" POSIX says "Reserved"
Link has been severed (POSIX.1)
.TP
.BR ENOMEDIUM
No medium found
.TP
.BR ENOMEM
Not enough space (POSIX.1)
.TP
.BR ENOMSG
No message of the desired type (POSIX.1)
.TP
.BR ENONET
Machine is not on the network
.TP
.BR ENOPKG
Package not installed
.TP
.BR ENOPROTOOPT
Protocol not available (POSIX.1)
.TP
.BR ENOSPC
No space left on device (POSIX.1)
.TP
.BR ENOSR
No STREAM resources (POSIX.1 (XSI STREAMS option))
.TP
.BR ENOSTR
Not a STREAM (POSIX.1 (XSI STREAMS option))
.TP
.BR ENOSYS
Function not implemented (POSIX.1)
.TP
.BR ENOTBLK
Block device required
.TP
.BR ENOTCONN
The socket is not connected (POSIX.1)
.TP
.BR ENOTDIR
Not a directory (POSIX.1)
.TP
.BR ENOTEMPTY
Directory not empty (POSIX.1)
.\" ENOTNAM is defined but appears to be unused.
.TP
.BR ENOTSOCK
Not a socket (POSIX.1)
.TP
.BR ENOTSUP
Operation not supported (POSIX.1)
.TP
.BR ENOTTY
Inappropriate I/O control operation (POSIX.1)
.TP
.BR ENOTUNIQ
Name not unique on network
.TP
.BR ENXIO
No such device or address (POSIX.1)
.TP
.BR EOPNOTSUPP
Operation not supported on socket (POSIX.1)
.sp
(ENOTSUP and EOPNOTSUPP have the same value on Linux, but
according to POSIX.1 these error values should be distinct.)
.TP
.BR EOVERFLOW
Value too large to be stored in data type (POSIX.1)
.TP
.BR EPERM
Operation not permitted (POSIX.1)
.TP
.BR EPFNOSUPPORT
Protocol family not supported
.TP
.BR EPIPE
Broken pipe (POSIX.1)
.TP
.BR EPROTO
Protocol error (POSIX.1)
.TP
.BR EPROTONOSUPPORT
Protocol not supported (POSIX.1)
.TP
.BR EPROTOTYPE
Protocol wrong type for socket (POSIX.1)
.TP
.BR ERANGE
Result too large (POSIX.1, C99)
.TP
.BR EREMCHG
Remote address changed
.TP
.BR EREMOTE
Object is remote
.TP
.BR EREMOTEIO
Remote I/O error
.TP
.BR ERESTART
Interrupted system call should be restarted
.TP
.BR EROFS
Read-only file system (POSIX.1)
.TP
.BR ESHUTDOWN
Cannot send after transport endpoint shutdown
.TP
.BR ESPIPE
Invalid seek (POSIX.1)
.TP
.BR ESOCKTNOSUPPORT
Socket type not supported
.TP
.BR ESRCH
No such process (POSIX.1)
.\" ESRMNT is defined but appears not to be used
.TP
.BR ESTALE
Stale file handle (POSIX.1)
.sp
This error can occur for NFS and for other file systems
.TP
.BR ESTRPIPE
Streams pipe error
.TP
.BR ETIME
Timer expired
(POSIX.1 (XSI STREAMS option))
.sp
(POSIX.1 says "STREAM
.BR ioctl ()
timeout")
.TP
.BR ETIMEDOUT
Connection timed out (POSIX.1)
.\" ETOOMANYREFS is defined, but appears not to be used.
.TP
.BR ETXTBSY
Text file busy (POSIX.1)
.TP
.BR EUCLEAN
Structure needs cleaning
.TP
.BR EUNATCH
Protocol driver not attached
.TP
.BR EUSERS
Too many users
.TP
.BR EWOULDBLOCK
Operation would block (may be same value as
.BR EAGAIN )
(POSIX.1)
.TP
.BR EXDEV
Improper link (POSIX.1)
.TP
.B EXFULL
Exchange full
.SH NOTES
A common mistake is to do
.RS
.nf
if (somecall() == \-1) {
printf("somecall() failed\en");
if (errno == ...) { ... }
}
.fi
.RE
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 ()).
If the value of
.I errno
should be preserved across a library call, it must be saved:
.RS
.nf
if (somecall() == \-1) {
int errsv = errno;
printf("somecall() failed\en");
if (errsv == ...) { ... }
}
.fi
.RE
.PP
It was common in traditional C to declare
.I errno
manually
(i.e.,
.IR "extern int errno" )
instead of including
.IR <errno.h> .
.BR "Do not do this" .
It will not work with modern versions of the C library.
However, on (very) old Unix systems, there may be no
.I <errno.h>
and the declaration is needed.
.SH "SEE ALSO"
.BR err (3),
.BR error (3),
.BR perror (3),
.BR strerror (3)
|