OSDN Git Service

26b34732c8c9599eb6874123546a424c885272a9
[linuxjm/LDP_man-pages.git] / original / man3 / errno.3
1 .\" Copyright (c) 1996 Andries Brouwer (aeb@cwi.nl)
2 .\"
3 .\" %%%LICENSE_START(GPLv2+_DOC_FULL)
4 .\" This is free documentation; you can redistribute it and/or
5 .\" modify it under the terms of the GNU General Public License as
6 .\" published by the Free Software Foundation; either version 2 of
7 .\" the License, or (at your option) any later version.
8 .\"
9 .\" The GNU General Public License's references to "object code"
10 .\" and "executables" are to be interpreted as the output of any
11 .\" document formatting or typesetting system, including
12 .\" intermediate and printed output.
13 .\"
14 .\" This manual is distributed in the hope that it will be useful,
15 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
16 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 .\" GNU General Public License for more details.
18 .\"
19 .\" You should have received a copy of the GNU General Public
20 .\" License along with this manual; if not, see
21 .\" <http://www.gnu.org/licenses/>.
22 .\" %%%LICENSE_END
23 .\"
24 .\" 5 Oct 2002, Modified by Michael Kerrisk <mtk.manpages@gmail.com>
25 .\"     Updated for POSIX.1 2001
26 .\" 2004-12-17 Martin Schulze <joey@infodrom.org>, mtk
27 .\"     Removed errno declaration prototype, added notes
28 .\" 2006-02-09 Kurt Wall, mtk
29 .\"     Added non-POSIX errors
30 .\"
31 .TH ERRNO 3 2008-07-09 "" "Linux Programmer's Manual"
32 .SH NAME
33 errno \- number of last error
34 .SH SYNOPSIS
35 .B #include <errno.h>
36 .\".sp
37 .\".BI "extern int " errno ;
38 .SH DESCRIPTION
39 The
40 .I <errno.h>
41 header file defines the integer variable
42 .IR errno ,
43 which is set by system calls and some library functions in the event
44 of an error to indicate what went wrong.
45 Its value is significant only when the return value of
46 the call indicated an error
47 (i.e., \-1 from most system calls;
48 \-1 or NULL from most library functions);
49 a function that succeeds
50 .I is
51 allowed to change
52 .IR errno .
53
54 Valid error numbers are all nonzero;
55 .I errno
56 is never set to zero
57 by any system call or library function.
58
59 For some system calls and library functions (e.g.,
60 .BR getpriority (2)),
61 \-1 is a valid return on success.
62 In such cases, a successful return can be distinguished from an error
63 return by setting
64 .I errno
65 to zero before the call, and then,
66 if the call returns a status that indicates that an error
67 may have occurred, checking to see if
68 .I errno
69 has a nonzero value.
70
71 .I errno
72 is defined by the ISO C standard to be a modifiable lvalue
73 of type
74 .IR int ,
75 and must not be explicitly declared;
76 .I errno
77 may be a macro.
78 .I errno
79 is thread-local; setting it in one thread
80 does not affect its value in any other thread.
81
82 All the error names specified by POSIX.1
83 must have distinct values, with the exception of
84 .B EAGAIN
85 and
86 .BR EWOULDBLOCK ,
87 which may be the same.
88
89 .\" The following is now
90 .\" POSIX.1 (2001 edition) lists the following symbolic error names.  Of
91 .\" these, \fBEDOM\fP and \fBERANGE\fP are in the ISO C standard.  ISO C
92 .\" Amendment 1 defines the additional error number \fBEILSEQ\fP for
93 .\" coding errors in multibyte or wide characters.
94 .\"
95 Below is a list of the symbolic error names that are defined on Linux.
96 Some of these are marked
97 .IR POSIX.1 ,
98 indicating that the name is defined by POSIX.1-2001, or
99 .IR C99 ,
100 indicating that the name is defined by C99.
101 .TP 16
102 .B E2BIG
103 Argument list too long (POSIX.1)
104 .TP
105 .B EACCES
106 Permission denied (POSIX.1)
107 .TP
108 .B EADDRINUSE
109 Address already in use (POSIX.1)
110 .TP
111 .B EADDRNOTAVAIL
112 Address not available (POSIX.1)
113 .\" EADV is only an error on HURD(?)
114 .TP
115 .B EAFNOSUPPORT
116 Address family not supported (POSIX.1)
117 .TP
118 .B EAGAIN
119 Resource temporarily unavailable (may be the same value as
120 .BR EWOULDBLOCK )
121 (POSIX.1)
122 .TP
123 .B EALREADY
124 Connection already in progress (POSIX.1)
125 .TP
126 .B EBADE
127 Invalid exchange
128 .TP
129 .B EBADF
130 Bad file descriptor (POSIX.1)
131 .TP
132 .B EBADFD
133 File descriptor in bad state
134 .TP
135 .B EBADMSG
136 Bad message (POSIX.1)
137 .TP
138 .B EBADR
139 Invalid request descriptor
140 .TP
141 .B EBADRQC
142 Invalid request code
143 .TP
144 .B EBADSLT
145 Invalid slot
146 .\" EBFONT is defined but appears not to be used by kernel or glibc.
147 .TP
148 .B EBUSY
149 Device or resource busy (POSIX.1)
150 .TP
151 .B ECANCELED
152 Operation canceled (POSIX.1)
153 .TP
154 .B ECHILD
155 No child processes (POSIX.1)
156 .TP
157 .B ECHRNG
158 Channel number out of range
159 .TP
160 .B ECOMM
161 Communication error on send
162 .TP
163 .B ECONNABORTED
164 Connection aborted (POSIX.1)
165 .TP
166 .B ECONNREFUSED
167 Connection refused (POSIX.1)
168 .TP
169 .B ECONNRESET
170 Connection reset (POSIX.1)
171 .TP
172 .B EDEADLK
173 Resource deadlock avoided (POSIX.1)
174 .TP
175 .B EDEADLOCK
176 Synonym for
177 .B EDEADLK
178 .TP
179 .B EDESTADDRREQ
180 Destination address required (POSIX.1)
181 .TP
182 .B EDOM
183 Mathematics argument out of domain of function (POSIX.1, C99)
184 .\" EDOTDOT is defined but appears to be unused
185 .TP
186 .B EDQUOT
187 .\" POSIX just says "Reserved"
188 Disk quota exceeded (POSIX.1)
189 .TP
190 .B EEXIST
191 File exists (POSIX.1)
192 .TP
193 .B EFAULT
194 Bad address (POSIX.1)
195 .TP
196 .B EFBIG
197 File too large (POSIX.1)
198 .TP
199 .B EHOSTDOWN
200 Host is down
201 .TP
202 .B EHOSTUNREACH
203 Host is unreachable (POSIX.1)
204 .TP
205 .B EIDRM
206 Identifier removed (POSIX.1)
207 .TP
208 .B EILSEQ
209 Illegal byte sequence (POSIX.1, C99)
210 .TP
211 .B EINPROGRESS
212 Operation in progress (POSIX.1)
213 .TP
214 .B EINTR
215 Interrupted function call (POSIX.1); see
216 .BR signal (7).
217 .TP
218 .B EINVAL
219 Invalid argument (POSIX.1)
220 .TP
221 .B EIO
222 Input/output error (POSIX.1)
223 .TP
224 .B EISCONN
225 Socket is connected (POSIX.1)
226 .TP
227 .B EISDIR
228 Is a directory (POSIX.1)
229 .TP
230 .B EISNAM
231 Is a named type file
232 .TP
233 .B EKEYEXPIRED
234 Key has expired
235 .TP
236 .B EKEYREJECTED
237 Key was rejected by service
238 .TP
239 .B EKEYREVOKED
240 Key has been revoked
241 .TP
242 .B EL2HLT
243 Level 2 halted
244 .TP
245 .B EL2NSYNC
246 Level 2 not synchronized
247 .TP
248 .B EL3HLT
249 Level 3 halted
250 .TP
251 .B EL3RST
252 Level 3 halted
253 .TP
254 .B ELIBACC
255 Cannot access a needed shared library
256 .TP
257 .B ELIBBAD
258 Accessing a corrupted shared library
259 .TP
260 .B ELIBMAX
261 Attempting to link in too many shared libraries
262 .TP
263 .B ELIBSCN
264 lib section in a.out corrupted
265 .TP
266 .B ELIBEXEC
267 Cannot exec a shared library directly
268 .TP
269 .B ELOOP
270 Too many levels of symbolic links (POSIX.1)
271 .\" ELNRNG is defined but appears to be unused
272 .TP
273 .B EMEDIUMTYPE
274 Wrong medium type
275 .TP
276 .B EMFILE
277 Too many open files (POSIX.1)
278 .TP
279 .B EMLINK
280 Too many links (POSIX.1)
281 .TP
282 .B EMSGSIZE
283 Message too long (POSIX.1)
284 .TP
285 .B EMULTIHOP
286 .\" POSIX says "Reserved"
287 Multihop attempted (POSIX.1)
288 .TP
289 .B ENAMETOOLONG
290 Filename too long (POSIX.1)
291 .\" ENAVAIL is defined, but appears not to be used
292 .TP
293 .B ENETDOWN
294 Network is down (POSIX.1)
295 .TP
296 .B ENETRESET
297 Connection aborted by network (POSIX.1)
298 .TP
299 .B ENETUNREACH
300 Network unreachable (POSIX.1)
301 .TP
302 .B ENFILE
303 Too many open files in system (POSIX.1)
304 .\" ENOANO is defined but appears to be unused.
305 .TP
306 .B ENOBUFS
307 No buffer space available (POSIX.1 (XSI STREAMS option))
308 .\" ENOCSI is defined but appears to be unused.
309 .TP
310 .B ENODATA
311 No message is available on the STREAM head read queue (POSIX.1)
312 .TP
313 .B ENODEV
314 No such device (POSIX.1)
315 .TP
316 .B ENOENT
317 No such file or directory (POSIX.1)
318 .TP
319 .B ENOEXEC
320 Exec format error (POSIX.1)
321 .TP
322 .B ENOKEY
323 Required key not available
324 .TP
325 .B ENOLCK
326 No locks available (POSIX.1)
327 .TP
328 .B ENOLINK
329 .\" POSIX says "Reserved"
330 Link has been severed (POSIX.1)
331 .TP
332 .B ENOMEDIUM
333 No medium found
334 .TP
335 .B ENOMEM
336 Not enough space (POSIX.1)
337 .TP
338 .B ENOMSG
339 No message of the desired type (POSIX.1)
340 .TP
341 .B ENONET
342 Machine is not on the network
343 .TP
344 .B ENOPKG
345 Package not installed
346 .TP
347 .B ENOPROTOOPT
348 Protocol not available (POSIX.1)
349 .TP
350 .B ENOSPC
351 No space left on device (POSIX.1)
352 .TP
353 .B ENOSR
354 No STREAM resources (POSIX.1 (XSI STREAMS option))
355 .TP
356 .B ENOSTR
357 Not a STREAM (POSIX.1 (XSI STREAMS option))
358 .TP
359 .B ENOSYS
360 Function not implemented (POSIX.1)
361 .TP
362 .B ENOTBLK
363 Block device required
364 .TP
365 .B ENOTCONN
366 The socket is not connected (POSIX.1)
367 .TP
368 .B ENOTDIR
369 Not a directory (POSIX.1)
370 .TP
371 .B ENOTEMPTY
372 Directory not empty (POSIX.1)
373 .\" ENOTNAM is defined but appears to be unused.
374 .TP
375 .B ENOTSOCK
376 Not a socket (POSIX.1)
377 .TP
378 .B ENOTSUP
379 Operation not supported (POSIX.1)
380 .TP
381 .B ENOTTY
382 Inappropriate I/O control operation (POSIX.1)
383 .TP
384 .B ENOTUNIQ
385 Name not unique on network
386 .TP
387 .B ENXIO
388 No such device or address (POSIX.1)
389 .TP
390 .B EOPNOTSUPP
391 Operation not supported on socket (POSIX.1)
392 .sp
393 .RB ( ENOTSUP
394 and
395 .B EOPNOTSUPP
396 have the same value on Linux, but
397 according to POSIX.1 these error values should be distinct.)
398 .TP
399 .B EOVERFLOW
400 Value too large to be stored in data type (POSIX.1)
401 .TP
402 .B EPERM
403 Operation not permitted (POSIX.1)
404 .TP
405 .B EPFNOSUPPORT
406 Protocol family not supported
407 .TP
408 .B EPIPE
409 Broken pipe (POSIX.1)
410 .TP
411 .B EPROTO
412 Protocol error (POSIX.1)
413 .TP
414 .B EPROTONOSUPPORT
415 Protocol not supported (POSIX.1)
416 .TP
417 .B EPROTOTYPE
418 Protocol wrong type for socket (POSIX.1)
419 .TP
420 .B ERANGE
421 Result too large (POSIX.1, C99)
422 .TP
423 .B EREMCHG
424 Remote address changed
425 .TP
426 .B EREMOTE
427 Object is remote
428 .TP
429 .B EREMOTEIO
430 Remote I/O error
431 .TP
432 .B ERESTART
433 Interrupted system call should be restarted
434 .TP
435 .B EROFS
436 Read-only filesystem (POSIX.1)
437 .TP
438 .B ESHUTDOWN
439 Cannot send after transport endpoint shutdown
440 .TP
441 .B ESPIPE
442 Invalid seek (POSIX.1)
443 .TP
444 .B ESOCKTNOSUPPORT
445 Socket type not supported
446 .TP
447 .B ESRCH
448 No such process (POSIX.1)
449 .\" ESRMNT is defined but appears not to be used
450 .TP
451 .B ESTALE
452 Stale file handle (POSIX.1)
453 .sp
454 This error can occur for NFS and for other filesystems
455 .TP
456 .B ESTRPIPE
457 Streams pipe error
458 .TP
459 .B ETIME
460 Timer expired
461 (POSIX.1 (XSI STREAMS option))
462 .sp
463 (POSIX.1 says "STREAM
464 .BR ioctl (2)
465 timeout")
466 .TP
467 .B ETIMEDOUT
468 Connection timed out (POSIX.1)
469 .\" ETOOMANYREFS is defined, but appears not to be used.
470 .TP
471 .B ETXTBSY
472 Text file busy (POSIX.1)
473 .TP
474 .B EUCLEAN
475 Structure needs cleaning
476 .TP
477 .B EUNATCH
478 Protocol driver not attached
479 .TP
480 .B EUSERS
481 Too many users
482 .TP
483 .B EWOULDBLOCK
484 Operation would block (may be same value as
485 .BR EAGAIN )
486 (POSIX.1)
487 .TP
488 .B EXDEV
489 Improper link (POSIX.1)
490 .TP
491 .B EXFULL
492 Exchange full
493 .SH NOTES
494 A common mistake is to do
495 .in +4n
496 .nf
497
498 if (somecall() == \-1) {
499     printf("somecall() failed\en");
500     if (errno == ...) { ... }
501 }
502
503 .fi
504 .in
505 where
506 .I errno
507 no longer needs to have the value it had upon return from
508 .IR somecall ()
509 (i.e., it may have been changed by the
510 .BR printf (3)).
511 If the value of
512 .I errno
513 should be preserved across a library call, it must be saved:
514 .in +4n
515 .nf
516
517 if (somecall() == \-1) {
518     int errsv = errno;
519     printf("somecall() failed\en");
520     if (errsv == ...) { ... }
521 }
522 .fi
523 .in
524 .PP
525 It was common in traditional C to declare
526 .I errno
527 manually
528 (i.e.,
529 .IR "extern int errno" )
530 instead of including
531 .IR <errno.h> .
532 .BR "Do not do this" .
533 It will not work with modern versions of the C library.
534 However, on (very) old UNIX systems, there may be no
535 .I <errno.h>
536 and the declaration is needed.
537 .SH SEE ALSO
538 .BR err (3),
539 .BR error (3),
540 .BR perror (3),
541 .BR strerror (3)
542 .SH COLOPHON
543 This page is part of release 3.67 of the Linux
544 .I man-pages
545 project.
546 A description of the project,
547 information about reporting bugs,
548 and the latest version of this page,
549 can be found at
550 \%http://www.kernel.org/doc/man\-pages/.