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 file handle
743 @deftypevr Macro int ESTALE
744 @comment errno 70 @c DO NOT REMOVE
745 Stale file handle. This indicates an internal confusion in the
746 file system which is due to file system rearrangements on the server host
747 for NFS file systems or corruption in other file systems.
748 Repairing this condition usually requires unmounting, possibly repairing
749 and remounting the file system.
753 @comment BSD: Object is remote
754 @deftypevr Macro int EREMOTE
755 @comment errno 71 @c DO NOT REMOVE
756 An attempt was made to NFS-mount a remote file system with a file name that
757 already specifies an NFS-mounted file.
758 (This is an error on some operating systems, but we expect it to work
759 properly on @gnuhurdsystems{}, making this error code impossible.)
763 @comment BSD: RPC struct is bad
764 @deftypevr Macro int EBADRPC
765 @comment errno 72 @c DO NOT REMOVE
770 @comment BSD: RPC version wrong
771 @deftypevr Macro int ERPCMISMATCH
772 @comment errno 73 @c DO NOT REMOVE
777 @comment BSD: RPC program not available
778 @deftypevr Macro int EPROGUNAVAIL
779 @comment errno 74 @c DO NOT REMOVE
784 @comment BSD: RPC program version wrong
785 @deftypevr Macro int EPROGMISMATCH
786 @comment errno 75 @c DO NOT REMOVE
791 @comment BSD: RPC bad procedure for program
792 @deftypevr Macro int EPROCUNAVAIL
793 @comment errno 76 @c DO NOT REMOVE
798 @comment POSIX.1: No locks available
799 @deftypevr Macro int ENOLCK
800 @comment errno 77 @c DO NOT REMOVE
801 No locks available. This is used by the file locking facilities; see
802 @ref{File Locks}. This error is never generated by @gnuhurdsystems{}, but
803 it can result from an operation to an NFS server running another
808 @comment BSD: Inappropriate file type or format
809 @deftypevr Macro int EFTYPE
810 @comment errno 79 @c DO NOT REMOVE
811 Inappropriate file type or format. The file was the wrong type for the
812 operation, or a data file had the wrong format.
814 On some systems @code{chmod} returns this error if you try to set the
815 sticky bit on a non-directory file; @pxref{Setting Permissions}.
819 @comment BSD: Authentication error
820 @deftypevr Macro int EAUTH
821 @comment errno 80 @c DO NOT REMOVE
826 @comment BSD: Need authenticator
827 @deftypevr Macro int ENEEDAUTH
828 @comment errno 81 @c DO NOT REMOVE
833 @comment POSIX.1: Function not implemented
834 @deftypevr Macro int ENOSYS
835 @comment errno 78 @c DO NOT REMOVE
836 Function not implemented. This indicates that the function called is
837 not implemented at all, either in the C library itself or in the
838 operating system. When you get this error, you can be sure that this
839 particular function will always fail with @code{ENOSYS} unless you
840 install a new version of the C library or the operating system.
844 @comment POSIX.1: Not supported
845 @deftypevr Macro int ENOTSUP
846 @comment errno 118 @c DO NOT REMOVE
847 Not supported. A function returns this error when certain parameter
848 values are valid, but the functionality they request is not available.
849 This can mean that the function does not implement a particular command
850 or option value or flag bit at all. For functions that operate on some
851 object given in a parameter, such as a file descriptor or a port, it
852 might instead mean that only @emph{that specific object} (file
853 descriptor, port, etc.) is unable to support the other parameters given;
854 different file descriptors might support different ranges of parameter
857 If the entire function is not available at all in the implementation,
858 it returns @code{ENOSYS} instead.
862 @comment ISO: Invalid or incomplete multibyte or wide character
863 @deftypevr Macro int EILSEQ
864 @comment errno 106 @c DO NOT REMOVE
865 While decoding a multibyte character the function came along an invalid
866 or an incomplete sequence of bytes or the given wide character is invalid.
870 @comment GNU: Inappropriate operation for background process
871 @deftypevr Macro int EBACKGROUND
872 @comment errno 100 @c DO NOT REMOVE
873 On @gnuhurdsystems{}, servers supporting the @code{term} protocol return
874 this error for certain operations when the caller is not in the
875 foreground process group of the terminal. Users do not usually see this
876 error because functions such as @code{read} and @code{write} translate
877 it into a @code{SIGTTIN} or @code{SIGTTOU} signal. @xref{Job Control},
878 for information on process groups and these signals.
882 @comment GNU: Translator died
883 @deftypevr Macro int EDIED
884 @comment errno 101 @c DO NOT REMOVE
885 On @gnuhurdsystems{}, opening a file returns this error when the file is
886 translated by a program and the translator program dies while starting
887 up, before it has connected to the file.
892 @deftypevr Macro int ED
893 @comment errno 102 @c DO NOT REMOVE
894 The experienced user will know what is wrong.
895 @c This error code is a joke. Its perror text is part of the joke.
900 @comment GNU: You really blew it this time
901 @deftypevr Macro int EGREGIOUS
902 @comment errno 103 @c DO NOT REMOVE
903 You did @strong{what}?
907 @comment GNU: Computer bought the farm
908 @deftypevr Macro int EIEIO
909 @comment errno 104 @c DO NOT REMOVE
910 Go home and have a glass of warm, dairy-fresh milk.
914 @comment GNU: Gratuitous error
915 @deftypevr Macro int EGRATUITOUS
916 @comment errno 105 @c DO NOT REMOVE
917 This error code has no purpose.
921 @comment XOPEN: Bad message
922 @deftypevr Macro int EBADMSG
927 @comment XOPEN: Identifier removed
928 @deftypevr Macro int EIDRM
933 @comment XOPEN: Multihop attempted
934 @deftypevr Macro int EMULTIHOP
939 @comment XOPEN: No data available
940 @deftypevr Macro int ENODATA
945 @comment XOPEN: Link has been severed
946 @deftypevr Macro int ENOLINK
951 @comment XOPEN: No message of desired type
952 @deftypevr Macro int ENOMSG
957 @comment XOPEN: Out of streams resources
958 @deftypevr Macro int ENOSR
963 @comment XOPEN: Device not a stream
964 @deftypevr Macro int ENOSTR
969 @comment XOPEN: Value too large for defined data type
970 @deftypevr Macro int EOVERFLOW
975 @comment XOPEN: Protocol error
976 @deftypevr Macro int EPROTO
981 @comment XOPEN: Timer expired
982 @deftypevr Macro int ETIME
987 @comment POSIX.1: Operation canceled
988 @deftypevr Macro int ECANCELED
990 Operation canceled; an asynchronous operation was canceled before it
991 completed. @xref{Asynchronous I/O}. When you call @code{aio_cancel},
992 the normal result is for the operations affected to complete with this
993 error; @pxref{Cancel AIO Operations}.
997 @emph{The following error codes are defined by the Linux/i386 kernel.
998 They are not yet documented.}
1001 @comment Linux???: Interrupted system call should be restarted
1002 @deftypevr Macro int ERESTART
1003 @comment errno ???/85
1007 @comment Linux???: Channel number out of range
1008 @deftypevr Macro int ECHRNG
1009 @comment errno ???/44
1013 @comment Obsolete: Level 2 not synchronized
1014 @deftypevr Macro int EL2NSYNC
1015 @comment errno ???/45
1019 @comment Obsolete: Level 3 halted
1020 @deftypevr Macro int EL3HLT
1021 @comment errno ???/46
1025 @comment Obsolete: Level 3 reset
1026 @deftypevr Macro int EL3RST
1027 @comment errno ???/47
1031 @comment Linux???: Link number out of range
1032 @deftypevr Macro int ELNRNG
1033 @comment errno ???/48
1037 @comment Linux???: Protocol driver not attached
1038 @deftypevr Macro int EUNATCH
1039 @comment errno ???/49
1043 @comment Linux???: No CSI structure available
1044 @deftypevr Macro int ENOCSI
1045 @comment errno ???/50
1049 @comment Obsolete: Level 2 halted
1050 @deftypevr Macro int EL2HLT
1051 @comment errno ???/51
1055 @comment Linux???: Invalid exchange
1056 @deftypevr Macro int EBADE
1057 @comment errno ???/52
1061 @comment Linux???: Invalid request descriptor
1062 @deftypevr Macro int EBADR
1063 @comment errno ???/53
1067 @comment Linux???: Exchange full
1068 @deftypevr Macro int EXFULL
1069 @comment errno ???/54
1073 @comment Linux???: No anode
1074 @deftypevr Macro int ENOANO
1075 @comment errno ???/55
1079 @comment Linux???: Invalid request code
1080 @deftypevr Macro int EBADRQC
1081 @comment errno ???/56
1085 @comment Linux???: Invalid slot
1086 @deftypevr Macro int EBADSLT
1087 @comment errno ???/57
1091 @comment Linux???: File locking deadlock error
1092 @deftypevr Macro int EDEADLOCK
1093 @comment errno ???/58
1097 @comment Linux???: Bad font file format
1098 @deftypevr Macro int EBFONT
1099 @comment errno ???/59
1103 @comment Linux???: Machine is not on the network
1104 @deftypevr Macro int ENONET
1105 @comment errno ???/64
1109 @comment Linux???: Package not installed
1110 @deftypevr Macro int ENOPKG
1111 @comment errno ???/65
1115 @comment Linux???: Advertise error
1116 @deftypevr Macro int EADV
1117 @comment errno ???/68
1121 @comment Linux???: Srmount error
1122 @deftypevr Macro int ESRMNT
1123 @comment errno ???/69
1127 @comment Linux???: Communication error on send
1128 @deftypevr Macro int ECOMM
1129 @comment errno ???/70
1133 @comment Linux???: RFS specific error
1134 @deftypevr Macro int EDOTDOT
1135 @comment errno ???/73
1139 @comment Linux???: Name not unique on network
1140 @deftypevr Macro int ENOTUNIQ
1141 @comment errno ???/76
1145 @comment Linux???: File descriptor in bad state
1146 @deftypevr Macro int EBADFD
1147 @comment errno ???/77
1151 @comment Linux???: Remote address changed
1152 @deftypevr Macro int EREMCHG
1153 @comment errno ???/78
1157 @comment Linux???: Can not access a needed shared library
1158 @deftypevr Macro int ELIBACC
1159 @comment errno ???/79
1163 @comment Linux???: Accessing a corrupted shared library
1164 @deftypevr Macro int ELIBBAD
1165 @comment errno ???/80
1169 @comment Linux???: .lib section in a.out corrupted
1170 @deftypevr Macro int ELIBSCN
1171 @comment errno ???/81
1175 @comment Linux???: Attempting to link in too many shared libraries
1176 @deftypevr Macro int ELIBMAX
1177 @comment errno ???/82
1181 @comment Linux???: Cannot exec a shared library directly
1182 @deftypevr Macro int ELIBEXEC
1183 @comment errno ???/83
1187 @comment Linux???: Streams pipe error
1188 @deftypevr Macro int ESTRPIPE
1189 @comment errno ???/86
1193 @comment Linux???: Structure needs cleaning
1194 @deftypevr Macro int EUCLEAN
1195 @comment errno ???/117
1199 @comment Linux???: Not a XENIX named type file
1200 @deftypevr Macro int ENOTNAM
1201 @comment errno ???/118
1205 @comment Linux???: No XENIX semaphores available
1206 @deftypevr Macro int ENAVAIL
1207 @comment errno ???/119
1211 @comment Linux???: Is a named type file
1212 @deftypevr Macro int EISNAM
1213 @comment errno ???/120
1217 @comment Linux???: Remote I/O error
1218 @deftypevr Macro int EREMOTEIO
1219 @comment errno ???/121
1223 @comment Linux???: No medium found
1224 @deftypevr Macro int ENOMEDIUM
1225 @comment errno ???/???
1229 @comment Linux???: Wrong medium type
1230 @deftypevr Macro int EMEDIUMTYPE
1231 @comment errno ???/???
1235 @comment Linux: Required key not available
1236 @deftypevr Macro int ENOKEY
1237 @comment errno ???/???
1241 @comment Linux: Key has expired
1242 @deftypevr Macro int EKEYEXPIRED
1243 @comment errno ???/???
1247 @comment Linux: Key has been revoked
1248 @deftypevr Macro int EKEYREVOKED
1249 @comment errno ???/???
1253 @comment Linux: Key was rejected by service
1254 @deftypevr Macro int EKEYREJECTED
1255 @comment errno ???/???
1259 @comment Linux: Owner died
1260 @deftypevr Macro int EOWNERDEAD
1261 @comment errno ???/???
1265 @comment Linux: State not recoverable
1266 @deftypevr Macro int ENOTRECOVERABLE
1267 @comment errno ???/???
1271 @comment Linux: Operation not possible due to RF-kill
1272 @deftypevr Macro int ERFKILL
1273 @comment errno ???/???
1277 @comment Linux: Memory page has hardware error
1278 @deftypevr Macro int EHWPOISON
1279 @comment errno ???/???
1282 @node Error Messages, , Error Codes, Error Reporting
1283 @section Error Messages
1285 The library has functions and variables designed to make it easy for
1286 your program to report informative error messages in the customary
1287 format about the failure of a library call. The functions
1288 @code{strerror} and @code{perror} give you the standard error message
1289 for a given error code; the variable
1290 @w{@code{program_invocation_short_name}} gives you convenient access to the
1291 name of the program that encountered the error.
1295 @deftypefun {char *} strerror (int @var{errnum})
1296 The @code{strerror} function maps the error code (@pxref{Checking for
1297 Errors}) specified by the @var{errnum} argument to a descriptive error
1298 message string. The return value is a pointer to this string.
1300 The value @var{errnum} normally comes from the variable @code{errno}.
1302 You should not modify the string returned by @code{strerror}. Also, if
1303 you make subsequent calls to @code{strerror}, the string might be
1304 overwritten. (But it's guaranteed that no library function ever calls
1305 @code{strerror} behind your back.)
1307 The function @code{strerror} is declared in @file{string.h}.
1312 @deftypefun {char *} strerror_r (int @var{errnum}, char *@var{buf}, size_t @var{n})
1313 The @code{strerror_r} function works like @code{strerror} but instead of
1314 returning the error message in a statically allocated buffer shared by
1315 all threads in the process, it returns a private copy for the
1316 thread. This might be either some permanent global data or a message
1317 string in the user supplied buffer starting at @var{buf} with the
1318 length of @var{n} bytes.
1320 At most @var{n} characters are written (including the NUL byte) so it is
1321 up to the user to select the buffer large enough.
1323 This function should always be used in multi-threaded programs since
1324 there is no way to guarantee the string returned by @code{strerror}
1325 really belongs to the last call of the current thread.
1327 This function @code{strerror_r} is a GNU extension and it is declared in
1333 @deftypefun void perror (const char *@var{message})
1334 This function prints an error message to the stream @code{stderr};
1335 see @ref{Standard Streams}. The orientation of @code{stderr} is not
1338 If you call @code{perror} with a @var{message} that is either a null
1339 pointer or an empty string, @code{perror} just prints the error message
1340 corresponding to @code{errno}, adding a trailing newline.
1342 If you supply a non-null @var{message} argument, then @code{perror}
1343 prefixes its output with this string. It adds a colon and a space
1344 character to separate the @var{message} from the error string corresponding
1347 The function @code{perror} is declared in @file{stdio.h}.
1350 @code{strerror} and @code{perror} produce the exact same message for any
1351 given error code; the precise text varies from system to system. With
1352 @theglibc{}, the messages are fairly short; there are no multi-line
1353 messages or embedded newlines. Each error message begins with a capital
1354 letter and does not include any terminating punctuation.
1356 @strong{Compatibility Note:} The @code{strerror} function was introduced
1357 in @w{ISO C89}. Many older C systems do not support this function yet.
1359 @cindex program name
1360 @cindex name of running program
1361 Many programs that don't read input from the terminal are designed to
1362 exit if any system call fails. By convention, the error message from
1363 such a program should start with the program's name, sans directories.
1364 You can find that name in the variable
1365 @code{program_invocation_short_name}; the full file name is stored the
1366 variable @code{program_invocation_name}.
1370 @deftypevar {char *} program_invocation_name
1371 This variable's value is the name that was used to invoke the program
1372 running in the current process. It is the same as @code{argv[0]}. Note
1373 that this is not necessarily a useful file name; often it contains no
1374 directory names. @xref{Program Arguments}.
1379 @deftypevar {char *} program_invocation_short_name
1380 This variable's value is the name that was used to invoke the program
1381 running in the current process, with directory names removed. (That is
1382 to say, it is the same as @code{program_invocation_name} minus
1383 everything up to the last slash, if any.)
1386 The library initialization code sets up both of these variables before
1387 calling @code{main}.
1389 @strong{Portability Note:} These two variables are GNU extensions. If
1390 you want your program to work with non-GNU libraries, you must save the
1391 value of @code{argv[0]} in @code{main}, and then strip off the directory
1392 names yourself. We added these extensions to make it possible to write
1393 self-contained error-reporting subroutines that require no explicit
1394 cooperation from @code{main}.
1396 Here is an example showing how to handle failure to open a file
1397 correctly. The function @code{open_sesame} tries to open the named file
1398 for reading and returns a stream if successful. The @code{fopen}
1399 library function returns a null pointer if it couldn't open the file for
1400 some reason. In that situation, @code{open_sesame} constructs an
1401 appropriate error message using the @code{strerror} function, and
1402 terminates the program. If we were going to make some other library
1403 calls before passing the error code to @code{strerror}, we'd have to
1404 save it in a local variable instead, because those other library
1405 functions might overwrite @code{errno} in the meantime.
1414 open_sesame (char *name)
1419 stream = fopen (name, "r");
1422 fprintf (stderr, "%s: Couldn't open file %s; %s\n",
1423 program_invocation_short_name, name, strerror (errno));
1424 exit (EXIT_FAILURE);
1431 Using @code{perror} has the advantage that the function is portable and
1432 available on all systems implementing @w{ISO C}. But often the text
1433 @code{perror} generates is not what is wanted and there is no way to
1434 extend or change what @code{perror} does. The GNU coding standard, for
1435 instance, requires error messages to be preceded by the program name and
1436 programs which read some input files should provide information
1437 about the input file name and the line number in case an error is
1438 encountered while reading the file. For these occasions there are two
1439 functions available which are widely used throughout the GNU project.
1440 These functions are declared in @file{error.h}.
1444 @deftypefun void error (int @var{status}, int @var{errnum}, const char *@var{format}, @dots{})
1445 The @code{error} function can be used to report general problems during
1446 program execution. The @var{format} argument is a format string just
1447 like those given to the @code{printf} family of functions. The
1448 arguments required for the format can follow the @var{format} parameter.
1449 Just like @code{perror}, @code{error} also can report an error code in
1450 textual form. But unlike @code{perror} the error value is explicitly
1451 passed to the function in the @var{errnum} parameter. This eliminates
1452 the problem mentioned above that the error reporting function must be
1453 called immediately after the function causing the error since otherwise
1454 @code{errno} might have a different value.
1456 The @code{error} prints first the program name. If the application
1457 defined a global variable @code{error_print_progname} and points it to a
1458 function this function will be called to print the program name.
1459 Otherwise the string from the global variable @code{program_name} is
1460 used. The program name is followed by a colon and a space which in turn
1461 is followed by the output produced by the format string. If the
1462 @var{errnum} parameter is non-zero the format string output is followed
1463 by a colon and a space, followed by the error message for the error code
1464 @var{errnum}. In any case is the output terminated with a newline.
1466 The output is directed to the @code{stderr} stream. If the
1467 @code{stderr} wasn't oriented before the call it will be narrow-oriented
1470 The function will return unless the @var{status} parameter has a
1471 non-zero value. In this case the function will call @code{exit} with
1472 the @var{status} value for its parameter and therefore never return. If
1473 @code{error} returns the global variable @code{error_message_count} is
1474 incremented by one to keep track of the number of errors reported.
1479 @deftypefun void error_at_line (int @var{status}, int @var{errnum}, const char *@var{fname}, unsigned int @var{lineno}, const char *@var{format}, @dots{})
1481 The @code{error_at_line} function is very similar to the @code{error}
1482 function. The only difference are the additional parameters @var{fname}
1483 and @var{lineno}. The handling of the other parameters is identical to
1484 that of @code{error} except that between the program name and the string
1485 generated by the format string additional text is inserted.
1487 Directly following the program name a colon, followed by the file name
1488 pointer to by @var{fname}, another colon, and a value of @var{lineno} is
1491 This additional output of course is meant to be used to locate an error
1492 in an input file (like a programming language source code file etc).
1494 If the global variable @code{error_one_per_line} is set to a non-zero
1495 value @code{error_at_line} will avoid printing consecutive messages for
1496 the same file and line. Repetition which are not directly following
1497 each other are not caught.
1499 Just like @code{error} this function only returned if @var{status} is
1500 zero. Otherwise @code{exit} is called with the non-zero value. If
1501 @code{error} returns the global variable @code{error_message_count} is
1502 incremented by one to keep track of the number of errors reported.
1505 As mentioned above the @code{error} and @code{error_at_line} functions
1506 can be customized by defining a variable named
1507 @code{error_print_progname}.
1511 @deftypevar {void (*error_print_progname)} (void)
1512 If the @code{error_print_progname} variable is defined to a non-zero
1513 value the function pointed to is called by @code{error} or
1514 @code{error_at_line}. It is expected to print the program name or do
1515 something similarly useful.
1517 The function is expected to be print to the @code{stderr} stream and
1518 must be able to handle whatever orientation the stream has.
1520 The variable is global and shared by all threads.
1525 @deftypevar {unsigned int} error_message_count
1526 The @code{error_message_count} variable is incremented whenever one of
1527 the functions @code{error} or @code{error_at_line} returns. The
1528 variable is global and shared by all threads.
1533 @deftypevar int error_one_per_line
1534 The @code{error_one_per_line} variable influences only
1535 @code{error_at_line}. Normally the @code{error_at_line} function
1536 creates output for every invocation. If @code{error_one_per_line} is
1537 set to a non-zero value @code{error_at_line} keeps track of the last
1538 file name and line number for which an error was reported and avoid
1539 directly following messages for the same file and line. This variable
1540 is global and shared by all threads.
1544 A program which read some input file and reports errors in it could look
1551 unsigned int lineno = 0;
1553 error_message_count = 0;
1554 while (! feof_unlocked (fp))
1556 ssize_t n = getline (&line, &len, fp);
1558 /* @r{End of file or error.} */
1562 /* @r{Process the line.} */
1565 if (@r{Detect error in line})
1566 error_at_line (0, errval, filename, lineno,
1567 "some error text %s", some_variable);
1570 if (error_message_count != 0)
1571 error (EXIT_FAILURE, 0, "%u errors found", error_message_count);
1575 @code{error} and @code{error_at_line} are clearly the functions of
1576 choice and enable the programmer to write applications which follow the
1577 GNU coding standard. @Theglibc{} additionally contains functions which
1578 are used in BSD for the same purpose. These functions are declared in
1579 @file{err.h}. It is generally advised to not use these functions. They
1580 are included only for compatibility.
1584 @deftypefun void warn (const char *@var{format}, @dots{})
1585 The @code{warn} function is roughly equivalent to a call like
1587 error (0, errno, format, @r{the parameters})
1590 except that the global variables @code{error} respects and modifies
1596 @deftypefun void vwarn (const char *@var{format}, va_list @var{ap})
1597 The @code{vwarn} function is just like @code{warn} except that the
1598 parameters for the handling of the format string @var{format} are passed
1599 in as an value of type @code{va_list}.
1604 @deftypefun void warnx (const char *@var{format}, @dots{})
1605 The @code{warnx} function is roughly equivalent to a call like
1607 error (0, 0, format, @r{the parameters})
1610 except that the global variables @code{error} respects and modifies
1611 are not used. The difference to @code{warn} is that no error number
1617 @deftypefun void vwarnx (const char *@var{format}, va_list @var{ap})
1618 The @code{vwarnx} function is just like @code{warnx} except that the
1619 parameters for the handling of the format string @var{format} are passed
1620 in as an value of type @code{va_list}.
1625 @deftypefun void err (int @var{status}, const char *@var{format}, @dots{})
1626 The @code{err} function is roughly equivalent to a call like
1628 error (status, errno, format, @r{the parameters})
1631 except that the global variables @code{error} respects and modifies
1632 are not used and that the program is exited even if @var{status} is zero.
1637 @deftypefun void verr (int @var{status}, const char *@var{format}, va_list @var{ap})
1638 The @code{verr} function is just like @code{err} except that the
1639 parameters for the handling of the format string @var{format} are passed
1640 in as an value of type @code{va_list}.
1645 @deftypefun void errx (int @var{status}, const char *@var{format}, @dots{})
1646 The @code{errx} function is roughly equivalent to a call like
1648 error (status, 0, format, @r{the parameters})
1651 except that the global variables @code{error} respects and modifies
1652 are not used and that the program is exited even if @var{status}
1653 is zero. The difference to @code{err} is that no error number
1659 @deftypefun void verrx (int @var{status}, const char *@var{format}, va_list @var{ap})
1660 The @code{verrx} function is just like @code{errx} except that the
1661 parameters for the handling of the format string @var{format} are passed
1662 in as an value of type @code{va_list}.