]> git.ipfire.org Git - thirdparty/glibc.git/blame - manual/errno.texi
Update.
[thirdparty/glibc.git] / manual / errno.texi
CommitLineData
28f540f4
RM
1@node Error Reporting, Memory Allocation, Introduction, Top
2@chapter Error Reporting
7a68c94a 3@c %MENU% How library functions report errors
28f540f4
RM
4@cindex error reporting
5@cindex reporting errors
6@cindex error codes
7@cindex status codes
8
9Many functions in the GNU C library detect and report error conditions,
10and sometimes your programs need to check for these error conditions.
11For example, when you open an input file, you should verify that the
12file was actually opened correctly, and print an error message or take
13other appropriate action if the call to the library function failed.
14
15This chapter describes how the error reporting facility works. Your
16program should include the header file @file{errno.h} to use this
17facility.
18@pindex errno.h
19
20@menu
21* Checking for Errors:: How errors are reported by library functions.
b8fe19fa 22* Error Codes:: Error code macros; all of these expand
28f540f4
RM
23 into integer constant values.
24* Error Messages:: Mapping error codes onto error messages.
25@end menu
26
27@node Checking for Errors, Error Codes, , Error Reporting
28@section Checking for Errors
29
30Most library functions return a special value to indicate that they have
31failed. The special value is typically @code{-1}, a null pointer, or a
32constant such as @code{EOF} that is defined for that purpose. But this
33return value tells you only that an error has occurred. To find out
34what kind of error it was, you need to look at the error code stored in the
35variable @code{errno}. This variable is declared in the header file
36@file{errno.h}.
37@pindex errno.h
38
39@comment errno.h
f65fd747 40@comment ISO
28f540f4
RM
41@deftypevr {Variable} {volatile int} errno
42The variable @code{errno} contains the system error number. You can
43change the value of @code{errno}.
44
45Since @code{errno} is declared @code{volatile}, it might be changed
46asynchronously by a signal handler; see @ref{Defining Handlers}.
47However, a properly written signal handler saves and restores the value
48of @code{errno}, so you generally do not need to worry about this
49possibility except when writing signal handlers.
50
51The initial value of @code{errno} at program startup is zero. Many
52library functions are guaranteed to set it to certain nonzero values
53when they encounter certain kinds of errors. These error conditions are
54listed for each function. These functions do not change @code{errno}
55when they succeed; thus, the value of @code{errno} after a successful
56call is not necessarily zero, and you should not use @code{errno} to
57determine @emph{whether} a call failed. The proper way to do that is
bc938d3d 58documented for each function. @emph{If} the call failed, you can
28f540f4
RM
59examine @code{errno}.
60
61Many library functions can set @code{errno} to a nonzero value as a
62result of calling other library functions which might fail. You should
63assume that any library function might alter @code{errno} when the
64function returns an error.
65
f65fd747 66@strong{Portability Note:} @w{ISO C} specifies @code{errno} as a
28f540f4
RM
67``modifiable lvalue'' rather than as a variable, permitting it to be
68implemented as a macro. For example, its expansion might involve a
69function call, like @w{@code{*_errno ()}}. In fact, that is what it is
70on the GNU system itself. The GNU library, on non-GNU systems, does
71whatever is right for the particular system.
72
73There are a few library functions, like @code{sqrt} and @code{atan},
74that return a perfectly legitimate value in case of an error, but also
75set @code{errno}. For these functions, if you want to check to see
76whether an error occurred, the recommended method is to set @code{errno}
77to zero before calling the function, and then check its value afterward.
78@end deftypevr
79
80@pindex errno.h
81All the error codes have symbolic names; they are macros defined in
82@file{errno.h}. The names start with @samp{E} and an upper-case
83letter or digit; you should consider names of this form to be
84reserved names. @xref{Reserved Names}.
85
86The error code values are all positive integers and are all distinct,
87with one exception: @code{EWOULDBLOCK} and @code{EAGAIN} are the same.
88Since the values are distinct, you can use them as labels in a
89@code{switch} statement; just don't use both @code{EWOULDBLOCK} and
90@code{EAGAIN}. Your program should not make any other assumptions about
91the specific values of these symbolic constants.
92
93The value of @code{errno} doesn't necessarily have to correspond to any
94of these macros, since some library functions might return other error
95codes of their own for other situations. The only values that are
96guaranteed to be meaningful for a particular library function are the
97ones that this manual lists for that function.
98
99On non-GNU systems, almost any system call can return @code{EFAULT} if
100it is given an invalid pointer as an argument. Since this could only
101happen as a result of a bug in your program, and since it will not
102happen on the GNU system, we have saved space by not mentioning
103@code{EFAULT} in the descriptions of individual functions.
104
105In some Unix systems, many system calls can also return @code{EFAULT} if
106given as an argument a pointer into the stack, and the kernel for some
107obscure reason fails in its attempt to extend the stack. If this ever
108happens, you should probably try using statically or dynamically
109allocated memory instead of stack memory on that system.
110
111@node Error Codes, Error Messages, Checking for Errors, Error Reporting
112@section Error Codes
113
114@pindex errno.h
115The error code macros are defined in the header file @file{errno.h}.
116All of them expand into integer constant values. Some of these error
117codes can't occur on the GNU system, but they can occur using the GNU
118library on other systems.
119
120@comment errno.h
121@comment POSIX.1: Operation not permitted
122@deftypevr Macro int EPERM
123@comment errno 1 @c DO NOT REMOVE
124Operation not permitted; only the owner of the file (or other resource)
125or processes with special privileges can perform the operation.
126@end deftypevr
127
128@comment errno.h
129@comment POSIX.1: No such file or directory
130@deftypevr Macro int ENOENT
131@comment errno 2 @c DO NOT REMOVE
132No such file or directory. This is a ``file doesn't exist'' error
133for ordinary files that are referenced in contexts where they are
134expected to already exist.
135@end deftypevr
136
137@comment errno.h
138@comment POSIX.1: No such process
139@deftypevr Macro int ESRCH
140@comment errno 3 @c DO NOT REMOVE
141No process matches the specified process ID.
142@end deftypevr
143
144@comment errno.h
145@comment POSIX.1: Interrupted system call
146@deftypevr Macro int EINTR
147@comment errno 4 @c DO NOT REMOVE
6d52618b 148Interrupted function call; an asynchronous signal occurred and prevented
28f540f4
RM
149completion of the call. When this happens, you should try the call
150again.
151
152You can choose to have functions resume after a signal that is handled,
153rather than failing with @code{EINTR}; see @ref{Interrupted
154Primitives}.
155@end deftypevr
156
157@comment errno.h
158@comment POSIX.1: Input/output error
159@deftypevr Macro int EIO
160@comment errno 5 @c DO NOT REMOVE
161Input/output error; usually used for physical read or write errors.
162@end deftypevr
163
164@comment errno.h
165@comment POSIX.1: Device not configured
166@deftypevr Macro int ENXIO
167@comment errno 6 @c DO NOT REMOVE
168No such device or address. The system tried to use the device
169represented by a file you specified, and it couldn't find the device.
170This can mean that the device file was installed incorrectly, or that
171the physical device is missing or not correctly attached to the
172computer.
173@end deftypevr
174
175@comment errno.h
176@comment POSIX.1: Argument list too long
177@deftypevr Macro int E2BIG
178@comment errno 7 @c DO NOT REMOVE
179Argument list too long; used when the arguments passed to a new program
180being executed with one of the @code{exec} functions (@pxref{Executing a
181File}) occupy too much memory space. This condition never arises in the
182GNU system.
183@end deftypevr
184
185@comment errno.h
186@comment POSIX.1: Exec format error
187@deftypevr Macro int ENOEXEC
188@comment errno 8 @c DO NOT REMOVE
189Invalid executable file format. This condition is detected by the
190@code{exec} functions; see @ref{Executing a File}.
191@end deftypevr
192
193@comment errno.h
194@comment POSIX.1: Bad file descriptor
195@deftypevr Macro int EBADF
196@comment errno 9 @c DO NOT REMOVE
197Bad file descriptor; for example, I/O on a descriptor that has been
198closed or reading from a descriptor open only for writing (or vice
199versa).
200@end deftypevr
201
202@comment errno.h
203@comment POSIX.1: No child processes
204@deftypevr Macro int ECHILD
205@comment errno 10 @c DO NOT REMOVE
206There are no child processes. This error happens on operations that are
207supposed to manipulate child processes, when there aren't any processes
208to manipulate.
209@end deftypevr
210
211@comment errno.h
212@comment POSIX.1: Resource deadlock avoided
213@deftypevr Macro int EDEADLK
214@comment errno 11 @c DO NOT REMOVE
215Deadlock avoided; allocating a system resource would have resulted in a
216deadlock situation. The system does not guarantee that it will notice
217all such situations. This error means you got lucky and the system
218noticed; it might just hang. @xref{File Locks}, for an example.
219@end deftypevr
220
221@comment errno.h
222@comment POSIX.1: Cannot allocate memory
223@deftypevr Macro int ENOMEM
224@comment errno 12 @c DO NOT REMOVE
225No memory available. The system cannot allocate more virtual memory
226because its capacity is full.
227@end deftypevr
228
229@comment errno.h
230@comment POSIX.1: Permission denied
231@deftypevr Macro int EACCES
232@comment errno 13 @c DO NOT REMOVE
233Permission denied; the file permissions do not allow the attempted operation.
234@end deftypevr
235
236@comment errno.h
237@comment POSIX.1: Bad address
238@deftypevr Macro int EFAULT
239@comment errno 14 @c DO NOT REMOVE
240Bad address; an invalid pointer was detected.
241In the GNU system, this error never happens; you get a signal instead.
242@end deftypevr
243
244@comment errno.h
245@comment BSD: Block device required
246@deftypevr Macro int ENOTBLK
247@comment errno 15 @c DO NOT REMOVE
248A file that isn't a block special file was given in a situation that
249requires one. For example, trying to mount an ordinary file as a file
250system in Unix gives this error.
251@end deftypevr
252
253@comment errno.h
b25ae9c6 254@comment POSIX.1: Device or resource busy
28f540f4
RM
255@deftypevr Macro int EBUSY
256@comment errno 16 @c DO NOT REMOVE
257Resource busy; a system resource that can't be shared is already in use.
258For example, if you try to delete a file that is the root of a currently
259mounted filesystem, you get this error.
260@end deftypevr
261
262@comment errno.h
263@comment POSIX.1: File exists
264@deftypevr Macro int EEXIST
265@comment errno 17 @c DO NOT REMOVE
266File exists; an existing file was specified in a context where it only
267makes sense to specify a new file.
268@end deftypevr
269
270@comment errno.h
271@comment POSIX.1: Invalid cross-device link
272@deftypevr Macro int EXDEV
273@comment errno 18 @c DO NOT REMOVE
274An attempt to make an improper link across file systems was detected.
275This happens not only when you use @code{link} (@pxref{Hard Links}) but
276also when you rename a file with @code{rename} (@pxref{Renaming Files}).
277@end deftypevr
278
279@comment errno.h
dfd2464b 280@comment POSIX.1: No such device
28f540f4
RM
281@deftypevr Macro int ENODEV
282@comment errno 19 @c DO NOT REMOVE
283The wrong type of device was given to a function that expects a
284particular sort of device.
285@end deftypevr
286
287@comment errno.h
288@comment POSIX.1: Not a directory
289@deftypevr Macro int ENOTDIR
290@comment errno 20 @c DO NOT REMOVE
291A file that isn't a directory was specified when a directory is required.
292@end deftypevr
293
294@comment errno.h
295@comment POSIX.1: Is a directory
296@deftypevr Macro int EISDIR
297@comment errno 21 @c DO NOT REMOVE
298File is a directory; you cannot open a directory for writing,
299or create or remove hard links to it.
300@end deftypevr
301
302@comment errno.h
303@comment POSIX.1: Invalid argument
304@deftypevr Macro int EINVAL
305@comment errno 22 @c DO NOT REMOVE
306Invalid argument. This is used to indicate various kinds of problems
307with passing the wrong argument to a library function.
308@end deftypevr
309
310@comment errno.h
311@comment POSIX.1: Too many open files
312@deftypevr Macro int EMFILE
313@comment errno 24 @c DO NOT REMOVE
314The current process has too many files open and can't open any more.
315Duplicate descriptors do count toward this limit.
316
317In BSD and GNU, the number of open files is controlled by a resource
318limit that can usually be increased. If you get this error, you might
319want to increase the @code{RLIMIT_NOFILE} limit or make it unlimited;
320@pxref{Limits on Resources}.
321@end deftypevr
322
323@comment errno.h
324@comment POSIX.1: Too many open files in system
325@deftypevr Macro int ENFILE
326@comment errno 23 @c DO NOT REMOVE
327There are too many distinct file openings in the entire system. Note
328that any number of linked channels count as just one file opening; see
329@ref{Linked Channels}. This error never occurs in the GNU system.
330@end deftypevr
331
332@comment errno.h
333@comment POSIX.1: Inappropriate ioctl for device
334@deftypevr Macro int ENOTTY
335@comment errno 25 @c DO NOT REMOVE
336Inappropriate I/O control operation, such as trying to set terminal
337modes on an ordinary file.
338@end deftypevr
339
340@comment errno.h
341@comment BSD: Text file busy
342@deftypevr Macro int ETXTBSY
343@comment errno 26 @c DO NOT REMOVE
344An attempt to execute a file that is currently open for writing, or
345write to a file that is currently being executed. Often using a
346debugger to run a program is considered having it open for writing and
347will cause this error. (The name stands for ``text file busy''.) This
348is not an error in the GNU system; the text is copied as necessary.
349@end deftypevr
350
351@comment errno.h
352@comment POSIX.1: File too large
353@deftypevr Macro int EFBIG
354@comment errno 27 @c DO NOT REMOVE
355File too big; the size of a file would be larger than allowed by the system.
356@end deftypevr
357
358@comment errno.h
359@comment POSIX.1: No space left on device
360@deftypevr Macro int ENOSPC
361@comment errno 28 @c DO NOT REMOVE
362No space left on device; write operation on a file failed because the
363disk is full.
364@end deftypevr
365
366@comment errno.h
367@comment POSIX.1: Illegal seek
368@deftypevr Macro int ESPIPE
369@comment errno 29 @c DO NOT REMOVE
370Invalid seek operation (such as on a pipe).
371@end deftypevr
372
373@comment errno.h
374@comment POSIX.1: Read-only file system
375@deftypevr Macro int EROFS
376@comment errno 30 @c DO NOT REMOVE
377An attempt was made to modify something on a read-only file system.
378@end deftypevr
379
380@comment errno.h
381@comment POSIX.1: Too many links
382@deftypevr Macro int EMLINK
383@comment errno 31 @c DO NOT REMOVE
384Too many links; the link count of a single file would become too large.
385@code{rename} can cause this error if the file being renamed already has
386as many links as it can take (@pxref{Renaming Files}).
387@end deftypevr
388
389@comment errno.h
390@comment POSIX.1: Broken pipe
391@deftypevr Macro int EPIPE
392@comment errno 32 @c DO NOT REMOVE
393Broken pipe; there is no process reading from the other end of a pipe.
394Every library function that returns this error code also generates a
395@code{SIGPIPE} signal; this signal terminates the program if not handled
396or blocked. Thus, your program will never actually see @code{EPIPE}
397unless it has handled or blocked @code{SIGPIPE}.
398@end deftypevr
399
400@comment errno.h
f65fd747 401@comment ISO: Numerical argument out of domain
28f540f4
RM
402@deftypevr Macro int EDOM
403@comment errno 33 @c DO NOT REMOVE
404Domain error; used by mathematical functions when an argument value does
405not fall into the domain over which the function is defined.
406@end deftypevr
407
408@comment errno.h
f65fd747 409@comment ISO: Numerical result out of range
28f540f4
RM
410@deftypevr Macro int ERANGE
411@comment errno 34 @c DO NOT REMOVE
412Range error; used by mathematical functions when the result value is
413not representable because of overflow or underflow.
414@end deftypevr
415
416@comment errno.h
417@comment POSIX.1: Resource temporarily unavailable
418@deftypevr Macro int EAGAIN
419@comment errno 35 @c DO NOT REMOVE
420Resource temporarily unavailable; the call might work if you try again
421later. The macro @code{EWOULDBLOCK} is another name for @code{EAGAIN};
422they are always the same in the GNU C library.
423
424This error can happen in a few different situations:
425
426@itemize @bullet
427@item
428An operation that would block was attempted on an object that has
429non-blocking mode selected. Trying the same operation again will block
430until some external condition makes it possible to read, write, or
431connect (whatever the operation). You can use @code{select} to find out
432when the operation will be possible; @pxref{Waiting for I/O}.
433
55c14926 434@strong{Portability Note:} In many older Unix systems, this condition
28f540f4
RM
435was indicated by @code{EWOULDBLOCK}, which was a distinct error code
436different from @code{EAGAIN}. To make your program portable, you should
437check for both codes and treat them the same.
438
439@item
440A temporary resource shortage made an operation impossible. @code{fork}
441can return this error. It indicates that the shortage is expected to
442pass, so your program can try the call again later and it may succeed.
443It is probably a good idea to delay for a few seconds before trying it
444again, to allow time for other processes to release scarce resources.
445Such shortages are usually fairly serious and affect the whole system,
446so usually an interactive program should report the error to the user
447and return to its command loop.
448@end itemize
449@end deftypevr
450
451@comment errno.h
452@comment BSD: Operation would block
453@deftypevr Macro int EWOULDBLOCK
454@comment errno EAGAIN @c DO NOT REMOVE
455In the GNU C library, this is another name for @code{EAGAIN} (above).
456The values are always the same, on every operating system.
457
458C libraries in many older Unix systems have @code{EWOULDBLOCK} as a
459separate error code.
460@end deftypevr
461
462@comment errno.h
463@comment BSD: Operation now in progress
464@deftypevr Macro int EINPROGRESS
465@comment errno 36 @c DO NOT REMOVE
466An operation that cannot complete immediately was initiated on an object
467that has non-blocking mode selected. Some functions that must always
468block (such as @code{connect}; @pxref{Connecting}) never return
469@code{EAGAIN}. Instead, they return @code{EINPROGRESS} to indicate that
470the operation has begun and will take some time. Attempts to manipulate
471the object before the call completes return @code{EALREADY}. You can
472use the @code{select} function to find out when the pending operation
473has completed; @pxref{Waiting for I/O}.
474@end deftypevr
475
476@comment errno.h
477@comment BSD: Operation already in progress
478@deftypevr Macro int EALREADY
479@comment errno 37 @c DO NOT REMOVE
480An operation is already in progress on an object that has non-blocking
481mode selected.
482@end deftypevr
483
484@comment errno.h
485@comment BSD: Socket operation on non-socket
486@deftypevr Macro int ENOTSOCK
487@comment errno 38 @c DO NOT REMOVE
488A file that isn't a socket was specified when a socket is required.
489@end deftypevr
490
491@comment errno.h
492@comment BSD: Message too long
493@deftypevr Macro int EMSGSIZE
494@comment errno 40 @c DO NOT REMOVE
495The size of a message sent on a socket was larger than the supported
b8fe19fa 496maximum size.
28f540f4
RM
497@end deftypevr
498
499@comment errno.h
500@comment BSD: Protocol wrong type for socket
501@deftypevr Macro int EPROTOTYPE
502@comment errno 41 @c DO NOT REMOVE
503The socket type does not support the requested communications protocol.
504@end deftypevr
505
506@comment errno.h
507@comment BSD: Protocol not available
508@deftypevr Macro int ENOPROTOOPT
509@comment errno 42 @c DO NOT REMOVE
510You specified a socket option that doesn't make sense for the
511particular protocol being used by the socket. @xref{Socket Options}.
512@end deftypevr
513
514@comment errno.h
515@comment BSD: Protocol not supported
516@deftypevr Macro int EPROTONOSUPPORT
517@comment errno 43 @c DO NOT REMOVE
518The socket domain does not support the requested communications protocol
7ba4fcfc 519(perhaps because the requested protocol is completely invalid).
28f540f4
RM
520@xref{Creating a Socket}.
521@end deftypevr
522
523@comment errno.h
524@comment BSD: Socket type not supported
525@deftypevr Macro int ESOCKTNOSUPPORT
526@comment errno 44 @c DO NOT REMOVE
527The socket type is not supported.
528@end deftypevr
529
530@comment errno.h
531@comment BSD: Operation not supported
532@deftypevr Macro int EOPNOTSUPP
533@comment errno 45 @c DO NOT REMOVE
534The operation you requested is not supported. Some socket functions
535don't make sense for all types of sockets, and others may not be
536implemented for all communications protocols. In the GNU system, this
537error can happen for many calls when the object does not support the
538particular operation; it is a generic indication that the server knows
539nothing to do for that call.
540@end deftypevr
541
542@comment errno.h
543@comment BSD: Protocol family not supported
544@deftypevr Macro int EPFNOSUPPORT
545@comment errno 46 @c DO NOT REMOVE
546The socket communications protocol family you requested is not supported.
547@end deftypevr
548
549@comment errno.h
b25ae9c6 550@comment BSD: Address family not supported by protocol
28f540f4
RM
551@deftypevr Macro int EAFNOSUPPORT
552@comment errno 47 @c DO NOT REMOVE
553The address family specified for a socket is not supported; it is
554inconsistent with the protocol being used on the socket. @xref{Sockets}.
555@end deftypevr
556
557@comment errno.h
558@comment BSD: Address already in use
559@deftypevr Macro int EADDRINUSE
560@comment errno 48 @c DO NOT REMOVE
561The requested socket address is already in use. @xref{Socket Addresses}.
562@end deftypevr
563
564@comment errno.h
b25ae9c6 565@comment BSD: Cannot assign requested address
28f540f4
RM
566@deftypevr Macro int EADDRNOTAVAIL
567@comment errno 49 @c DO NOT REMOVE
568The requested socket address is not available; for example, you tried
569to give a socket a name that doesn't match the local host name.
570@xref{Socket Addresses}.
571@end deftypevr
572
573@comment errno.h
574@comment BSD: Network is down
575@deftypevr Macro int ENETDOWN
576@comment errno 50 @c DO NOT REMOVE
577A socket operation failed because the network was down.
578@end deftypevr
579
580@comment errno.h
581@comment BSD: Network is unreachable
582@deftypevr Macro int ENETUNREACH
583@comment errno 51 @c DO NOT REMOVE
584A socket operation failed because the subnet containing the remote host
585was unreachable.
586@end deftypevr
587
588@comment errno.h
589@comment BSD: Network dropped connection on reset
590@deftypevr Macro int ENETRESET
591@comment errno 52 @c DO NOT REMOVE
592A network connection was reset because the remote host crashed.
593@end deftypevr
594
595@comment errno.h
596@comment BSD: Software caused connection abort
597@deftypevr Macro int ECONNABORTED
598@comment errno 53 @c DO NOT REMOVE
599A network connection was aborted locally.
600@end deftypevr
601
602@comment errno.h
603@comment BSD: Connection reset by peer
604@deftypevr Macro int ECONNRESET
605@comment errno 54 @c DO NOT REMOVE
606A network connection was closed for reasons outside the control of the
607local host, such as by the remote machine rebooting or an unrecoverable
608protocol violation.
609@end deftypevr
610
611@comment errno.h
612@comment BSD: No buffer space available
613@deftypevr Macro int ENOBUFS
614@comment errno 55 @c DO NOT REMOVE
615The kernel's buffers for I/O operations are all in use. In GNU, this
616error is always synonymous with @code{ENOMEM}; you may get one or the
617other from network operations.
618@end deftypevr
619
620@comment errno.h
b25ae9c6 621@comment BSD: Transport endpoint is already connected
28f540f4
RM
622@deftypevr Macro int EISCONN
623@comment errno 56 @c DO NOT REMOVE
624You tried to connect a socket that is already connected.
625@xref{Connecting}.
626@end deftypevr
627
628@comment errno.h
b25ae9c6 629@comment BSD: Transport endpoint is not connected
28f540f4
RM
630@deftypevr Macro int ENOTCONN
631@comment errno 57 @c DO NOT REMOVE
632The socket is not connected to anything. You get this error when you
633try to transmit data over a socket, without first specifying a
634destination for the data. For a connectionless socket (for datagram
635protocols, such as UDP), you get @code{EDESTADDRREQ} instead.
636@end deftypevr
637
638@comment errno.h
639@comment BSD: Destination address required
640@deftypevr Macro int EDESTADDRREQ
641@comment errno 39 @c DO NOT REMOVE
642No default destination address was set for the socket. You get this
643error when you try to transmit data over a connectionless socket,
644without first specifying a destination for the data with @code{connect}.
645@end deftypevr
646
647@comment errno.h
b25ae9c6 648@comment BSD: Cannot send after transport endpoint shutdown
28f540f4
RM
649@deftypevr Macro int ESHUTDOWN
650@comment errno 58 @c DO NOT REMOVE
651The socket has already been shut down.
652@end deftypevr
653
654@comment errno.h
b25ae9c6 655@comment BSD: Too many references: cannot splice
28f540f4
RM
656@deftypevr Macro int ETOOMANYREFS
657@comment errno 59 @c DO NOT REMOVE
658???
659@end deftypevr
660
661@comment errno.h
662@comment BSD: Connection timed out
663@deftypevr Macro int ETIMEDOUT
664@comment errno 60 @c DO NOT REMOVE
665A socket operation with a specified timeout received no response during
666the timeout period.
667@end deftypevr
668
669@comment errno.h
670@comment BSD: Connection refused
671@deftypevr Macro int ECONNREFUSED
672@comment errno 61 @c DO NOT REMOVE
673A remote host refused to allow the network connection (typically because
674it is not running the requested service).
675@end deftypevr
676
677@comment errno.h
678@comment BSD: Too many levels of symbolic links
679@deftypevr Macro int ELOOP
680@comment errno 62 @c DO NOT REMOVE
681Too many levels of symbolic links were encountered in looking up a file name.
682This often indicates a cycle of symbolic links.
683@end deftypevr
684
685@comment errno.h
686@comment POSIX.1: File name too long
687@deftypevr Macro int ENAMETOOLONG
688@comment errno 63 @c DO NOT REMOVE
689Filename too long (longer than @code{PATH_MAX}; @pxref{Limits for
690Files}) or host name too long (in @code{gethostname} or
691@code{sethostname}; @pxref{Host Identification}).
692@end deftypevr
693
694@comment errno.h
695@comment BSD: Host is down
696@deftypevr Macro int EHOSTDOWN
697@comment errno 64 @c DO NOT REMOVE
698The remote host for a requested network connection is down.
699@end deftypevr
700
701@comment errno.h
702@comment BSD: No route to host
703@deftypevr Macro int EHOSTUNREACH
704@comment errno 65 @c DO NOT REMOVE
705The remote host for a requested network connection is not reachable.
706@end deftypevr
707
708@comment errno.h
709@comment POSIX.1: Directory not empty
710@deftypevr Macro int ENOTEMPTY
711@comment errno 66 @c DO NOT REMOVE
712Directory not empty, where an empty directory was expected. Typically,
713this error occurs when you are trying to delete a directory.
714@end deftypevr
715
716@comment errno.h
717@comment BSD: Too many processes
718@deftypevr Macro int EPROCLIM
719@comment errno 67 @c DO NOT REMOVE
720This means that the per-user limit on new process would be exceeded by
721an attempted @code{fork}. @xref{Limits on Resources}, for details on
722the @code{RLIMIT_NPROC} limit.
723@end deftypevr
724
725@comment errno.h
726@comment BSD: Too many users
727@deftypevr Macro int EUSERS
728@comment errno 68 @c DO NOT REMOVE
729The file quota system is confused because there are too many users.
730@c This can probably happen in a GNU system when using NFS.
731@end deftypevr
732
733@comment errno.h
f1f0edfe 734@comment BSD: Disk quota exceeded
28f540f4
RM
735@deftypevr Macro int EDQUOT
736@comment errno 69 @c DO NOT REMOVE
737The user's disk quota was exceeded.
738@end deftypevr
739
740@comment errno.h
741@comment BSD: Stale NFS file handle
742@deftypevr Macro int ESTALE
743@comment errno 70 @c DO NOT REMOVE
744Stale NFS file handle. This indicates an internal confusion in the NFS
745system which is due to file system rearrangements on the server host.
746Repairing this condition usually requires unmounting and remounting
747the NFS file system on the local host.
748@end deftypevr
749
750@comment errno.h
b25ae9c6 751@comment BSD: Object is remote
28f540f4
RM
752@deftypevr Macro int EREMOTE
753@comment errno 71 @c DO NOT REMOVE
754An attempt was made to NFS-mount a remote file system with a file name that
755already specifies an NFS-mounted file.
756(This is an error on some operating systems, but we expect it to work
757properly on the GNU system, making this error code impossible.)
758@end deftypevr
759
760@comment errno.h
761@comment BSD: RPC struct is bad
762@deftypevr Macro int EBADRPC
763@comment errno 72 @c DO NOT REMOVE
764???
765@end deftypevr
766
767@comment errno.h
768@comment BSD: RPC version wrong
769@deftypevr Macro int ERPCMISMATCH
770@comment errno 73 @c DO NOT REMOVE
771???
772@end deftypevr
773
774@comment errno.h
775@comment BSD: RPC program not available
776@deftypevr Macro int EPROGUNAVAIL
777@comment errno 74 @c DO NOT REMOVE
778???
779@end deftypevr
780
781@comment errno.h
782@comment BSD: RPC program version wrong
783@deftypevr Macro int EPROGMISMATCH
784@comment errno 75 @c DO NOT REMOVE
785???
786@end deftypevr
787
788@comment errno.h
789@comment BSD: RPC bad procedure for program
790@deftypevr Macro int EPROCUNAVAIL
791@comment errno 76 @c DO NOT REMOVE
792???
793@end deftypevr
794
795@comment errno.h
796@comment POSIX.1: No locks available
797@deftypevr Macro int ENOLCK
798@comment errno 77 @c DO NOT REMOVE
799No locks available. This is used by the file locking facilities; see
800@ref{File Locks}. This error is never generated by the GNU system, but
801it can result from an operation to an NFS server running another
802operating system.
803@end deftypevr
804
805@comment errno.h
806@comment BSD: Inappropriate file type or format
807@deftypevr Macro int EFTYPE
808@comment errno 79 @c DO NOT REMOVE
809Inappropriate file type or format. The file was the wrong type for the
810operation, or a data file had the wrong format.
811
812On some systems @code{chmod} returns this error if you try to set the
813sticky bit on a non-directory file; @pxref{Setting Permissions}.
814@end deftypevr
815
816@comment errno.h
817@comment BSD: Authentication error
818@deftypevr Macro int EAUTH
819@comment errno 80 @c DO NOT REMOVE
820???
821@end deftypevr
822
823@comment errno.h
824@comment BSD: Need authenticator
825@deftypevr Macro int ENEEDAUTH
826@comment errno 81 @c DO NOT REMOVE
827???
828@end deftypevr
829
830@comment errno.h
831@comment POSIX.1: Function not implemented
832@deftypevr Macro int ENOSYS
833@comment errno 78 @c DO NOT REMOVE
75d0cab2
RM
834Function not implemented. This indicates that the function called is
835not implemented at all, either in the C library itself or in the
836operating system. When you get this error, you can be sure that this
837particular function will always fail with @code{ENOSYS} unless you
838install a new version of the C library or the operating system.
839@end deftypevr
840
841@comment errno.h
842@comment POSIX.1: Not supported
843@deftypevr Macro int ENOTSUP
844@comment errno 118 @c DO NOT REMOVE
845Not supported. A function returns this error when certain parameter
846values are valid, but the functionality they request is not available.
847This can mean that the function does not implement a particular command
848or option value or flag bit at all. For functions that operate on some
849object given in a parameter, such as a file descriptor or a port, it
850might instead mean that only @emph{that specific object} (file
851descriptor, port, etc.) is unable to support the other parameters given;
852different file descriptors might support different ranges of parameter
853values.
854
855If the entire function is not available at all in the implementation,
856it returns @code{ENOSYS} instead.
28f540f4
RM
857@end deftypevr
858
b8fe19fa 859@comment errno.h
fa0bc87c 860@comment ISO: Invalid or incomplete multibyte or wide character
b8fe19fa
RM
861@deftypevr Macro int EILSEQ
862@comment errno 106 @c DO NOT REMOVE
863While decoding a multibyte character the function came along an invalid
864or an incomplete sequence of bytes or the given wide character is invalid.
865@end deftypevr
866
28f540f4
RM
867@comment errno.h
868@comment GNU: Inappropriate operation for background process
869@deftypevr Macro int EBACKGROUND
870@comment errno 100 @c DO NOT REMOVE
871In the GNU system, servers supporting the @code{term} protocol return
872this error for certain operations when the caller is not in the
873foreground process group of the terminal. Users do not usually see this
874error because functions such as @code{read} and @code{write} translate
875it into a @code{SIGTTIN} or @code{SIGTTOU} signal. @xref{Job Control},
876for information on process groups and these signals.
877@end deftypevr
878
879@comment errno.h
880@comment GNU: Translator died
881@deftypevr Macro int EDIED
882@comment errno 101 @c DO NOT REMOVE
883In the GNU system, opening a file returns this error when the file is
884translated by a program and the translator program dies while starting
885up, before it has connected to the file.
886@end deftypevr
887
888@comment errno.h
889@comment GNU: ?
890@deftypevr Macro int ED
891@comment errno 102 @c DO NOT REMOVE
892The experienced user will know what is wrong.
a78b0f18
RM
893@c This error code is a joke. Its perror text is part of the joke.
894@c Don't change it.
28f540f4
RM
895@end deftypevr
896
897@comment errno.h
898@comment GNU: You really blew it this time
899@deftypevr Macro int EGREGIOUS
900@comment errno 103 @c DO NOT REMOVE
901You did @strong{what}?
902@end deftypevr
903
904@comment errno.h
905@comment GNU: Computer bought the farm
906@deftypevr Macro int EIEIO
907@comment errno 104 @c DO NOT REMOVE
908Go home and have a glass of warm, dairy-fresh milk.
909@end deftypevr
910
911@comment errno.h
912@comment GNU: Gratuitous error
913@deftypevr Macro int EGRATUITOUS
914@comment errno 105 @c DO NOT REMOVE
915This error code has no purpose.
916@end deftypevr
917
ebe3b3eb
TBB
918@comment errno.h
919@comment XOPEN: Bad message
920@deftypevr Macro int EBADMSG
921@comment errno 107
922@end deftypevr
b25ae9c6
RM
923
924@comment errno.h
ebe3b3eb
TBB
925@comment XOPEN: Identifier removed
926@deftypevr Macro int EIDRM
927@comment errno 108
928@end deftypevr
929
930@comment errno.h
931@comment XOPEN: Multihop attempted
932@deftypevr Macro int EMULTIHOP
933@comment errno 109
934@end deftypevr
935
936@comment errno.h
937@comment XOPEN: No data available
938@deftypevr Macro int ENODATA
939@comment errno 110
b25ae9c6
RM
940@end deftypevr
941
942@comment errno.h
ebe3b3eb
TBB
943@comment XOPEN: Link has been severed
944@deftypevr Macro int ENOLINK
945@comment errno 111
946@end deftypevr
947
948@comment errno.h
949@comment XOPEN: No message of desired type
b25ae9c6 950@deftypevr Macro int ENOMSG
ebe3b3eb 951@comment errno 112
b25ae9c6
RM
952@end deftypevr
953
954@comment errno.h
ebe3b3eb
TBB
955@comment XOPEN: Out of streams resources
956@deftypevr Macro int ENOSR
957@comment errno 113
958@end deftypevr
959
960@comment errno.h
961@comment XOPEN: Device not a stream
962@deftypevr Macro int ENOSTR
963@comment errno 114
964@end deftypevr
965
966@comment errno.h
967@comment XOPEN: Value too large for defined data type
968@deftypevr Macro int EOVERFLOW
969@comment errno 115
970@end deftypevr
971
972@comment errno.h
973@comment XOPEN: Protocol error
974@deftypevr Macro int EPROTO
975@comment errno 116
976@end deftypevr
977
978@comment errno.h
979@comment XOPEN: Timer expired
980@deftypevr Macro int ETIME
981@comment errno 117
982@end deftypevr
983
984
985@emph{The following error codes are defined by the Linux/i386 kernel.
986They are not yet documented.}
987
988@comment errno.h
989@comment Linux???: Interrupted system call should be restarted
990@deftypevr Macro int ERESTART
991@comment errno ???/85
b25ae9c6
RM
992@end deftypevr
993
994@comment errno.h
995@comment Linux???: Channel number out of range
996@deftypevr Macro int ECHRNG
997@comment errno ???/44
998@end deftypevr
999
1000@comment errno.h
838e5ffe 1001@comment Obsolete: Level 2 not synchronized
b25ae9c6
RM
1002@deftypevr Macro int EL2NSYNC
1003@comment errno ???/45
1004@end deftypevr
1005
1006@comment errno.h
838e5ffe 1007@comment Obsolete: Level 3 halted
b25ae9c6
RM
1008@deftypevr Macro int EL3HLT
1009@comment errno ???/46
1010@end deftypevr
1011
1012@comment errno.h
838e5ffe 1013@comment Obsolete: Level 3 reset
b25ae9c6
RM
1014@deftypevr Macro int EL3RST
1015@comment errno ???/47
1016@end deftypevr
1017
1018@comment errno.h
1019@comment Linux???: Link number out of range
1020@deftypevr Macro int ELNRNG
1021@comment errno ???/48
1022@end deftypevr
1023
1024@comment errno.h
1025@comment Linux???: Protocol driver not attached
1026@deftypevr Macro int EUNATCH
1027@comment errno ???/49
1028@end deftypevr
1029
1030@comment errno.h
1031@comment Linux???: No CSI structure available
1032@deftypevr Macro int ENOCSI
1033@comment errno ???/50
1034@end deftypevr
1035
1036@comment errno.h
838e5ffe 1037@comment Obsolete: Level 2 halted
b25ae9c6
RM
1038@deftypevr Macro int EL2HLT
1039@comment errno ???/51
1040@end deftypevr
1041
1042@comment errno.h
1043@comment Linux???: Invalid exchange
1044@deftypevr Macro int EBADE
1045@comment errno ???/52
1046@end deftypevr
1047
1048@comment errno.h
1049@comment Linux???: Invalid request descriptor
1050@deftypevr Macro int EBADR
1051@comment errno ???/53
1052@end deftypevr
1053
1054@comment errno.h
1055@comment Linux???: Exchange full
1056@deftypevr Macro int EXFULL
1057@comment errno ???/54
1058@end deftypevr
1059
1060@comment errno.h
1061@comment Linux???: No anode
1062@deftypevr Macro int ENOANO
1063@comment errno ???/55
1064@end deftypevr
1065
1066@comment errno.h
1067@comment Linux???: Invalid request code
1068@deftypevr Macro int EBADRQC
1069@comment errno ???/56
1070@end deftypevr
1071
1072@comment errno.h
1073@comment Linux???: Invalid slot
1074@deftypevr Macro int EBADSLT
1075@comment errno ???/57
1076@end deftypevr
1077
1078@comment errno.h
1079@comment Linux???: File locking deadlock error
1080@deftypevr Macro int EDEADLOCK
1081@comment errno ???/58
1082@end deftypevr
1083
1084@comment errno.h
1085@comment Linux???: Bad font file format
1086@deftypevr Macro int EBFONT
1087@comment errno ???/59
1088@end deftypevr
1089
b25ae9c6
RM
1090@comment errno.h
1091@comment Linux???: Machine is not on the network
1092@deftypevr Macro int ENONET
1093@comment errno ???/64
1094@end deftypevr
1095
1096@comment errno.h
1097@comment Linux???: Package not installed
1098@deftypevr Macro int ENOPKG
1099@comment errno ???/65
1100@end deftypevr
1101
b25ae9c6
RM
1102@comment errno.h
1103@comment Linux???: Advertise error
1104@deftypevr Macro int EADV
1105@comment errno ???/68
1106@end deftypevr
1107
1108@comment errno.h
1109@comment Linux???: Srmount error
1110@deftypevr Macro int ESRMNT
1111@comment errno ???/69
1112@end deftypevr
1113
1114@comment errno.h
1115@comment Linux???: Communication error on send
1116@deftypevr Macro int ECOMM
1117@comment errno ???/70
1118@end deftypevr
1119
b25ae9c6
RM
1120@comment errno.h
1121@comment Linux???: RFS specific error
1122@deftypevr Macro int EDOTDOT
1123@comment errno ???/73
1124@end deftypevr
1125
b25ae9c6
RM
1126@comment errno.h
1127@comment Linux???: Name not unique on network
1128@deftypevr Macro int ENOTUNIQ
1129@comment errno ???/76
1130@end deftypevr
1131
1132@comment errno.h
1133@comment Linux???: File descriptor in bad state
1134@deftypevr Macro int EBADFD
1135@comment errno ???/77
1136@end deftypevr
1137
1138@comment errno.h
1139@comment Linux???: Remote address changed
1140@deftypevr Macro int EREMCHG
1141@comment errno ???/78
1142@end deftypevr
1143
1144@comment errno.h
1145@comment Linux???: Can not access a needed shared library
1146@deftypevr Macro int ELIBACC
1147@comment errno ???/79
1148@end deftypevr
1149
1150@comment errno.h
1151@comment Linux???: Accessing a corrupted shared library
1152@deftypevr Macro int ELIBBAD
1153@comment errno ???/80
1154@end deftypevr
1155
1156@comment errno.h
1157@comment Linux???: .lib section in a.out corrupted
1158@deftypevr Macro int ELIBSCN
1159@comment errno ???/81
1160@end deftypevr
1161
1162@comment errno.h
1163@comment Linux???: Attempting to link in too many shared libraries
1164@deftypevr Macro int ELIBMAX
1165@comment errno ???/82
1166@end deftypevr
1167
1168@comment errno.h
1169@comment Linux???: Cannot exec a shared library directly
1170@deftypevr Macro int ELIBEXEC
1171@comment errno ???/83
1172@end deftypevr
1173
1174@comment errno.h
1175@comment Linux???: Streams pipe error
1176@deftypevr Macro int ESTRPIPE
1177@comment errno ???/86
1178@end deftypevr
1179
1180@comment errno.h
1181@comment Linux???: Structure needs cleaning
1182@deftypevr Macro int EUCLEAN
1183@comment errno ???/117
1184@end deftypevr
1185
1186@comment errno.h
1187@comment Linux???: Not a XENIX named type file
1188@deftypevr Macro int ENOTNAM
1189@comment errno ???/118
1190@end deftypevr
1191
1192@comment errno.h
1193@comment Linux???: No XENIX semaphores available
1194@deftypevr Macro int ENAVAIL
1195@comment errno ???/119
1196@end deftypevr
1197
1198@comment errno.h
1199@comment Linux???: Is a named type file
1200@deftypevr Macro int EISNAM
1201@comment errno ???/120
1202@end deftypevr
1203
1204@comment errno.h
1205@comment Linux???: Remote I/O error
1206@deftypevr Macro int EREMOTEIO
1207@comment errno ???/121
1208@end deftypevr
28f540f4 1209
22d57dd3
UD
1210@comment errno.h
1211@comment Linux???: No medium found
1212@deftypevr Macro int ENOMEDIUM
1213@comment errno ???/???
1214@end deftypevr
1215
1216@comment errno.h
1217@comment Linux???: Wrong medium type
1218@deftypevr Macro int EMEDIUMTYPE
1219@comment errno ???/???
1220@end deftypevr
1221
28f540f4
RM
1222@node Error Messages, , Error Codes, Error Reporting
1223@section Error Messages
1224
1225The library has functions and variables designed to make it easy for
1226your program to report informative error messages in the customary
1227format about the failure of a library call. The functions
1228@code{strerror} and @code{perror} give you the standard error message
1229for a given error code; the variable
1230@w{@code{program_invocation_short_name}} gives you convenient access to the
1231name of the program that encountered the error.
1232
1233@comment string.h
f65fd747 1234@comment ISO
28f540f4
RM
1235@deftypefun {char *} strerror (int @var{errnum})
1236The @code{strerror} function maps the error code (@pxref{Checking for
1237Errors}) specified by the @var{errnum} argument to a descriptive error
1238message string. The return value is a pointer to this string.
1239
1240The value @var{errnum} normally comes from the variable @code{errno}.
1241
1242You should not modify the string returned by @code{strerror}. Also, if
1243you make subsequent calls to @code{strerror}, the string might be
1244overwritten. (But it's guaranteed that no library function ever calls
1245@code{strerror} behind your back.)
1246
1247The function @code{strerror} is declared in @file{string.h}.
1248@end deftypefun
1249
22d57dd3
UD
1250@comment string.h
1251@comment GNU
1252@deftypefun {char *} strerror_r (int @var{errnum}, char *@var{buf}, size_t @var{n})
1253The @code{strerror_r} function works like @code{strerror} but instead of
1254returning the error message in a statically allocated buffer shared by
da2d1bc5
UD
1255all threads in the process, it returns a private copy for the
1256thread. This might be either some permanent global data or a message
1257string in the user supplied buffer starting at @var{buf} with the
1258length of @var{n} bytes.
22d57dd3
UD
1259
1260At most @var{n} characters are written (including the NUL byte) so it is
1261up to the user to select the buffer large enough.
1262
1263This function should always be used in multi-threaded programs since
1264there is no way to guarantee the string returned by @code{strerror}
1265really belongs to the last call of the current thread.
1266
1267This function @code{strerror_r} is a GNU extension and it is declared in
1268@file{string.h}.
1269@end deftypefun
1270
28f540f4 1271@comment stdio.h
f65fd747 1272@comment ISO
28f540f4
RM
1273@deftypefun void perror (const char *@var{message})
1274This function prints an error message to the stream @code{stderr};
1275see @ref{Standard Streams}.
1276
1277If you call @code{perror} with a @var{message} that is either a null
b8fe19fa 1278pointer or an empty string, @code{perror} just prints the error message
28f540f4
RM
1279corresponding to @code{errno}, adding a trailing newline.
1280
1281If you supply a non-null @var{message} argument, then @code{perror}
b8fe19fa 1282prefixes its output with this string. It adds a colon and a space
28f540f4
RM
1283character to separate the @var{message} from the error string corresponding
1284to @code{errno}.
1285
1286The function @code{perror} is declared in @file{stdio.h}.
1287@end deftypefun
1288
1289@code{strerror} and @code{perror} produce the exact same message for any
1290given error code; the precise text varies from system to system. On the
1291GNU system, the messages are fairly short; there are no multi-line
1292messages or embedded newlines. Each error message begins with a capital
1293letter and does not include any terminating punctuation.
1294
1295@strong{Compatibility Note:} The @code{strerror} function is a new
f65fd747 1296feature of @w{ISO C}. Many older C systems do not support this function
28f540f4
RM
1297yet.
1298
1299@cindex program name
1300@cindex name of running program
1301Many programs that don't read input from the terminal are designed to
1302exit if any system call fails. By convention, the error message from
1303such a program should start with the program's name, sans directories.
1304You can find that name in the variable
1305@code{program_invocation_short_name}; the full file name is stored the
bc938d3d 1306variable @code{program_invocation_name}.
28f540f4
RM
1307
1308@comment errno.h
1309@comment GNU
b8fe19fa 1310@deftypevar {char *} program_invocation_name
28f540f4
RM
1311This variable's value is the name that was used to invoke the program
1312running in the current process. It is the same as @code{argv[0]}. Note
1313that this is not necessarily a useful file name; often it contains no
1314directory names. @xref{Program Arguments}.
1315@end deftypevar
1316
1317@comment errno.h
1318@comment GNU
b8fe19fa 1319@deftypevar {char *} program_invocation_short_name
28f540f4
RM
1320This variable's value is the name that was used to invoke the program
1321running in the current process, with directory names removed. (That is
1322to say, it is the same as @code{program_invocation_name} minus
1323everything up to the last slash, if any.)
1324@end deftypevar
1325
1326The library initialization code sets up both of these variables before
1327calling @code{main}.
1328
1329@strong{Portability Note:} These two variables are GNU extensions. If
1330you want your program to work with non-GNU libraries, you must save the
1331value of @code{argv[0]} in @code{main}, and then strip off the directory
1332names yourself. We added these extensions to make it possible to write
1333self-contained error-reporting subroutines that require no explicit
1334cooperation from @code{main}.
1335
1336Here is an example showing how to handle failure to open a file
1337correctly. The function @code{open_sesame} tries to open the named file
1338for reading and returns a stream if successful. The @code{fopen}
1339library function returns a null pointer if it couldn't open the file for
1340some reason. In that situation, @code{open_sesame} constructs an
1341appropriate error message using the @code{strerror} function, and
1342terminates the program. If we were going to make some other library
1343calls before passing the error code to @code{strerror}, we'd have to
1344save it in a local variable instead, because those other library
1345functions might overwrite @code{errno} in the meantime.
1346
1347@smallexample
1348#include <errno.h>
1349#include <stdio.h>
1350#include <stdlib.h>
1351#include <string.h>
1352
1353FILE *
1354open_sesame (char *name)
b8fe19fa 1355@{
28f540f4
RM
1356 FILE *stream;
1357
b8fe19fa 1358 errno = 0;
28f540f4
RM
1359 stream = fopen (name, "r");
1360 if (stream == NULL)
1361 @{
1362 fprintf (stderr, "%s: Couldn't open file %s; %s\n",
1363 program_invocation_short_name, name, strerror (errno));
1364 exit (EXIT_FAILURE);
1365 @}
1366 else
1367 return stream;
1368@}
1369@end smallexample