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