1 @node Error Reporting, Memory, Introduction, Top
2 @chapter Error Reporting
3 @c %MENU% How library functions report errors
4 @cindex error reporting
5 @cindex reporting errors
9 Many functions in @theglibc{} detect and report error conditions,
10 and sometimes your programs need to check for these error conditions.
11 For example, when you open an input file, you should verify that the
12 file was actually opened correctly, and print an error message or take
13 other appropriate action if the call to the library function failed.
15 This chapter describes how the error reporting facility works. Your
16 program should include the header file @file{errno.h} to use this
21 * Checking for Errors:: How errors are reported by library functions.
22 * Error Codes:: Error code macros; all of these expand
23 into integer constant values.
24 * Error Messages:: Mapping error codes onto error messages.
27 @node Checking for Errors, Error Codes, , Error Reporting
28 @section Checking for Errors
30 Most library functions return a special value to indicate that they have
31 failed. The special value is typically @code{-1}, a null pointer, or a
32 constant such as @code{EOF} that is defined for that purpose. But this
33 return value tells you only that an error has occurred. To find out
34 what kind of error it was, you need to look at the error code stored in the
35 variable @code{errno}. This variable is declared in the header file
41 @deftypevr {Variable} {volatile int} errno
42 The variable @code{errno} contains the system error number. You can
43 change the value of @code{errno}.
45 Since @code{errno} is declared @code{volatile}, it might be changed
46 asynchronously by a signal handler; see @ref{Defining Handlers}.
47 However, a properly written signal handler saves and restores the value
48 of @code{errno}, so you generally do not need to worry about this
49 possibility except when writing signal handlers.
51 The initial value of @code{errno} at program startup is zero. Many
52 library functions are guaranteed to set it to certain nonzero values
53 when they encounter certain kinds of errors. These error conditions are
54 listed for each function. These functions do not change @code{errno}
55 when they succeed; thus, the value of @code{errno} after a successful
56 call is not necessarily zero, and you should not use @code{errno} to
57 determine @emph{whether} a call failed. The proper way to do that is
58 documented for each function. @emph{If} the call failed, you can
61 Many library functions can set @code{errno} to a nonzero value as a
62 result of calling other library functions which might fail. You should
63 assume that any library function might alter @code{errno} when the
64 function returns an error.
66 @strong{Portability Note:} @w{ISO C} specifies @code{errno} as a
67 ``modifiable lvalue'' rather than as a variable, permitting it to be
68 implemented as a macro. For example, its expansion might involve a
69 function call, like @w{@code{*__errno_location ()}}. In fact, that is
71 on @gnulinuxhurdsystems{}. @Theglibc{}, on each system, does
72 whatever is right for the particular system.
74 There are a few library functions, like @code{sqrt} and @code{atan},
75 that return a perfectly legitimate value in case of an error, but also
76 set @code{errno}. For these functions, if you want to check to see
77 whether an error occurred, the recommended method is to set @code{errno}
78 to zero before calling the function, and then check its value afterward.
82 All the error codes have symbolic names; they are macros defined in
83 @file{errno.h}. The names start with @samp{E} and an upper-case
84 letter or digit; you should consider names of this form to be
85 reserved names. @xref{Reserved Names}.
87 The error code values are all positive integers and are all distinct,
88 with one exception: @code{EWOULDBLOCK} and @code{EAGAIN} are the same.
89 Since the values are distinct, you can use them as labels in a
90 @code{switch} statement; just don't use both @code{EWOULDBLOCK} and
91 @code{EAGAIN}. Your program should not make any other assumptions about
92 the specific values of these symbolic constants.
94 The value of @code{errno} doesn't necessarily have to correspond to any
95 of these macros, since some library functions might return other error
96 codes of their own for other situations. The only values that are
97 guaranteed to be meaningful for a particular library function are the
98 ones that this manual lists for that function.
100 Except on @gnuhurdsystems{}, almost any system call can return @code{EFAULT} if
101 it is given an invalid pointer as an argument. Since this could only
102 happen as a result of a bug in your program, and since it will not
103 happen on @gnuhurdsystems{}, we have saved space by not mentioning
104 @code{EFAULT} in the descriptions of individual functions.
106 In some Unix systems, many system calls can also return @code{EFAULT} if
107 given as an argument a pointer into the stack, and the kernel for some
108 obscure reason fails in its attempt to extend the stack. If this ever
109 happens, you should probably try using statically or dynamically
110 allocated memory instead of stack memory on that system.
112 @node Error Codes, Error Messages, Checking for Errors, Error Reporting
116 The error code macros are defined in the header file @file{errno.h}.
117 All of them expand into integer constant values. Some of these error
118 codes can't occur on @gnusystems{}, but they can occur using @theglibc{}
122 @comment POSIX.1: Operation not permitted
123 @deftypevr Macro int EPERM
124 @comment errno 1 @c DO NOT REMOVE
125 Operation not permitted; only the owner of the file (or other resource)
126 or processes with special privileges can perform the operation.
130 @comment POSIX.1: No such file or directory
131 @deftypevr Macro int ENOENT
132 @comment errno 2 @c DO NOT REMOVE
133 No such file or directory. This is a ``file doesn't exist'' error
134 for ordinary files that are referenced in contexts where they are
135 expected to already exist.
139 @comment POSIX.1: No such process
140 @deftypevr Macro int ESRCH
141 @comment errno 3 @c DO NOT REMOVE
142 No process matches the specified process ID.
146 @comment POSIX.1: Interrupted system call
147 @deftypevr Macro int EINTR
148 @comment errno 4 @c DO NOT REMOVE
149 Interrupted function call; an asynchronous signal occurred and prevented
150 completion of the call. When this happens, you should try the call
153 You can choose to have functions resume after a signal that is handled,
154 rather than failing with @code{EINTR}; see @ref{Interrupted
159 @comment POSIX.1: Input/output error
160 @deftypevr Macro int EIO
161 @comment errno 5 @c DO NOT REMOVE
162 Input/output error; usually used for physical read or write errors.
166 @comment POSIX.1: No such device or address
167 @deftypevr Macro int ENXIO
168 @comment errno 6 @c DO NOT REMOVE
169 No such device or address. The system tried to use the device
170 represented by a file you specified, and it couldn't find the device.
171 This can mean that the device file was installed incorrectly, or that
172 the physical device is missing or not correctly attached to the
177 @comment POSIX.1: Argument list too long
178 @deftypevr Macro int E2BIG
179 @comment errno 7 @c DO NOT REMOVE
180 Argument list too long; used when the arguments passed to a new program
181 being executed with one of the @code{exec} functions (@pxref{Executing a
182 File}) occupy too much memory space. This condition never arises on
187 @comment POSIX.1: Exec format error
188 @deftypevr Macro int ENOEXEC
189 @comment errno 8 @c DO NOT REMOVE
190 Invalid executable file format. This condition is detected by the
191 @code{exec} functions; see @ref{Executing a File}.
195 @comment POSIX.1: Bad file descriptor
196 @deftypevr Macro int EBADF
197 @comment errno 9 @c DO NOT REMOVE
198 Bad file descriptor; for example, I/O on a descriptor that has been
199 closed or reading from a descriptor open only for writing (or vice
204 @comment POSIX.1: No child processes
205 @deftypevr Macro int ECHILD
206 @comment errno 10 @c DO NOT REMOVE
207 There are no child processes. This error happens on operations that are
208 supposed to manipulate child processes, when there aren't any processes
213 @comment POSIX.1: Resource deadlock avoided
214 @deftypevr Macro int EDEADLK
215 @comment errno 11 @c DO NOT REMOVE
216 Deadlock avoided; allocating a system resource would have resulted in a
217 deadlock situation. The system does not guarantee that it will notice
218 all such situations. This error means you got lucky and the system
219 noticed; it might just hang. @xref{File Locks}, for an example.
223 @comment POSIX.1: Cannot allocate memory
224 @deftypevr Macro int ENOMEM
225 @comment errno 12 @c DO NOT REMOVE
226 No memory available. The system cannot allocate more virtual memory
227 because its capacity is full.
231 @comment POSIX.1: Permission denied
232 @deftypevr Macro int EACCES
233 @comment errno 13 @c DO NOT REMOVE
234 Permission denied; the file permissions do not allow the attempted operation.
238 @comment POSIX.1: Bad address
239 @deftypevr Macro int EFAULT
240 @comment errno 14 @c DO NOT REMOVE
241 Bad address; an invalid pointer was detected.
242 On @gnuhurdsystems{}, this error never happens; you get a signal instead.
246 @comment BSD: Block device required
247 @deftypevr Macro int ENOTBLK
248 @comment errno 15 @c DO NOT REMOVE
249 A file that isn't a block special file was given in a situation that
250 requires one. For example, trying to mount an ordinary file as a file
251 system in Unix gives this error.
255 @comment POSIX.1: Device or resource busy
256 @deftypevr Macro int EBUSY
257 @comment errno 16 @c DO NOT REMOVE
258 Resource busy; a system resource that can't be shared is already in use.
259 For example, if you try to delete a file that is the root of a currently
260 mounted filesystem, you get this error.
264 @comment POSIX.1: File exists
265 @deftypevr Macro int EEXIST
266 @comment errno 17 @c DO NOT REMOVE
267 File exists; an existing file was specified in a context where it only
268 makes sense to specify a new file.
272 @comment POSIX.1: Invalid cross-device link
273 @deftypevr Macro int EXDEV
274 @comment errno 18 @c DO NOT REMOVE
275 An attempt to make an improper link across file systems was detected.
276 This happens not only when you use @code{link} (@pxref{Hard Links}) but
277 also when you rename a file with @code{rename} (@pxref{Renaming Files}).
281 @comment POSIX.1: No such device
282 @deftypevr Macro int ENODEV
283 @comment errno 19 @c DO NOT REMOVE
284 The wrong type of device was given to a function that expects a
285 particular sort of device.
289 @comment POSIX.1: Not a directory
290 @deftypevr Macro int ENOTDIR
291 @comment errno 20 @c DO NOT REMOVE
292 A file that isn't a directory was specified when a directory is required.
296 @comment POSIX.1: Is a directory
297 @deftypevr Macro int EISDIR
298 @comment errno 21 @c DO NOT REMOVE
299 File is a directory; you cannot open a directory for writing,
300 or create or remove hard links to it.
304 @comment POSIX.1: Invalid argument
305 @deftypevr Macro int EINVAL
306 @comment errno 22 @c DO NOT REMOVE
307 Invalid argument. This is used to indicate various kinds of problems
308 with passing the wrong argument to a library function.
312 @comment POSIX.1: Too many open files
313 @deftypevr Macro int EMFILE
314 @comment errno 24 @c DO NOT REMOVE
315 The current process has too many files open and can't open any more.
316 Duplicate descriptors do count toward this limit.
318 In BSD and GNU, the number of open files is controlled by a resource
319 limit that can usually be increased. If you get this error, you might
320 want to increase the @code{RLIMIT_NOFILE} limit or make it unlimited;
321 @pxref{Limits on Resources}.
325 @comment POSIX.1: Too many open files in system
326 @deftypevr Macro int ENFILE
327 @comment errno 23 @c DO NOT REMOVE
328 There are too many distinct file openings in the entire system. Note
329 that any number of linked channels count as just one file opening; see
330 @ref{Linked Channels}. This error never occurs on @gnuhurdsystems{}.
334 @comment POSIX.1: Inappropriate ioctl for device
335 @deftypevr Macro int ENOTTY
336 @comment errno 25 @c DO NOT REMOVE
337 Inappropriate I/O control operation, such as trying to set terminal
338 modes on an ordinary file.
342 @comment BSD: Text file busy
343 @deftypevr Macro int ETXTBSY
344 @comment errno 26 @c DO NOT REMOVE
345 An attempt to execute a file that is currently open for writing, or
346 write to a file that is currently being executed. Often using a
347 debugger to run a program is considered having it open for writing and
348 will cause this error. (The name stands for ``text file busy''.) This
349 is not an error on @gnuhurdsystems{}; the text is copied as necessary.
353 @comment POSIX.1: File too large
354 @deftypevr Macro int EFBIG
355 @comment errno 27 @c DO NOT REMOVE
356 File too big; the size of a file would be larger than allowed by the system.
360 @comment POSIX.1: No space left on device
361 @deftypevr Macro int ENOSPC
362 @comment errno 28 @c DO NOT REMOVE
363 No space left on device; write operation on a file failed because the
368 @comment POSIX.1: Illegal seek
369 @deftypevr Macro int ESPIPE
370 @comment errno 29 @c DO NOT REMOVE
371 Invalid seek operation (such as on a pipe).
375 @comment POSIX.1: Read-only file system
376 @deftypevr Macro int EROFS
377 @comment errno 30 @c DO NOT REMOVE
378 An attempt was made to modify something on a read-only file system.
382 @comment POSIX.1: Too many links
383 @deftypevr Macro int EMLINK
384 @comment errno 31 @c DO NOT REMOVE
385 Too many links; the link count of a single file would become too large.
386 @code{rename} can cause this error if the file being renamed already has
387 as many links as it can take (@pxref{Renaming Files}).
391 @comment POSIX.1: Broken pipe
392 @deftypevr Macro int EPIPE
393 @comment errno 32 @c DO NOT REMOVE
394 Broken pipe; there is no process reading from the other end of a pipe.
395 Every library function that returns this error code also generates a
396 @code{SIGPIPE} signal; this signal terminates the program if not handled
397 or blocked. Thus, your program will never actually see @code{EPIPE}
398 unless it has handled or blocked @code{SIGPIPE}.
402 @comment ISO: Numerical argument out of domain
403 @deftypevr Macro int EDOM
404 @comment errno 33 @c DO NOT REMOVE
405 Domain error; used by mathematical functions when an argument value does
406 not fall into the domain over which the function is defined.
410 @comment ISO: Numerical result out of range
411 @deftypevr Macro int ERANGE
412 @comment errno 34 @c DO NOT REMOVE
413 Range error; used by mathematical functions when the result value is
414 not representable because of overflow or underflow.
418 @comment POSIX.1: Resource temporarily unavailable
419 @deftypevr Macro int EAGAIN
420 @comment errno 35 @c DO NOT REMOVE
421 Resource temporarily unavailable; the call might work if you try again
422 later. The macro @code{EWOULDBLOCK} is another name for @code{EAGAIN};
423 they are always the same in @theglibc{}.
425 This error can happen in a few different situations:
429 An operation that would block was attempted on an object that has
430 non-blocking mode selected. Trying the same operation again will block
431 until some external condition makes it possible to read, write, or
432 connect (whatever the operation). You can use @code{select} to find out
433 when the operation will be possible; @pxref{Waiting for I/O}.
435 @strong{Portability Note:} In many older Unix systems, this condition
436 was indicated by @code{EWOULDBLOCK}, which was a distinct error code
437 different from @code{EAGAIN}. To make your program portable, you should
438 check for both codes and treat them the same.
441 A temporary resource shortage made an operation impossible. @code{fork}
442 can return this error. It indicates that the shortage is expected to
443 pass, so your program can try the call again later and it may succeed.
444 It is probably a good idea to delay for a few seconds before trying it
445 again, to allow time for other processes to release scarce resources.
446 Such shortages are usually fairly serious and affect the whole system,
447 so usually an interactive program should report the error to the user
448 and return to its command loop.
453 @comment BSD: Operation would block
454 @deftypevr Macro int EWOULDBLOCK
455 @comment errno EAGAIN @c DO NOT REMOVE
456 In @theglibc{}, this is another name for @code{EAGAIN} (above).
457 The values are always the same, on every operating system.
459 C libraries in many older Unix systems have @code{EWOULDBLOCK} as a
464 @comment BSD: Operation now in progress
465 @deftypevr Macro int EINPROGRESS
466 @comment errno 36 @c DO NOT REMOVE
467 An operation that cannot complete immediately was initiated on an object
468 that has non-blocking mode selected. Some functions that must always
469 block (such as @code{connect}; @pxref{Connecting}) never return
470 @code{EAGAIN}. Instead, they return @code{EINPROGRESS} to indicate that
471 the operation has begun and will take some time. Attempts to manipulate
472 the object before the call completes return @code{EALREADY}. You can
473 use the @code{select} function to find out when the pending operation
474 has completed; @pxref{Waiting for I/O}.
478 @comment BSD: Operation already in progress
479 @deftypevr Macro int EALREADY
480 @comment errno 37 @c DO NOT REMOVE
481 An operation is already in progress on an object that has non-blocking
486 @comment BSD: Socket operation on non-socket
487 @deftypevr Macro int ENOTSOCK
488 @comment errno 38 @c DO NOT REMOVE
489 A file that isn't a socket was specified when a socket is required.
493 @comment BSD: Message too long
494 @deftypevr Macro int EMSGSIZE
495 @comment errno 40 @c DO NOT REMOVE
496 The size of a message sent on a socket was larger than the supported
501 @comment BSD: Protocol wrong type for socket
502 @deftypevr Macro int EPROTOTYPE
503 @comment errno 41 @c DO NOT REMOVE
504 The socket type does not support the requested communications protocol.
508 @comment BSD: Protocol not available
509 @deftypevr Macro int ENOPROTOOPT
510 @comment errno 42 @c DO NOT REMOVE
511 You specified a socket option that doesn't make sense for the
512 particular protocol being used by the socket. @xref{Socket Options}.
516 @comment BSD: Protocol not supported
517 @deftypevr Macro int EPROTONOSUPPORT
518 @comment errno 43 @c DO NOT REMOVE
519 The socket domain does not support the requested communications protocol
520 (perhaps because the requested protocol is completely invalid).
521 @xref{Creating a Socket}.
525 @comment BSD: Socket type not supported
526 @deftypevr Macro int ESOCKTNOSUPPORT
527 @comment errno 44 @c DO NOT REMOVE
528 The socket type is not supported.
532 @comment BSD: Operation not supported
533 @deftypevr Macro int EOPNOTSUPP
534 @comment errno 45 @c DO NOT REMOVE
535 The operation you requested is not supported. Some socket functions
536 don't make sense for all types of sockets, and others may not be
537 implemented for all communications protocols. On @gnuhurdsystems{}, this
538 error can happen for many calls when the object does not support the
539 particular operation; it is a generic indication that the server knows
540 nothing to do for that call.
544 @comment BSD: Protocol family not supported
545 @deftypevr Macro int EPFNOSUPPORT
546 @comment errno 46 @c DO NOT REMOVE
547 The socket communications protocol family you requested is not supported.
551 @comment BSD: Address family not supported by protocol
552 @deftypevr Macro int EAFNOSUPPORT
553 @comment errno 47 @c DO NOT REMOVE
554 The address family specified for a socket is not supported; it is
555 inconsistent with the protocol being used on the socket. @xref{Sockets}.
559 @comment BSD: Address already in use
560 @deftypevr Macro int EADDRINUSE
561 @comment errno 48 @c DO NOT REMOVE
562 The requested socket address is already in use. @xref{Socket Addresses}.
566 @comment BSD: Cannot assign requested address
567 @deftypevr Macro int EADDRNOTAVAIL
568 @comment errno 49 @c DO NOT REMOVE
569 The requested socket address is not available; for example, you tried
570 to give a socket a name that doesn't match the local host name.
571 @xref{Socket Addresses}.
575 @comment BSD: Network is down
576 @deftypevr Macro int ENETDOWN
577 @comment errno 50 @c DO NOT REMOVE
578 A socket operation failed because the network was down.
582 @comment BSD: Network is unreachable
583 @deftypevr Macro int ENETUNREACH
584 @comment errno 51 @c DO NOT REMOVE
585 A socket operation failed because the subnet containing the remote host
590 @comment BSD: Network dropped connection on reset
591 @deftypevr Macro int ENETRESET
592 @comment errno 52 @c DO NOT REMOVE
593 A network connection was reset because the remote host crashed.
597 @comment BSD: Software caused connection abort
598 @deftypevr Macro int ECONNABORTED
599 @comment errno 53 @c DO NOT REMOVE
600 A network connection was aborted locally.
604 @comment BSD: Connection reset by peer
605 @deftypevr Macro int ECONNRESET
606 @comment errno 54 @c DO NOT REMOVE
607 A network connection was closed for reasons outside the control of the
608 local host, such as by the remote machine rebooting or an unrecoverable
613 @comment BSD: No buffer space available
614 @deftypevr Macro int ENOBUFS
615 @comment errno 55 @c DO NOT REMOVE
616 The kernel's buffers for I/O operations are all in use. In GNU, this
617 error is always synonymous with @code{ENOMEM}; you may get one or the
618 other from network operations.
622 @comment BSD: Transport endpoint is already connected
623 @deftypevr Macro int EISCONN
624 @comment errno 56 @c DO NOT REMOVE
625 You tried to connect a socket that is already connected.
630 @comment BSD: Transport endpoint is not connected
631 @deftypevr Macro int ENOTCONN
632 @comment errno 57 @c DO NOT REMOVE
633 The socket is not connected to anything. You get this error when you
634 try to transmit data over a socket, without first specifying a
635 destination for the data. For a connectionless socket (for datagram
636 protocols, such as UDP), you get @code{EDESTADDRREQ} instead.
640 @comment BSD: Destination address required
641 @deftypevr Macro int EDESTADDRREQ
642 @comment errno 39 @c DO NOT REMOVE
643 No default destination address was set for the socket. You get this
644 error when you try to transmit data over a connectionless socket,
645 without first specifying a destination for the data with @code{connect}.
649 @comment BSD: Cannot send after transport endpoint shutdown
650 @deftypevr Macro int ESHUTDOWN
651 @comment errno 58 @c DO NOT REMOVE
652 The socket has already been shut down.
656 @comment BSD: Too many references: cannot splice
657 @deftypevr Macro int ETOOMANYREFS
658 @comment errno 59 @c DO NOT REMOVE
663 @comment BSD: Connection timed out
664 @deftypevr Macro int ETIMEDOUT
665 @comment errno 60 @c DO NOT REMOVE
666 A socket operation with a specified timeout received no response during
671 @comment BSD: Connection refused
672 @deftypevr Macro int ECONNREFUSED
673 @comment errno 61 @c DO NOT REMOVE
674 A remote host refused to allow the network connection (typically because
675 it is not running the requested service).
679 @comment BSD: Too many levels of symbolic links
680 @deftypevr Macro int ELOOP
681 @comment errno 62 @c DO NOT REMOVE
682 Too many levels of symbolic links were encountered in looking up a file name.
683 This often indicates a cycle of symbolic links.
687 @comment POSIX.1: File name too long
688 @deftypevr Macro int ENAMETOOLONG
689 @comment errno 63 @c DO NOT REMOVE
690 Filename too long (longer than @code{PATH_MAX}; @pxref{Limits for
691 Files}) or host name too long (in @code{gethostname} or
692 @code{sethostname}; @pxref{Host Identification}).
696 @comment BSD: Host is down
697 @deftypevr Macro int EHOSTDOWN
698 @comment errno 64 @c DO NOT REMOVE
699 The remote host for a requested network connection is down.
703 @comment BSD: No route to host
704 @deftypevr Macro int EHOSTUNREACH
705 @comment errno 65 @c DO NOT REMOVE
706 The remote host for a requested network connection is not reachable.
710 @comment POSIX.1: Directory not empty
711 @deftypevr Macro int ENOTEMPTY
712 @comment errno 66 @c DO NOT REMOVE
713 Directory not empty, where an empty directory was expected. Typically,
714 this error occurs when you are trying to delete a directory.
718 @comment BSD: Too many processes
719 @deftypevr Macro int EPROCLIM
720 @comment errno 67 @c DO NOT REMOVE
721 This means that the per-user limit on new process would be exceeded by
722 an attempted @code{fork}. @xref{Limits on Resources}, for details on
723 the @code{RLIMIT_NPROC} limit.
727 @comment BSD: Too many users
728 @deftypevr Macro int EUSERS
729 @comment errno 68 @c DO NOT REMOVE
730 The file quota system is confused because there are too many users.
731 @c This can probably happen in a GNU system when using NFS.
735 @comment BSD: Disk quota exceeded
736 @deftypevr Macro int EDQUOT
737 @comment errno 69 @c DO NOT REMOVE
738 The user's disk quota was exceeded.
742 @comment BSD: Stale NFS file handle
743 @deftypevr Macro int ESTALE
744 @comment errno 70 @c DO NOT REMOVE
745 Stale NFS file handle. This indicates an internal confusion in the NFS
746 system which is due to file system rearrangements on the server host.
747 Repairing this condition usually requires unmounting and remounting
748 the NFS file system on the local host.
752 @comment BSD: Object is remote
753 @deftypevr Macro int EREMOTE
754 @comment errno 71 @c DO NOT REMOVE
755 An attempt was made to NFS-mount a remote file system with a file name that
756 already specifies an NFS-mounted file.
757 (This is an error on some operating systems, but we expect it to work
758 properly on @gnuhurdsystems{}, making this error code impossible.)
762 @comment BSD: RPC struct is bad
763 @deftypevr Macro int EBADRPC
764 @comment errno 72 @c DO NOT REMOVE
769 @comment BSD: RPC version wrong
770 @deftypevr Macro int ERPCMISMATCH
771 @comment errno 73 @c DO NOT REMOVE
776 @comment BSD: RPC program not available
777 @deftypevr Macro int EPROGUNAVAIL
778 @comment errno 74 @c DO NOT REMOVE
783 @comment BSD: RPC program version wrong
784 @deftypevr Macro int EPROGMISMATCH
785 @comment errno 75 @c DO NOT REMOVE
790 @comment BSD: RPC bad procedure for program
791 @deftypevr Macro int EPROCUNAVAIL
792 @comment errno 76 @c DO NOT REMOVE
797 @comment POSIX.1: No locks available
798 @deftypevr Macro int ENOLCK
799 @comment errno 77 @c DO NOT REMOVE
800 No locks available. This is used by the file locking facilities; see
801 @ref{File Locks}. This error is never generated by @gnuhurdsystems{}, but
802 it can result from an operation to an NFS server running another
807 @comment BSD: Inappropriate file type or format
808 @deftypevr Macro int EFTYPE
809 @comment errno 79 @c DO NOT REMOVE
810 Inappropriate file type or format. The file was the wrong type for the
811 operation, or a data file had the wrong format.
813 On some systems @code{chmod} returns this error if you try to set the
814 sticky bit on a non-directory file; @pxref{Setting Permissions}.
818 @comment BSD: Authentication error
819 @deftypevr Macro int EAUTH
820 @comment errno 80 @c DO NOT REMOVE
825 @comment BSD: Need authenticator
826 @deftypevr Macro int ENEEDAUTH
827 @comment errno 81 @c DO NOT REMOVE
832 @comment POSIX.1: Function not implemented
833 @deftypevr Macro int ENOSYS
834 @comment errno 78 @c DO NOT REMOVE
835 Function not implemented. This indicates that the function called is
836 not implemented at all, either in the C library itself or in the
837 operating system. When you get this error, you can be sure that this
838 particular function will always fail with @code{ENOSYS} unless you
839 install a new version of the C library or the operating system.
843 @comment POSIX.1: Not supported
844 @deftypevr Macro int ENOTSUP
845 @comment errno 118 @c DO NOT REMOVE
846 Not supported. A function returns this error when certain parameter
847 values are valid, but the functionality they request is not available.
848 This can mean that the function does not implement a particular command
849 or option value or flag bit at all. For functions that operate on some
850 object given in a parameter, such as a file descriptor or a port, it
851 might instead mean that only @emph{that specific object} (file
852 descriptor, port, etc.) is unable to support the other parameters given;
853 different file descriptors might support different ranges of parameter
856 If the entire function is not available at all in the implementation,
857 it returns @code{ENOSYS} instead.
861 @comment ISO: Invalid or incomplete multibyte or wide character
862 @deftypevr Macro int EILSEQ
863 @comment errno 106 @c DO NOT REMOVE
864 While decoding a multibyte character the function came along an invalid
865 or an incomplete sequence of bytes or the given wide character is invalid.
869 @comment GNU: Inappropriate operation for background process
870 @deftypevr Macro int EBACKGROUND
871 @comment errno 100 @c DO NOT REMOVE
872 On @gnuhurdsystems{}, servers supporting the @code{term} protocol return
873 this error for certain operations when the caller is not in the
874 foreground process group of the terminal. Users do not usually see this
875 error because functions such as @code{read} and @code{write} translate
876 it into a @code{SIGTTIN} or @code{SIGTTOU} signal. @xref{Job Control},
877 for information on process groups and these signals.
881 @comment GNU: Translator died
882 @deftypevr Macro int EDIED
883 @comment errno 101 @c DO NOT REMOVE
884 On @gnuhurdsystems{}, opening a file returns this error when the file is
885 translated by a program and the translator program dies while starting
886 up, before it has connected to the file.
891 @deftypevr Macro int ED
892 @comment errno 102 @c DO NOT REMOVE
893 The experienced user will know what is wrong.
894 @c This error code is a joke. Its perror text is part of the joke.
899 @comment GNU: You really blew it this time
900 @deftypevr Macro int EGREGIOUS
901 @comment errno 103 @c DO NOT REMOVE
902 You did @strong{what}?
906 @comment GNU: Computer bought the farm
907 @deftypevr Macro int EIEIO
908 @comment errno 104 @c DO NOT REMOVE
909 Go home and have a glass of warm, dairy-fresh milk.
913 @comment GNU: Gratuitous error
914 @deftypevr Macro int EGRATUITOUS
915 @comment errno 105 @c DO NOT REMOVE
916 This error code has no purpose.
920 @comment XOPEN: Bad message
921 @deftypevr Macro int EBADMSG
926 @comment XOPEN: Identifier removed
927 @deftypevr Macro int EIDRM
932 @comment XOPEN: Multihop attempted
933 @deftypevr Macro int EMULTIHOP
938 @comment XOPEN: No data available
939 @deftypevr Macro int ENODATA
944 @comment XOPEN: Link has been severed
945 @deftypevr Macro int ENOLINK
950 @comment XOPEN: No message of desired type
951 @deftypevr Macro int ENOMSG
956 @comment XOPEN: Out of streams resources
957 @deftypevr Macro int ENOSR
962 @comment XOPEN: Device not a stream
963 @deftypevr Macro int ENOSTR
968 @comment XOPEN: Value too large for defined data type
969 @deftypevr Macro int EOVERFLOW
974 @comment XOPEN: Protocol error
975 @deftypevr Macro int EPROTO
980 @comment XOPEN: Timer expired
981 @deftypevr Macro int ETIME
986 @comment POSIX.1: Operation canceled
987 @deftypevr Macro int ECANCELED
989 Operation canceled; an asynchronous operation was canceled before it
990 completed. @xref{Asynchronous I/O}. When you call @code{aio_cancel},
991 the normal result is for the operations affected to complete with this
992 error; @pxref{Cancel AIO Operations}.
996 @emph{The following error codes are defined by the Linux/i386 kernel.
997 They are not yet documented.}
1000 @comment Linux???: Interrupted system call should be restarted
1001 @deftypevr Macro int ERESTART
1002 @comment errno ???/85
1006 @comment Linux???: Channel number out of range
1007 @deftypevr Macro int ECHRNG
1008 @comment errno ???/44
1012 @comment Obsolete: Level 2 not synchronized
1013 @deftypevr Macro int EL2NSYNC
1014 @comment errno ???/45
1018 @comment Obsolete: Level 3 halted
1019 @deftypevr Macro int EL3HLT
1020 @comment errno ???/46
1024 @comment Obsolete: Level 3 reset
1025 @deftypevr Macro int EL3RST
1026 @comment errno ???/47
1030 @comment Linux???: Link number out of range
1031 @deftypevr Macro int ELNRNG
1032 @comment errno ???/48
1036 @comment Linux???: Protocol driver not attached
1037 @deftypevr Macro int EUNATCH
1038 @comment errno ???/49
1042 @comment Linux???: No CSI structure available
1043 @deftypevr Macro int ENOCSI
1044 @comment errno ???/50
1048 @comment Obsolete: Level 2 halted
1049 @deftypevr Macro int EL2HLT
1050 @comment errno ???/51
1054 @comment Linux???: Invalid exchange
1055 @deftypevr Macro int EBADE
1056 @comment errno ???/52
1060 @comment Linux???: Invalid request descriptor
1061 @deftypevr Macro int EBADR
1062 @comment errno ???/53
1066 @comment Linux???: Exchange full
1067 @deftypevr Macro int EXFULL
1068 @comment errno ???/54
1072 @comment Linux???: No anode
1073 @deftypevr Macro int ENOANO
1074 @comment errno ???/55
1078 @comment Linux???: Invalid request code
1079 @deftypevr Macro int EBADRQC
1080 @comment errno ???/56
1084 @comment Linux???: Invalid slot
1085 @deftypevr Macro int EBADSLT
1086 @comment errno ???/57
1090 @comment Linux???: File locking deadlock error
1091 @deftypevr Macro int EDEADLOCK
1092 @comment errno ???/58
1096 @comment Linux???: Bad font file format
1097 @deftypevr Macro int EBFONT
1098 @comment errno ???/59
1102 @comment Linux???: Machine is not on the network
1103 @deftypevr Macro int ENONET
1104 @comment errno ???/64
1108 @comment Linux???: Package not installed
1109 @deftypevr Macro int ENOPKG
1110 @comment errno ???/65
1114 @comment Linux???: Advertise error
1115 @deftypevr Macro int EADV
1116 @comment errno ???/68
1120 @comment Linux???: Srmount error
1121 @deftypevr Macro int ESRMNT
1122 @comment errno ???/69
1126 @comment Linux???: Communication error on send
1127 @deftypevr Macro int ECOMM
1128 @comment errno ???/70
1132 @comment Linux???: RFS specific error
1133 @deftypevr Macro int EDOTDOT
1134 @comment errno ???/73
1138 @comment Linux???: Name not unique on network
1139 @deftypevr Macro int ENOTUNIQ
1140 @comment errno ???/76
1144 @comment Linux???: File descriptor in bad state
1145 @deftypevr Macro int EBADFD
1146 @comment errno ???/77
1150 @comment Linux???: Remote address changed
1151 @deftypevr Macro int EREMCHG
1152 @comment errno ???/78
1156 @comment Linux???: Can not access a needed shared library
1157 @deftypevr Macro int ELIBACC
1158 @comment errno ???/79
1162 @comment Linux???: Accessing a corrupted shared library
1163 @deftypevr Macro int ELIBBAD
1164 @comment errno ???/80
1168 @comment Linux???: .lib section in a.out corrupted
1169 @deftypevr Macro int ELIBSCN
1170 @comment errno ???/81
1174 @comment Linux???: Attempting to link in too many shared libraries
1175 @deftypevr Macro int ELIBMAX
1176 @comment errno ???/82
1180 @comment Linux???: Cannot exec a shared library directly
1181 @deftypevr Macro int ELIBEXEC
1182 @comment errno ???/83
1186 @comment Linux???: Streams pipe error
1187 @deftypevr Macro int ESTRPIPE
1188 @comment errno ???/86
1192 @comment Linux???: Structure needs cleaning
1193 @deftypevr Macro int EUCLEAN
1194 @comment errno ???/117
1198 @comment Linux???: Not a XENIX named type file
1199 @deftypevr Macro int ENOTNAM
1200 @comment errno ???/118
1204 @comment Linux???: No XENIX semaphores available
1205 @deftypevr Macro int ENAVAIL
1206 @comment errno ???/119
1210 @comment Linux???: Is a named type file
1211 @deftypevr Macro int EISNAM
1212 @comment errno ???/120
1216 @comment Linux???: Remote I/O error
1217 @deftypevr Macro int EREMOTEIO
1218 @comment errno ???/121
1222 @comment Linux???: No medium found
1223 @deftypevr Macro int ENOMEDIUM
1224 @comment errno ???/???
1228 @comment Linux???: Wrong medium type
1229 @deftypevr Macro int EMEDIUMTYPE
1230 @comment errno ???/???
1234 @comment Linux: Required key not available
1235 @deftypevr Macro int ENOKEY
1236 @comment errno ???/???
1240 @comment Linux: Key has expired
1241 @deftypevr Macro int EKEYEXPIRED
1242 @comment errno ???/???
1246 @comment Linux: Key has been revoked
1247 @deftypevr Macro int EKEYREVOKED
1248 @comment errno ???/???
1252 @comment Linux: Key was rejected by service
1253 @deftypevr Macro int EKEYREJECTED
1254 @comment errno ???/???
1258 @comment Linux: Owner died
1259 @deftypevr Macro int EOWNERDEAD
1260 @comment errno ???/???
1264 @comment Linux: State not recoverable
1265 @deftypevr Macro int ENOTRECOVERABLE
1266 @comment errno ???/???
1270 @comment Linux: Operation not possible due to RF-kill
1271 @deftypevr Macro int ERFKILL
1272 @comment errno ???/???
1276 @comment Linux: Memory page has hardware error
1277 @deftypevr Macro int EHWPOISON
1278 @comment errno ???/???
1281 @node Error Messages, , Error Codes, Error Reporting
1282 @section Error Messages
1284 The library has functions and variables designed to make it easy for
1285 your program to report informative error messages in the customary
1286 format about the failure of a library call. The functions
1287 @code{strerror} and @code{perror} give you the standard error message
1288 for a given error code; the variable
1289 @w{@code{program_invocation_short_name}} gives you convenient access to the
1290 name of the program that encountered the error.
1294 @deftypefun {char *} strerror (int @var{errnum})
1295 The @code{strerror} function maps the error code (@pxref{Checking for
1296 Errors}) specified by the @var{errnum} argument to a descriptive error
1297 message string. The return value is a pointer to this string.
1299 The value @var{errnum} normally comes from the variable @code{errno}.
1301 You should not modify the string returned by @code{strerror}. Also, if
1302 you make subsequent calls to @code{strerror}, the string might be
1303 overwritten. (But it's guaranteed that no library function ever calls
1304 @code{strerror} behind your back.)
1306 The function @code{strerror} is declared in @file{string.h}.
1311 @deftypefun {char *} strerror_r (int @var{errnum}, char *@var{buf}, size_t @var{n})
1312 The @code{strerror_r} function works like @code{strerror} but instead of
1313 returning the error message in a statically allocated buffer shared by
1314 all threads in the process, it returns a private copy for the
1315 thread. This might be either some permanent global data or a message
1316 string in the user supplied buffer starting at @var{buf} with the
1317 length of @var{n} bytes.
1319 At most @var{n} characters are written (including the NUL byte) so it is
1320 up to the user to select the buffer large enough.
1322 This function should always be used in multi-threaded programs since
1323 there is no way to guarantee the string returned by @code{strerror}
1324 really belongs to the last call of the current thread.
1326 This function @code{strerror_r} is a GNU extension and it is declared in
1332 @deftypefun void perror (const char *@var{message})
1333 This function prints an error message to the stream @code{stderr};
1334 see @ref{Standard Streams}. The orientation of @code{stderr} is not
1337 If you call @code{perror} with a @var{message} that is either a null
1338 pointer or an empty string, @code{perror} just prints the error message
1339 corresponding to @code{errno}, adding a trailing newline.
1341 If you supply a non-null @var{message} argument, then @code{perror}
1342 prefixes its output with this string. It adds a colon and a space
1343 character to separate the @var{message} from the error string corresponding
1346 The function @code{perror} is declared in @file{stdio.h}.
1349 @code{strerror} and @code{perror} produce the exact same message for any
1350 given error code; the precise text varies from system to system. With
1351 @theglibc{}, the messages are fairly short; there are no multi-line
1352 messages or embedded newlines. Each error message begins with a capital
1353 letter and does not include any terminating punctuation.
1355 @strong{Compatibility Note:} The @code{strerror} function was introduced
1356 in @w{ISO C89}. Many older C systems do not support this function yet.
1358 @cindex program name
1359 @cindex name of running program
1360 Many programs that don't read input from the terminal are designed to
1361 exit if any system call fails. By convention, the error message from
1362 such a program should start with the program's name, sans directories.
1363 You can find that name in the variable
1364 @code{program_invocation_short_name}; the full file name is stored the
1365 variable @code{program_invocation_name}.
1369 @deftypevar {char *} program_invocation_name
1370 This variable's value is the name that was used to invoke the program
1371 running in the current process. It is the same as @code{argv[0]}. Note
1372 that this is not necessarily a useful file name; often it contains no
1373 directory names. @xref{Program Arguments}.
1378 @deftypevar {char *} program_invocation_short_name
1379 This variable's value is the name that was used to invoke the program
1380 running in the current process, with directory names removed. (That is
1381 to say, it is the same as @code{program_invocation_name} minus
1382 everything up to the last slash, if any.)
1385 The library initialization code sets up both of these variables before
1386 calling @code{main}.
1388 @strong{Portability Note:} These two variables are GNU extensions. If
1389 you want your program to work with non-GNU libraries, you must save the
1390 value of @code{argv[0]} in @code{main}, and then strip off the directory
1391 names yourself. We added these extensions to make it possible to write
1392 self-contained error-reporting subroutines that require no explicit
1393 cooperation from @code{main}.
1395 Here is an example showing how to handle failure to open a file
1396 correctly. The function @code{open_sesame} tries to open the named file
1397 for reading and returns a stream if successful. The @code{fopen}
1398 library function returns a null pointer if it couldn't open the file for
1399 some reason. In that situation, @code{open_sesame} constructs an
1400 appropriate error message using the @code{strerror} function, and
1401 terminates the program. If we were going to make some other library
1402 calls before passing the error code to @code{strerror}, we'd have to
1403 save it in a local variable instead, because those other library
1404 functions might overwrite @code{errno} in the meantime.
1413 open_sesame (char *name)
1418 stream = fopen (name, "r");
1421 fprintf (stderr, "%s: Couldn't open file %s; %s\n",
1422 program_invocation_short_name, name, strerror (errno));
1423 exit (EXIT_FAILURE);
1430 Using @code{perror} has the advantage that the function is portable and
1431 available on all systems implementing @w{ISO C}. But often the text
1432 @code{perror} generates is not what is wanted and there is no way to
1433 extend or change what @code{perror} does. The GNU coding standard, for
1434 instance, requires error messages to be preceded by the program name and
1435 programs which read some input files should provide information
1436 about the input file name and the line number in case an error is
1437 encountered while reading the file. For these occasions there are two
1438 functions available which are widely used throughout the GNU project.
1439 These functions are declared in @file{error.h}.
1443 @deftypefun void error (int @var{status}, int @var{errnum}, const char *@var{format}, @dots{})
1444 The @code{error} function can be used to report general problems during
1445 program execution. The @var{format} argument is a format string just
1446 like those given to the @code{printf} family of functions. The
1447 arguments required for the format can follow the @var{format} parameter.
1448 Just like @code{perror}, @code{error} also can report an error code in
1449 textual form. But unlike @code{perror} the error value is explicitly
1450 passed to the function in the @var{errnum} parameter. This eliminates
1451 the problem mentioned above that the error reporting function must be
1452 called immediately after the function causing the error since otherwise
1453 @code{errno} might have a different value.
1455 The @code{error} prints first the program name. If the application
1456 defined a global variable @code{error_print_progname} and points it to a
1457 function this function will be called to print the program name.
1458 Otherwise the string from the global variable @code{program_name} is
1459 used. The program name is followed by a colon and a space which in turn
1460 is followed by the output produced by the format string. If the
1461 @var{errnum} parameter is non-zero the format string output is followed
1462 by a colon and a space, followed by the error message for the error code
1463 @var{errnum}. In any case is the output terminated with a newline.
1465 The output is directed to the @code{stderr} stream. If the
1466 @code{stderr} wasn't oriented before the call it will be narrow-oriented
1469 The function will return unless the @var{status} parameter has a
1470 non-zero value. In this case the function will call @code{exit} with
1471 the @var{status} value for its parameter and therefore never return. If
1472 @code{error} returns the global variable @code{error_message_count} is
1473 incremented by one to keep track of the number of errors reported.
1478 @deftypefun void error_at_line (int @var{status}, int @var{errnum}, const char *@var{fname}, unsigned int @var{lineno}, const char *@var{format}, @dots{})
1480 The @code{error_at_line} function is very similar to the @code{error}
1481 function. The only difference are the additional parameters @var{fname}
1482 and @var{lineno}. The handling of the other parameters is identical to
1483 that of @code{error} except that between the program name and the string
1484 generated by the format string additional text is inserted.
1486 Directly following the program name a colon, followed by the file name
1487 pointer to by @var{fname}, another colon, and a value of @var{lineno} is
1490 This additional output of course is meant to be used to locate an error
1491 in an input file (like a programming language source code file etc).
1493 If the global variable @code{error_one_per_line} is set to a non-zero
1494 value @code{error_at_line} will avoid printing consecutive messages for
1495 the same file and line. Repetition which are not directly following
1496 each other are not caught.
1498 Just like @code{error} this function only returned if @var{status} is
1499 zero. Otherwise @code{exit} is called with the non-zero value. If
1500 @code{error} returns the global variable @code{error_message_count} is
1501 incremented by one to keep track of the number of errors reported.
1504 As mentioned above the @code{error} and @code{error_at_line} functions
1505 can be customized by defining a variable named
1506 @code{error_print_progname}.
1510 @deftypevar {void (*) error_print_progname } (void)
1511 If the @code{error_print_progname} variable is defined to a non-zero
1512 value the function pointed to is called by @code{error} or
1513 @code{error_at_line}. It is expected to print the program name or do
1514 something similarly useful.
1516 The function is expected to be print to the @code{stderr} stream and
1517 must be able to handle whatever orientation the stream has.
1519 The variable is global and shared by all threads.
1524 @deftypevar {unsigned int} error_message_count
1525 The @code{error_message_count} variable is incremented whenever one of
1526 the functions @code{error} or @code{error_at_line} returns. The
1527 variable is global and shared by all threads.
1532 @deftypevar int error_one_per_line
1533 The @code{error_one_per_line} variable influences only
1534 @code{error_at_line}. Normally the @code{error_at_line} function
1535 creates output for every invocation. If @code{error_one_per_line} is
1536 set to a non-zero value @code{error_at_line} keeps track of the last
1537 file name and line number for which an error was reported and avoid
1538 directly following messages for the same file and line. This variable
1539 is global and shared by all threads.
1543 A program which read some input file and reports errors in it could look
1550 unsigned int lineno = 0;
1552 error_message_count = 0;
1553 while (! feof_unlocked (fp))
1555 ssize_t n = getline (&line, &len, fp);
1557 /* @r{End of file or error.} */
1561 /* @r{Process the line.} */
1564 if (@r{Detect error in line})
1565 error_at_line (0, errval, filename, lineno,
1566 "some error text %s", some_variable);
1569 if (error_message_count != 0)
1570 error (EXIT_FAILURE, 0, "%u errors found", error_message_count);
1574 @code{error} and @code{error_at_line} are clearly the functions of
1575 choice and enable the programmer to write applications which follow the
1576 GNU coding standard. @Theglibc{} additionally contains functions which
1577 are used in BSD for the same purpose. These functions are declared in
1578 @file{err.h}. It is generally advised to not use these functions. They
1579 are included only for compatibility.
1583 @deftypefun void warn (const char *@var{format}, @dots{})
1584 The @code{warn} function is roughly equivalent to a call like
1586 error (0, errno, format, @r{the parameters})
1589 except that the global variables @code{error} respects and modifies
1595 @deftypefun void vwarn (const char *@var{format}, va_list @var{ap})
1596 The @code{vwarn} function is just like @code{warn} except that the
1597 parameters for the handling of the format string @var{format} are passed
1598 in as an value of type @code{va_list}.
1603 @deftypefun void warnx (const char *@var{format}, @dots{})
1604 The @code{warnx} function is roughly equivalent to a call like
1606 error (0, 0, format, @r{the parameters})
1609 except that the global variables @code{error} respects and modifies
1610 are not used. The difference to @code{warn} is that no error number
1616 @deftypefun void vwarnx (const char *@var{format}, va_list @var{ap})
1617 The @code{vwarnx} function is just like @code{warnx} except that the
1618 parameters for the handling of the format string @var{format} are passed
1619 in as an value of type @code{va_list}.
1624 @deftypefun void err (int @var{status}, const char *@var{format}, @dots{})
1625 The @code{err} function is roughly equivalent to a call like
1627 error (status, errno, format, @r{the parameters})
1630 except that the global variables @code{error} respects and modifies
1631 are not used and that the program is exited even if @var{status} is zero.
1636 @deftypefun void verr (int @var{status}, const char *@var{format}, va_list @var{ap})
1637 The @code{verr} function is just like @code{err} except that the
1638 parameters for the handling of the format string @var{format} are passed
1639 in as an value of type @code{va_list}.
1644 @deftypefun void errx (int @var{status}, const char *@var{format}, @dots{})
1645 The @code{errx} function is roughly equivalent to a call like
1647 error (status, 0, format, @r{the parameters})
1650 except that the global variables @code{error} respects and modifies
1651 are not used and that the program is exited even if @var{status}
1652 is zero. The difference to @code{err} is that no error number
1658 @deftypefun void verrx (int @var{status}, const char *@var{format}, va_list @var{ap})
1659 The @code{verrx} function is just like @code{errx} except that the
1660 parameters for the handling of the format string @var{format} are passed
1661 in as an value of type @code{va_list}.