Blame manual/errno.texi

Packit 6c4009
@node Error Reporting, Memory, Introduction, Top
Packit 6c4009
@chapter Error Reporting
Packit 6c4009
@c %MENU% How library functions report errors
Packit 6c4009
@cindex error reporting
Packit 6c4009
@cindex reporting errors
Packit 6c4009
@cindex error codes
Packit 6c4009
@cindex status codes
Packit 6c4009
Packit 6c4009
Many functions in @theglibc{} detect and report error conditions,
Packit 6c4009
and sometimes your programs need to check for these error conditions.
Packit 6c4009
For example, when you open an input file, you should verify that the
Packit 6c4009
file was actually opened correctly, and print an error message or take
Packit 6c4009
other appropriate action if the call to the library function failed.
Packit 6c4009
Packit 6c4009
This chapter describes how the error reporting facility works.  Your
Packit 6c4009
program should include the header file @file{errno.h} to use this
Packit 6c4009
facility.
Packit 6c4009
@pindex errno.h
Packit 6c4009
Packit 6c4009
@menu
Packit 6c4009
* Checking for Errors::         How errors are reported by library functions.
Packit 6c4009
* Error Codes::                 Error code macros; all of these expand
Packit 6c4009
                                 into integer constant values.
Packit 6c4009
* Error Messages::              Mapping error codes onto error messages.
Packit 6c4009
@end menu
Packit 6c4009
Packit 6c4009
@node Checking for Errors, Error Codes,  , Error Reporting
Packit 6c4009
@section Checking for Errors
Packit 6c4009
Packit 6c4009
Most library functions return a special value to indicate that they have
Packit 6c4009
failed.  The special value is typically @code{-1}, a null pointer, or a
Packit 6c4009
constant such as @code{EOF} that is defined for that purpose.  But this
Packit 6c4009
return value tells you only that an error has occurred.  To find out
Packit 6c4009
what kind of error it was, you need to look at the error code stored in the
Packit 6c4009
variable @code{errno}.  This variable is declared in the header file
Packit 6c4009
@file{errno.h}.
Packit 6c4009
@pindex errno.h
Packit 6c4009
Packit 6c4009
@deftypevr {Variable} {volatile int} errno
Packit 6c4009
@standards{ISO, errno.h}
Packit 6c4009
The variable @code{errno} contains the system error number.  You can
Packit 6c4009
change the value of @code{errno}.
Packit 6c4009
Packit 6c4009
Since @code{errno} is declared @code{volatile}, it might be changed
Packit 6c4009
asynchronously by a signal handler; see @ref{Defining Handlers}.
Packit 6c4009
However, a properly written signal handler saves and restores the value
Packit 6c4009
of @code{errno}, so you generally do not need to worry about this
Packit 6c4009
possibility except when writing signal handlers.
Packit 6c4009
Packit 6c4009
The initial value of @code{errno} at program startup is zero.  In many
Packit 6c4009
cases, when a library function encounters an error, it will set
Packit 6c4009
@code{errno} to a non-zero value to indicate what specific error
Packit 6c4009
condition occurred.  The documentation for each function lists the
Packit 6c4009
error conditions that are possible for that function.  Not all library
Packit 6c4009
functions use this mechanism; some return an error code directly,
Packit 6c4009
instead.
Packit 6c4009
Packit 6c4009
@strong{Warning:} Many library functions may set @code{errno} to some
Packit 6c4009
meaningless non-zero value even if they did not encounter any errors,
Packit 6c4009
and even if they return error codes directly.  Therefore, it is
Packit 6c4009
usually incorrect to check @emph{whether} an error occurred by
Packit 6c4009
inspecting the value of @code{errno}.  The proper way to check for
Packit 6c4009
error is documented for each function.
Packit 6c4009
Packit 6c4009
@strong{Portability Note:} @w{ISO C} specifies @code{errno} as a
Packit 6c4009
``modifiable lvalue'' rather than as a variable, permitting it to be
Packit 6c4009
implemented as a macro.  For example, its expansion might involve a
Packit 6c4009
function call, like @w{@code{*__errno_location ()}}.  In fact, that is
Packit 6c4009
what it is
Packit 6c4009
on @gnulinuxhurdsystems{}.  @Theglibc{}, on each system, does
Packit 6c4009
whatever is right for the particular system.
Packit 6c4009
Packit 6c4009
There are a few library functions, like @code{sqrt} and @code{atan},
Packit 6c4009
that return a perfectly legitimate value in case of an error, but also
Packit 6c4009
set @code{errno}.  For these functions, if you want to check to see
Packit 6c4009
whether an error occurred, the recommended method is to set @code{errno}
Packit 6c4009
to zero before calling the function, and then check its value afterward.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@pindex errno.h
Packit 6c4009
All the error codes have symbolic names; they are macros defined in
Packit 6c4009
@file{errno.h}.  The names start with @samp{E} and an upper-case
Packit 6c4009
letter or digit; you should consider names of this form to be
Packit 6c4009
reserved names.  @xref{Reserved Names}.
Packit 6c4009
Packit 6c4009
The error code values are all positive integers and are all distinct,
Packit 6c4009
with one exception: @code{EWOULDBLOCK} and @code{EAGAIN} are the same.
Packit 6c4009
Since the values are distinct, you can use them as labels in a
Packit 6c4009
@code{switch} statement; just don't use both @code{EWOULDBLOCK} and
Packit 6c4009
@code{EAGAIN}.  Your program should not make any other assumptions about
Packit 6c4009
the specific values of these symbolic constants.
Packit 6c4009
Packit 6c4009
The value of @code{errno} doesn't necessarily have to correspond to any
Packit 6c4009
of these macros, since some library functions might return other error
Packit 6c4009
codes of their own for other situations.  The only values that are
Packit 6c4009
guaranteed to be meaningful for a particular library function are the
Packit 6c4009
ones that this manual lists for that function.
Packit 6c4009
Packit 6c4009
Except on @gnuhurdsystems{}, almost any system call can return @code{EFAULT} if
Packit 6c4009
it is given an invalid pointer as an argument.  Since this could only
Packit 6c4009
happen as a result of a bug in your program, and since it will not
Packit 6c4009
happen on @gnuhurdsystems{}, we have saved space by not mentioning
Packit 6c4009
@code{EFAULT} in the descriptions of individual functions.
Packit 6c4009
Packit 6c4009
In some Unix systems, many system calls can also return @code{EFAULT} if
Packit 6c4009
given as an argument a pointer into the stack, and the kernel for some
Packit 6c4009
obscure reason fails in its attempt to extend the stack.  If this ever
Packit 6c4009
happens, you should probably try using statically or dynamically
Packit 6c4009
allocated memory instead of stack memory on that system.
Packit 6c4009
Packit 6c4009
@node Error Codes, Error Messages, Checking for Errors, Error Reporting
Packit 6c4009
@section Error Codes
Packit 6c4009
Packit 6c4009
@pindex errno.h
Packit 6c4009
The error code macros are defined in the header file @file{errno.h}.
Packit 6c4009
All of them expand into integer constant values.  Some of these error
Packit 6c4009
codes can't occur on @gnusystems{}, but they can occur using @theglibc{}
Packit 6c4009
on other systems.
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EPERM
Packit 6c4009
@standards{POSIX.1, errno.h}
Packit 6c4009
@errno{EPERM, 1, Operation not permitted}
Packit 6c4009
Only the owner of the file (or other resource)
Packit 6c4009
or processes with special privileges can perform the operation.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ENOENT
Packit 6c4009
@standards{POSIX.1, errno.h}
Packit 6c4009
@errno{ENOENT, 2, No such file or directory}
Packit 6c4009
This is a ``file doesn't exist'' error
Packit 6c4009
for ordinary files that are referenced in contexts where they are
Packit 6c4009
expected to already exist.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ESRCH
Packit 6c4009
@standards{POSIX.1, errno.h}
Packit 6c4009
@errno{ESRCH, 3, No such process}
Packit 6c4009
No process matches the specified process ID.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EINTR
Packit 6c4009
@standards{POSIX.1, errno.h}
Packit 6c4009
@errno{EINTR, 4, Interrupted system call}
Packit 6c4009
An asynchronous signal occurred and prevented
Packit 6c4009
completion of the call.  When this happens, you should try the call
Packit 6c4009
again.
Packit 6c4009
Packit 6c4009
You can choose to have functions resume after a signal that is handled,
Packit 6c4009
rather than failing with @code{EINTR}; see @ref{Interrupted
Packit 6c4009
Primitives}.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EIO
Packit 6c4009
@standards{POSIX.1, errno.h}
Packit 6c4009
@errno{EIO, 5, Input/output error}
Packit 6c4009
Usually used for physical read or write errors.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ENXIO
Packit 6c4009
@standards{POSIX.1, errno.h}
Packit 6c4009
@errno{ENXIO, 6, No such device or address}
Packit 6c4009
The system tried to use the device
Packit 6c4009
represented by a file you specified, and it couldn't find the device.
Packit 6c4009
This can mean that the device file was installed incorrectly, or that
Packit 6c4009
the physical device is missing or not correctly attached to the
Packit 6c4009
computer.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int E2BIG
Packit 6c4009
@standards{POSIX.1, errno.h}
Packit 6c4009
@errno{E2BIG, 7, Argument list too long}
Packit 6c4009
Used when the arguments passed to a new program
Packit 6c4009
being executed with one of the @code{exec} functions (@pxref{Executing a
Packit 6c4009
File}) occupy too much memory space.  This condition never arises on
Packit 6c4009
@gnuhurdsystems{}.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ENOEXEC
Packit 6c4009
@standards{POSIX.1, errno.h}
Packit 6c4009
@errno{ENOEXEC, 8, Exec format error}
Packit 6c4009
Invalid executable file format.  This condition is detected by the
Packit 6c4009
@code{exec} functions; see @ref{Executing a File}.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EBADF
Packit 6c4009
@standards{POSIX.1, errno.h}
Packit 6c4009
@errno{EBADF, 9, Bad file descriptor}
Packit 6c4009
For example, I/O on a descriptor that has been
Packit 6c4009
closed or reading from a descriptor open only for writing (or vice
Packit 6c4009
versa).
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ECHILD
Packit 6c4009
@standards{POSIX.1, errno.h}
Packit 6c4009
@errno{ECHILD, 10, No child processes}
Packit 6c4009
This error happens on operations that are
Packit 6c4009
supposed to manipulate child processes, when there aren't any processes
Packit 6c4009
to manipulate.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EDEADLK
Packit 6c4009
@standards{POSIX.1, errno.h}
Packit 6c4009
@errno{EDEADLK, 11, Resource deadlock avoided}
Packit 6c4009
Allocating a system resource would have resulted in a
Packit 6c4009
deadlock situation.  The system does not guarantee that it will notice
Packit 6c4009
all such situations.  This error means you got lucky and the system
Packit 6c4009
noticed; it might just hang.  @xref{File Locks}, for an example.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ENOMEM
Packit 6c4009
@standards{POSIX.1, errno.h}
Packit 6c4009
@errno{ENOMEM, 12, Cannot allocate memory}
Packit 6c4009
The system cannot allocate more virtual memory
Packit 6c4009
because its capacity is full.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EACCES
Packit 6c4009
@standards{POSIX.1, errno.h}
Packit 6c4009
@errno{EACCES, 13, Permission denied}
Packit 6c4009
The file permissions do not allow the attempted operation.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EFAULT
Packit 6c4009
@standards{POSIX.1, errno.h}
Packit 6c4009
@errno{EFAULT, 14, Bad address}
Packit 6c4009
An invalid pointer was detected.
Packit 6c4009
On @gnuhurdsystems{}, this error never happens; you get a signal instead.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ENOTBLK
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{ENOTBLK, 15, Block device required}
Packit 6c4009
A file that isn't a block special file was given in a situation that
Packit 6c4009
requires one.  For example, trying to mount an ordinary file as a file
Packit 6c4009
system in Unix gives this error.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EBUSY
Packit 6c4009
@standards{POSIX.1, errno.h}
Packit 6c4009
@errno{EBUSY, 16, Device or resource busy}
Packit 6c4009
A system resource that can't be shared is already in use.
Packit 6c4009
For example, if you try to delete a file that is the root of a currently
Packit 6c4009
mounted filesystem, you get this error.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EEXIST
Packit 6c4009
@standards{POSIX.1, errno.h}
Packit 6c4009
@errno{EEXIST, 17, File exists}
Packit 6c4009
An existing file was specified in a context where it only
Packit 6c4009
makes sense to specify a new file.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EXDEV
Packit 6c4009
@standards{POSIX.1, errno.h}
Packit 6c4009
@errno{EXDEV, 18, Invalid cross-device link}
Packit 6c4009
An attempt to make an improper link across file systems was detected.
Packit 6c4009
This happens not only when you use @code{link} (@pxref{Hard Links}) but
Packit 6c4009
also when you rename a file with @code{rename} (@pxref{Renaming Files}).
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ENODEV
Packit 6c4009
@standards{POSIX.1, errno.h}
Packit 6c4009
@errno{ENODEV, 19, No such device}
Packit 6c4009
The wrong type of device was given to a function that expects a
Packit 6c4009
particular sort of device.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ENOTDIR
Packit 6c4009
@standards{POSIX.1, errno.h}
Packit 6c4009
@errno{ENOTDIR, 20, Not a directory}
Packit 6c4009
A file that isn't a directory was specified when a directory is required.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EISDIR
Packit 6c4009
@standards{POSIX.1, errno.h}
Packit 6c4009
@errno{EISDIR, 21, Is a directory}
Packit 6c4009
You cannot open a directory for writing,
Packit 6c4009
or create or remove hard links to it.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EINVAL
Packit 6c4009
@standards{POSIX.1, errno.h}
Packit 6c4009
@errno{EINVAL, 22, Invalid argument}
Packit 6c4009
This is used to indicate various kinds of problems
Packit 6c4009
with passing the wrong argument to a library function.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EMFILE
Packit 6c4009
@standards{POSIX.1, errno.h}
Packit 6c4009
@errno{EMFILE, 24, Too many open files}
Packit 6c4009
The current process has too many files open and can't open any more.
Packit 6c4009
Duplicate descriptors do count toward this limit.
Packit 6c4009
Packit 6c4009
In BSD and GNU, the number of open files is controlled by a resource
Packit 6c4009
limit that can usually be increased.  If you get this error, you might
Packit 6c4009
want to increase the @code{RLIMIT_NOFILE} limit or make it unlimited;
Packit 6c4009
@pxref{Limits on Resources}.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ENFILE
Packit 6c4009
@standards{POSIX.1, errno.h}
Packit 6c4009
@errno{ENFILE, 23, Too many open files in system}
Packit 6c4009
There are too many distinct file openings in the entire system.  Note
Packit 6c4009
that any number of linked channels count as just one file opening; see
Packit 6c4009
@ref{Linked Channels}.  This error never occurs on @gnuhurdsystems{}.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ENOTTY
Packit 6c4009
@standards{POSIX.1, errno.h}
Packit 6c4009
@errno{ENOTTY, 25, Inappropriate ioctl for device}
Packit 6c4009
Inappropriate I/O control operation, such as trying to set terminal
Packit 6c4009
modes on an ordinary file.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ETXTBSY
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{ETXTBSY, 26, Text file busy}
Packit 6c4009
An attempt to execute a file that is currently open for writing, or
Packit 6c4009
write to a file that is currently being executed.  Often using a
Packit 6c4009
debugger to run a program is considered having it open for writing and
Packit 6c4009
will cause this error.  (The name stands for ``text file busy''.)  This
Packit 6c4009
is not an error on @gnuhurdsystems{}; the text is copied as necessary.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EFBIG
Packit 6c4009
@standards{POSIX.1, errno.h}
Packit 6c4009
@errno{EFBIG, 27, File too large}
Packit 6c4009
The size of a file would be larger than allowed by the system.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ENOSPC
Packit 6c4009
@standards{POSIX.1, errno.h}
Packit 6c4009
@errno{ENOSPC, 28, No space left on device}
Packit 6c4009
Write operation on a file failed because the
Packit 6c4009
disk is full.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ESPIPE
Packit 6c4009
@standards{POSIX.1, errno.h}
Packit 6c4009
@errno{ESPIPE, 29, Illegal seek}
Packit 6c4009
Invalid seek operation (such as on a pipe).
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EROFS
Packit 6c4009
@standards{POSIX.1, errno.h}
Packit 6c4009
@errno{EROFS, 30, Read-only file system}
Packit 6c4009
An attempt was made to modify something on a read-only file system.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EMLINK
Packit 6c4009
@standards{POSIX.1, errno.h}
Packit 6c4009
@errno{EMLINK, 31, Too many links}
Packit 6c4009
The link count of a single file would become too large.
Packit 6c4009
@code{rename} can cause this error if the file being renamed already has
Packit 6c4009
as many links as it can take (@pxref{Renaming Files}).
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EPIPE
Packit 6c4009
@standards{POSIX.1, errno.h}
Packit 6c4009
@errno{EPIPE, 32, Broken pipe}
Packit 6c4009
There is no process reading from the other end of a pipe.
Packit 6c4009
Every library function that returns this error code also generates a
Packit 6c4009
@code{SIGPIPE} signal; this signal terminates the program if not handled
Packit 6c4009
or blocked.  Thus, your program will never actually see @code{EPIPE}
Packit 6c4009
unless it has handled or blocked @code{SIGPIPE}.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EDOM
Packit 6c4009
@standards{ISO, errno.h}
Packit 6c4009
@errno{EDOM, 33, Numerical argument out of domain}
Packit 6c4009
Used by mathematical functions when an argument value does
Packit 6c4009
not fall into the domain over which the function is defined.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ERANGE
Packit 6c4009
@standards{ISO, errno.h}
Packit 6c4009
@errno{ERANGE, 34, Numerical result out of range}
Packit 6c4009
Used by mathematical functions when the result value is
Packit 6c4009
not representable because of overflow or underflow.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EAGAIN
Packit 6c4009
@standards{POSIX.1, errno.h}
Packit 6c4009
@errno{EAGAIN, 35, Resource temporarily unavailable}
Packit 6c4009
The call might work if you try again
Packit 6c4009
later.  The macro @code{EWOULDBLOCK} is another name for @code{EAGAIN};
Packit 6c4009
they are always the same in @theglibc{}.
Packit 6c4009
Packit 6c4009
This error can happen in a few different situations:
Packit 6c4009
Packit 6c4009
@itemize @bullet
Packit 6c4009
@item
Packit 6c4009
An operation that would block was attempted on an object that has
Packit 6c4009
non-blocking mode selected.  Trying the same operation again will block
Packit 6c4009
until some external condition makes it possible to read, write, or
Packit 6c4009
connect (whatever the operation).  You can use @code{select} to find out
Packit 6c4009
when the operation will be possible; @pxref{Waiting for I/O}.
Packit 6c4009
Packit 6c4009
@strong{Portability Note:} In many older Unix systems, this condition
Packit 6c4009
was indicated by @code{EWOULDBLOCK}, which was a distinct error code
Packit 6c4009
different from @code{EAGAIN}.  To make your program portable, you should
Packit 6c4009
check for both codes and treat them the same.
Packit 6c4009
Packit 6c4009
@item
Packit 6c4009
A temporary resource shortage made an operation impossible.  @code{fork}
Packit 6c4009
can return this error.  It indicates that the shortage is expected to
Packit 6c4009
pass, so your program can try the call again later and it may succeed.
Packit 6c4009
It is probably a good idea to delay for a few seconds before trying it
Packit 6c4009
again, to allow time for other processes to release scarce resources.
Packit 6c4009
Such shortages are usually fairly serious and affect the whole system,
Packit 6c4009
so usually an interactive program should report the error to the user
Packit 6c4009
and return to its command loop.
Packit 6c4009
@end itemize
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EWOULDBLOCK
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{EWOULDBLOCK, EAGAIN, Operation would block}
Packit 6c4009
In @theglibc{}, this is another name for @code{EAGAIN} (above).
Packit 6c4009
The values are always the same, on every operating system.
Packit 6c4009
Packit 6c4009
C libraries in many older Unix systems have @code{EWOULDBLOCK} as a
Packit 6c4009
separate error code.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EINPROGRESS
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{EINPROGRESS, 36, Operation now in progress}
Packit 6c4009
An operation that cannot complete immediately was initiated on an object
Packit 6c4009
that has non-blocking mode selected.  Some functions that must always
Packit 6c4009
block (such as @code{connect}; @pxref{Connecting}) never return
Packit 6c4009
@code{EAGAIN}.  Instead, they return @code{EINPROGRESS} to indicate that
Packit 6c4009
the operation has begun and will take some time.  Attempts to manipulate
Packit 6c4009
the object before the call completes return @code{EALREADY}.  You can
Packit 6c4009
use the @code{select} function to find out when the pending operation
Packit 6c4009
has completed; @pxref{Waiting for I/O}.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EALREADY
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{EALREADY, 37, Operation already in progress}
Packit 6c4009
An operation is already in progress on an object that has non-blocking
Packit 6c4009
mode selected.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ENOTSOCK
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{ENOTSOCK, 38, Socket operation on non-socket}
Packit 6c4009
A file that isn't a socket was specified when a socket is required.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EMSGSIZE
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{EMSGSIZE, 40, Message too long}
Packit 6c4009
The size of a message sent on a socket was larger than the supported
Packit 6c4009
maximum size.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EPROTOTYPE
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{EPROTOTYPE, 41, Protocol wrong type for socket}
Packit 6c4009
The socket type does not support the requested communications protocol.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ENOPROTOOPT
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{ENOPROTOOPT, 42, Protocol not available}
Packit 6c4009
You specified a socket option that doesn't make sense for the
Packit 6c4009
particular protocol being used by the socket.  @xref{Socket Options}.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EPROTONOSUPPORT
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{EPROTONOSUPPORT, 43, Protocol not supported}
Packit 6c4009
The socket domain does not support the requested communications protocol
Packit 6c4009
(perhaps because the requested protocol is completely invalid).
Packit 6c4009
@xref{Creating a Socket}.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ESOCKTNOSUPPORT
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{ESOCKTNOSUPPORT, 44, Socket type not supported}
Packit 6c4009
The socket type is not supported.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EOPNOTSUPP
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{EOPNOTSUPP, 45, Operation not supported}
Packit 6c4009
The operation you requested is not supported.  Some socket functions
Packit 6c4009
don't make sense for all types of sockets, and others may not be
Packit 6c4009
implemented for all communications protocols.  On @gnuhurdsystems{}, this
Packit 6c4009
error can happen for many calls when the object does not support the
Packit 6c4009
particular operation; it is a generic indication that the server knows
Packit 6c4009
nothing to do for that call.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EPFNOSUPPORT
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{EPFNOSUPPORT, 46, Protocol family not supported}
Packit 6c4009
The socket communications protocol family you requested is not supported.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EAFNOSUPPORT
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{EAFNOSUPPORT, 47, Address family not supported by protocol}
Packit 6c4009
The address family specified for a socket is not supported; it is
Packit 6c4009
inconsistent with the protocol being used on the socket.  @xref{Sockets}.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EADDRINUSE
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{EADDRINUSE, 48, Address already in use}
Packit 6c4009
The requested socket address is already in use.  @xref{Socket Addresses}.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EADDRNOTAVAIL
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{EADDRNOTAVAIL, 49, Cannot assign requested address}
Packit 6c4009
The requested socket address is not available; for example, you tried
Packit 6c4009
to give a socket a name that doesn't match the local host name.
Packit 6c4009
@xref{Socket Addresses}.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ENETDOWN
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{ENETDOWN, 50, Network is down}
Packit 6c4009
A socket operation failed because the network was down.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ENETUNREACH
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{ENETUNREACH, 51, Network is unreachable}
Packit 6c4009
A socket operation failed because the subnet containing the remote host
Packit 6c4009
was unreachable.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ENETRESET
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{ENETRESET, 52, Network dropped connection on reset}
Packit 6c4009
A network connection was reset because the remote host crashed.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ECONNABORTED
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{ECONNABORTED, 53, Software caused connection abort}
Packit 6c4009
A network connection was aborted locally.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ECONNRESET
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{ECONNRESET, 54, Connection reset by peer}
Packit 6c4009
A network connection was closed for reasons outside the control of the
Packit 6c4009
local host, such as by the remote machine rebooting or an unrecoverable
Packit 6c4009
protocol violation.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ENOBUFS
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{ENOBUFS, 55, No buffer space available}
Packit 6c4009
The kernel's buffers for I/O operations are all in use.  In GNU, this
Packit 6c4009
error is always synonymous with @code{ENOMEM}; you may get one or the
Packit 6c4009
other from network operations.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EISCONN
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{EISCONN, 56, Transport endpoint is already connected}
Packit 6c4009
You tried to connect a socket that is already connected.
Packit 6c4009
@xref{Connecting}.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ENOTCONN
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{ENOTCONN, 57, Transport endpoint is not connected}
Packit 6c4009
The socket is not connected to anything.  You get this error when you
Packit 6c4009
try to transmit data over a socket, without first specifying a
Packit 6c4009
destination for the data.  For a connectionless socket (for datagram
Packit 6c4009
protocols, such as UDP), you get @code{EDESTADDRREQ} instead.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EDESTADDRREQ
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{EDESTADDRREQ, 39, Destination address required}
Packit 6c4009
No default destination address was set for the socket.  You get this
Packit 6c4009
error when you try to transmit data over a connectionless socket,
Packit 6c4009
without first specifying a destination for the data with @code{connect}.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ESHUTDOWN
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{ESHUTDOWN, 58, Cannot send after transport endpoint shutdown}
Packit 6c4009
The socket has already been shut down.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ETOOMANYREFS
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{ETOOMANYREFS, 59, Too many references: cannot splice}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ETIMEDOUT
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{ETIMEDOUT, 60, Connection timed out}
Packit 6c4009
A socket operation with a specified timeout received no response during
Packit 6c4009
the timeout period.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ECONNREFUSED
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{ECONNREFUSED, 61, Connection refused}
Packit 6c4009
A remote host refused to allow the network connection (typically because
Packit 6c4009
it is not running the requested service).
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ELOOP
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{ELOOP, 62, Too many levels of symbolic links}
Packit 6c4009
Too many levels of symbolic links were encountered in looking up a file name.
Packit 6c4009
This often indicates a cycle of symbolic links.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ENAMETOOLONG
Packit 6c4009
@standards{POSIX.1, errno.h}
Packit 6c4009
@errno{ENAMETOOLONG, 63, File name too long}
Packit 6c4009
Filename too long (longer than @code{PATH_MAX}; @pxref{Limits for
Packit 6c4009
Files}) or host name too long (in @code{gethostname} or
Packit 6c4009
@code{sethostname}; @pxref{Host Identification}).
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EHOSTDOWN
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{EHOSTDOWN, 64, Host is down}
Packit 6c4009
The remote host for a requested network connection is down.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EHOSTUNREACH
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{EHOSTUNREACH, 65, No route to host}
Packit 6c4009
The remote host for a requested network connection is not reachable.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ENOTEMPTY
Packit 6c4009
@standards{POSIX.1, errno.h}
Packit 6c4009
@errno{ENOTEMPTY, 66, Directory not empty}
Packit 6c4009
Directory not empty, where an empty directory was expected.  Typically,
Packit 6c4009
this error occurs when you are trying to delete a directory.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EPROCLIM
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{EPROCLIM, 67, Too many processes}
Packit 6c4009
This means that the per-user limit on new process would be exceeded by
Packit 6c4009
an attempted @code{fork}.  @xref{Limits on Resources}, for details on
Packit 6c4009
the @code{RLIMIT_NPROC} limit.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EUSERS
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{EUSERS, 68, Too many users}
Packit 6c4009
The file quota system is confused because there are too many users.
Packit 6c4009
@c This can probably happen in a GNU system when using NFS.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EDQUOT
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{EDQUOT, 69, Disk quota exceeded}
Packit 6c4009
The user's disk quota was exceeded.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ESTALE
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{ESTALE, 70, Stale file handle}
Packit 6c4009
This indicates an internal confusion in the
Packit 6c4009
file system which is due to file system rearrangements on the server host
Packit 6c4009
for NFS file systems or corruption in other file systems.
Packit 6c4009
Repairing this condition usually requires unmounting, possibly repairing
Packit 6c4009
and remounting the file system.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EREMOTE
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{EREMOTE, 71, Object is remote}
Packit 6c4009
An attempt was made to NFS-mount a remote file system with a file name that
Packit 6c4009
already specifies an NFS-mounted file.
Packit 6c4009
(This is an error on some operating systems, but we expect it to work
Packit 6c4009
properly on @gnuhurdsystems{}, making this error code impossible.)
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EBADRPC
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{EBADRPC, 72, RPC struct is bad}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ERPCMISMATCH
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{ERPCMISMATCH, 73, RPC version wrong}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EPROGUNAVAIL
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{EPROGUNAVAIL, 74, RPC program not available}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EPROGMISMATCH
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{EPROGMISMATCH, 75, RPC program version wrong}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EPROCUNAVAIL
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{EPROCUNAVAIL, 76, RPC bad procedure for program}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ENOLCK
Packit 6c4009
@standards{POSIX.1, errno.h}
Packit 6c4009
@errno{ENOLCK, 77, No locks available}
Packit 6c4009
This is used by the file locking facilities; see
Packit 6c4009
@ref{File Locks}.  This error is never generated by @gnuhurdsystems{}, but
Packit 6c4009
it can result from an operation to an NFS server running another
Packit 6c4009
operating system.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EFTYPE
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{EFTYPE, 79, Inappropriate file type or format}
Packit 6c4009
The file was the wrong type for the
Packit 6c4009
operation, or a data file had the wrong format.
Packit 6c4009
Packit 6c4009
On some systems @code{chmod} returns this error if you try to set the
Packit 6c4009
sticky bit on a non-directory file; @pxref{Setting Permissions}.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EAUTH
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{EAUTH, 80, Authentication error}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ENEEDAUTH
Packit 6c4009
@standards{BSD, errno.h}
Packit 6c4009
@errno{ENEEDAUTH, 81, Need authenticator}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ENOSYS
Packit 6c4009
@standards{POSIX.1, errno.h}
Packit 6c4009
@errno{ENOSYS, 78, Function not implemented}
Packit 6c4009
This indicates that the function called is
Packit 6c4009
not implemented at all, either in the C library itself or in the
Packit 6c4009
operating system.  When you get this error, you can be sure that this
Packit 6c4009
particular function will always fail with @code{ENOSYS} unless you
Packit 6c4009
install a new version of the C library or the operating system.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ENOTSUP
Packit 6c4009
@standards{POSIX.1, errno.h}
Packit 6c4009
@errno{ENOTSUP, 118, Not supported}
Packit 6c4009
A function returns this error when certain parameter
Packit 6c4009
values are valid, but the functionality they request is not available.
Packit 6c4009
This can mean that the function does not implement a particular command
Packit 6c4009
or option value or flag bit at all.  For functions that operate on some
Packit 6c4009
object given in a parameter, such as a file descriptor or a port, it
Packit 6c4009
might instead mean that only @emph{that specific object} (file
Packit 6c4009
descriptor, port, etc.) is unable to support the other parameters given;
Packit 6c4009
different file descriptors might support different ranges of parameter
Packit 6c4009
values.
Packit 6c4009
Packit 6c4009
If the entire function is not available at all in the implementation,
Packit 6c4009
it returns @code{ENOSYS} instead.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EILSEQ
Packit 6c4009
@standards{ISO, errno.h}
Packit 6c4009
@errno{EILSEQ, 106, Invalid or incomplete multibyte or wide character}
Packit 6c4009
While decoding a multibyte character the function came along an invalid
Packit 6c4009
or an incomplete sequence of bytes or the given wide character is invalid.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EBACKGROUND
Packit 6c4009
@standards{GNU, errno.h}
Packit 6c4009
@errno{EBACKGROUND, 100, Inappropriate operation for background process}
Packit 6c4009
On @gnuhurdsystems{}, servers supporting the @code{term} protocol return
Packit 6c4009
this error for certain operations when the caller is not in the
Packit 6c4009
foreground process group of the terminal.  Users do not usually see this
Packit 6c4009
error because functions such as @code{read} and @code{write} translate
Packit 6c4009
it into a @code{SIGTTIN} or @code{SIGTTOU} signal.  @xref{Job Control},
Packit 6c4009
for information on process groups and these signals.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EDIED
Packit 6c4009
@standards{GNU, errno.h}
Packit 6c4009
@errno{EDIED, 101, Translator died}
Packit 6c4009
On @gnuhurdsystems{}, opening a file returns this error when the file is
Packit 6c4009
translated by a program and the translator program dies while starting
Packit 6c4009
up, before it has connected to the file.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ED
Packit 6c4009
@standards{GNU, errno.h}
Packit 6c4009
@errno{ED, 102, ?}
Packit 6c4009
The experienced user will know what is wrong.
Packit 6c4009
@c This error code is a joke.  Its perror text is part of the joke.
Packit 6c4009
@c Don't change it.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EGREGIOUS
Packit 6c4009
@standards{GNU, errno.h}
Packit 6c4009
@errno{EGREGIOUS, 103, You really blew it this time}
Packit 6c4009
You did @strong{what}?
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EIEIO
Packit 6c4009
@standards{GNU, errno.h}
Packit 6c4009
@errno{EIEIO, 104, Computer bought the farm}
Packit 6c4009
Go home and have a glass of warm, dairy-fresh milk.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EGRATUITOUS
Packit 6c4009
@standards{GNU, errno.h}
Packit 6c4009
@errno{EGRATUITOUS, 105, Gratuitous error}
Packit 6c4009
This error code has no purpose.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EBADMSG
Packit 6c4009
@standards{XOPEN, errno.h}
Packit 6c4009
@errno{EBADMSG, 107, Bad message}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EIDRM
Packit 6c4009
@standards{XOPEN, errno.h}
Packit 6c4009
@errno{EIDRM, 108, Identifier removed}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EMULTIHOP
Packit 6c4009
@standards{XOPEN, errno.h}
Packit 6c4009
@errno{EMULTIHOP, 109, Multihop attempted}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ENODATA
Packit 6c4009
@standards{XOPEN, errno.h}
Packit 6c4009
@errno{ENODATA, 110, No data available}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ENOLINK
Packit 6c4009
@standards{XOPEN, errno.h}
Packit 6c4009
@errno{ENOLINK, 111, Link has been severed}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ENOMSG
Packit 6c4009
@standards{XOPEN, errno.h}
Packit 6c4009
@errno{ENOMSG, 112, No message of desired type}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ENOSR
Packit 6c4009
@standards{XOPEN, errno.h}
Packit 6c4009
@errno{ENOSR, 113, Out of streams resources}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ENOSTR
Packit 6c4009
@standards{XOPEN, errno.h}
Packit 6c4009
@errno{ENOSTR, 114, Device not a stream}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EOVERFLOW
Packit 6c4009
@standards{XOPEN, errno.h}
Packit 6c4009
@errno{EOVERFLOW, 115, Value too large for defined data type}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EPROTO
Packit 6c4009
@standards{XOPEN, errno.h}
Packit 6c4009
@errno{EPROTO, 116, Protocol error}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ETIME
Packit 6c4009
@standards{XOPEN, errno.h}
Packit 6c4009
@errno{ETIME, 117, Timer expired}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ECANCELED
Packit 6c4009
@standards{POSIX.1, errno.h}
Packit 6c4009
@errno{ECANCELED, 119, Operation canceled}
Packit 6c4009
An asynchronous operation was canceled before it
Packit 6c4009
completed.  @xref{Asynchronous I/O}.  When you call @code{aio_cancel},
Packit 6c4009
the normal result is for the operations affected to complete with this
Packit 6c4009
error; @pxref{Cancel AIO Operations}.
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EOWNERDEAD
Packit 6c4009
@standards{GNU, errno.h}
Packit 6c4009
@errno{EOWNERDEAD, 120, Owner died}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ENOTRECOVERABLE
Packit 6c4009
@standards{GNU, errno.h}
Packit 6c4009
@errno{ENOTRECOVERABLE, 121, State not recoverable}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
Packit 6c4009
@emph{The following error codes are defined by the Linux/i386 kernel.
Packit 6c4009
They are not yet documented.}
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ERESTART
Packit 6c4009
@standards{Linux???, errno.h}
Packit 6c4009
@errno{ERESTART, ???/85, Interrupted system call should be restarted}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ECHRNG
Packit 6c4009
@standards{Linux???, errno.h}
Packit 6c4009
@errno{ECHRNG, ???/44, Channel number out of range}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EL2NSYNC
Packit 6c4009
@standards{Obsolete, errno.h}
Packit 6c4009
@errno{EL2NSYNC, ???/45, Level 2 not synchronized}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EL3HLT
Packit 6c4009
@standards{Obsolete, errno.h}
Packit 6c4009
@errno{EL3HLT, ???/46, Level 3 halted}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EL3RST
Packit 6c4009
@standards{Obsolete, errno.h}
Packit 6c4009
@errno{EL3RST, ???/47, Level 3 reset}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ELNRNG
Packit 6c4009
@standards{Linux???, errno.h}
Packit 6c4009
@errno{ELNRNG, ???/48, Link number out of range}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EUNATCH
Packit 6c4009
@standards{Linux???, errno.h}
Packit 6c4009
@errno{EUNATCH, ???/49, Protocol driver not attached}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ENOCSI
Packit 6c4009
@standards{Linux???, errno.h}
Packit 6c4009
@errno{ENOCSI, ???/50, No CSI structure available}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EL2HLT
Packit 6c4009
@standards{Obsolete, errno.h}
Packit 6c4009
@errno{EL2HLT, ???/51, Level 2 halted}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EBADE
Packit 6c4009
@standards{Linux???, errno.h}
Packit 6c4009
@errno{EBADE, ???/52, Invalid exchange}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EBADR
Packit 6c4009
@standards{Linux???, errno.h}
Packit 6c4009
@errno{EBADR, ???/53, Invalid request descriptor}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EXFULL
Packit 6c4009
@standards{Linux???, errno.h}
Packit 6c4009
@errno{EXFULL, ???/54, Exchange full}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ENOANO
Packit 6c4009
@standards{Linux???, errno.h}
Packit 6c4009
@errno{ENOANO, ???/55, No anode}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EBADRQC
Packit 6c4009
@standards{Linux???, errno.h}
Packit 6c4009
@errno{EBADRQC, ???/56, Invalid request code}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EBADSLT
Packit 6c4009
@standards{Linux???, errno.h}
Packit 6c4009
@errno{EBADSLT, ???/57, Invalid slot}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EDEADLOCK
Packit 6c4009
@standards{Linux???, errno.h}
Packit 6c4009
@errno{EDEADLOCK, ???/58, File locking deadlock error}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EBFONT
Packit 6c4009
@standards{Linux???, errno.h}
Packit 6c4009
@errno{EBFONT, ???/59, Bad font file format}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ENONET
Packit 6c4009
@standards{Linux???, errno.h}
Packit 6c4009
@errno{ENONET, ???/64, Machine is not on the network}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ENOPKG
Packit 6c4009
@standards{Linux???, errno.h}
Packit 6c4009
@errno{ENOPKG, ???/65, Package not installed}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EADV
Packit 6c4009
@standards{Linux???, errno.h}
Packit 6c4009
@errno{EADV, ???/68, Advertise error}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ESRMNT
Packit 6c4009
@standards{Linux???, errno.h}
Packit 6c4009
@errno{ESRMNT, ???/69, Srmount error}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ECOMM
Packit 6c4009
@standards{Linux???, errno.h}
Packit 6c4009
@errno{ECOMM, ???/70, Communication error on send}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EDOTDOT
Packit 6c4009
@standards{Linux???, errno.h}
Packit 6c4009
@errno{EDOTDOT, ???/73, RFS specific error}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ENOTUNIQ
Packit 6c4009
@standards{Linux???, errno.h}
Packit 6c4009
@errno{ENOTUNIQ, ???/76, Name not unique on network}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EBADFD
Packit 6c4009
@standards{Linux???, errno.h}
Packit 6c4009
@errno{EBADFD, ???/77, File descriptor in bad state}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EREMCHG
Packit 6c4009
@standards{Linux???, errno.h}
Packit 6c4009
@errno{EREMCHG, ???/78, Remote address changed}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ELIBACC
Packit 6c4009
@standards{Linux???, errno.h}
Packit 6c4009
@errno{ELIBACC, ???/79, Can not access a needed shared library}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ELIBBAD
Packit 6c4009
@standards{Linux???, errno.h}
Packit 6c4009
@errno{ELIBBAD, ???/80, Accessing a corrupted shared library}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ELIBSCN
Packit 6c4009
@standards{Linux???, errno.h}
Packit 6c4009
@errno{ELIBSCN, ???/81, .lib section in a.out corrupted}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ELIBMAX
Packit 6c4009
@standards{Linux???, errno.h}
Packit 6c4009
@errno{ELIBMAX, ???/82, Attempting to link in too many shared libraries}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ELIBEXEC
Packit 6c4009
@standards{Linux???, errno.h}
Packit 6c4009
@errno{ELIBEXEC, ???/83, Cannot exec a shared library directly}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ESTRPIPE
Packit 6c4009
@standards{Linux???, errno.h}
Packit 6c4009
@errno{ESTRPIPE, ???/86, Streams pipe error}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EUCLEAN
Packit 6c4009
@standards{Linux???, errno.h}
Packit 6c4009
@errno{EUCLEAN, ???/117, Structure needs cleaning}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ENOTNAM
Packit 6c4009
@standards{Linux???, errno.h}
Packit 6c4009
@errno{ENOTNAM, ???/118, Not a XENIX named type file}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ENAVAIL
Packit 6c4009
@standards{Linux???, errno.h}
Packit 6c4009
@errno{ENAVAIL, ???/119, No XENIX semaphores available}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EISNAM
Packit 6c4009
@standards{Linux???, errno.h}
Packit 6c4009
@errno{EISNAM, ???/120, Is a named type file}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EREMOTEIO
Packit 6c4009
@standards{Linux???, errno.h}
Packit 6c4009
@errno{EREMOTEIO, ???/121, Remote I/O error}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ENOMEDIUM
Packit 6c4009
@standards{Linux???, errno.h}
Packit 6c4009
@errno{ENOMEDIUM, ???/???, No medium found}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EMEDIUMTYPE
Packit 6c4009
@standards{Linux???, errno.h}
Packit 6c4009
@errno{EMEDIUMTYPE, ???/???, Wrong medium type}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ENOKEY
Packit 6c4009
@standards{Linux, errno.h}
Packit 6c4009
@errno{ENOKEY, ???/???, Required key not available}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EKEYEXPIRED
Packit 6c4009
@standards{Linux, errno.h}
Packit 6c4009
@errno{EKEYEXPIRED, ???/???, Key has expired}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EKEYREVOKED
Packit 6c4009
@standards{Linux, errno.h}
Packit 6c4009
@errno{EKEYREVOKED, ???/???, Key has been revoked}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EKEYREJECTED
Packit 6c4009
@standards{Linux, errno.h}
Packit 6c4009
@errno{EKEYREJECTED, ???/???, Key was rejected by service}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int ERFKILL
Packit 6c4009
@standards{Linux, errno.h}
Packit 6c4009
@errno{ERFKILL, ???/???, Operation not possible due to RF-kill}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@deftypevr Macro int EHWPOISON
Packit 6c4009
@standards{Linux, errno.h}
Packit 6c4009
@errno{EHWPOISON, ???/???, Memory page has hardware error}
Packit 6c4009
@end deftypevr
Packit 6c4009
Packit 6c4009
@node Error Messages,  , Error Codes, Error Reporting
Packit 6c4009
@section Error Messages
Packit 6c4009
Packit 6c4009
The library has functions and variables designed to make it easy for
Packit 6c4009
your program to report informative error messages in the customary
Packit 6c4009
format about the failure of a library call.  The functions
Packit 6c4009
@code{strerror} and @code{perror} give you the standard error message
Packit 6c4009
for a given error code; the variable
Packit 6c4009
@w{@code{program_invocation_short_name}} gives you convenient access to the
Packit 6c4009
name of the program that encountered the error.
Packit 6c4009
Packit 6c4009
@deftypefun {char *} strerror (int @var{errnum})
Packit 6c4009
@standards{ISO, string.h}
Packit 6c4009
@safety{@prelim{}@mtunsafe{@mtasurace{:strerror}}@asunsafe{@ascuheap{} @ascuintl{}}@acunsafe{@acsmem{}}}
Packit 6c4009
@c Calls strerror_r with a static buffer allocated with malloc on the
Packit 6c4009
@c first use.
Packit 6c4009
The @code{strerror} function maps the error code (@pxref{Checking for
Packit 6c4009
Errors}) specified by the @var{errnum} argument to a descriptive error
Packit 6c4009
message string.  The return value is a pointer to this string.
Packit 6c4009
Packit 6c4009
The value @var{errnum} normally comes from the variable @code{errno}.
Packit 6c4009
Packit 6c4009
You should not modify the string returned by @code{strerror}.  Also, if
Packit 6c4009
you make subsequent calls to @code{strerror}, the string might be
Packit 6c4009
overwritten.  (But it's guaranteed that no library function ever calls
Packit 6c4009
@code{strerror} behind your back.)
Packit 6c4009
Packit 6c4009
The function @code{strerror} is declared in @file{string.h}.
Packit 6c4009
@end deftypefun
Packit 6c4009
Packit 6c4009
@deftypefun {char *} strerror_r (int @var{errnum}, char *@var{buf}, size_t @var{n})
Packit 6c4009
@standards{GNU, string.h}
Packit 6c4009
@safety{@prelim{}@mtsafe{}@asunsafe{@ascuintl{}}@acunsafe{}}
Packit 6c4009
The @code{strerror_r} function works like @code{strerror} but instead of
Packit 6c4009
returning the error message in a statically allocated buffer shared by
Packit 6c4009
all threads in the process, it returns a private copy for the
Packit 6c4009
thread.  This might be either some permanent global data or a message
Packit 6c4009
string in the user supplied buffer starting at @var{buf} with the
Packit 6c4009
length of @var{n} bytes.
Packit 6c4009
Packit 6c4009
At most @var{n} characters are written (including the NUL byte) so it is
Packit 6c4009
up to the user to select a buffer large enough.
Packit 6c4009
Packit 6c4009
This function should always be used in multi-threaded programs since
Packit 6c4009
there is no way to guarantee the string returned by @code{strerror}
Packit 6c4009
really belongs to the last call of the current thread.
Packit 6c4009
Packit 6c4009
The function @code{strerror_r} is a GNU extension and it is declared in
Packit 6c4009
@file{string.h}.
Packit 6c4009
@end deftypefun
Packit 6c4009
Packit 6c4009
@deftypefun void perror (const char *@var{message})
Packit 6c4009
@standards{ISO, stdio.h}
Packit 6c4009
@safety{@prelim{}@mtsafe{@mtasurace{:stderr}}@asunsafe{@asucorrupt{} @ascuintl{} @ascuheap{} @asulock{}}@acunsafe{@acucorrupt{} @aculock{} @acsmem{} @acsfd{}}}
Packit 6c4009
@c Besides strerror_r's and some of fprintf's issues, if stderr is not
Packit 6c4009
@c oriented yet, create a new stream with a dup of stderr's fd and write
Packit 6c4009
@c to that instead of stderr, to avoid orienting it.
Packit 6c4009
This function prints an error message to the stream @code{stderr};
Packit 6c4009
see @ref{Standard Streams}.  The orientation of @code{stderr} is not
Packit 6c4009
changed.
Packit 6c4009
Packit 6c4009
If you call @code{perror} with a @var{message} that is either a null
Packit 6c4009
pointer or an empty string, @code{perror} just prints the error message
Packit 6c4009
corresponding to @code{errno}, adding a trailing newline.
Packit 6c4009
Packit 6c4009
If you supply a non-null @var{message} argument, then @code{perror}
Packit 6c4009
prefixes its output with this string.  It adds a colon and a space
Packit 6c4009
character to separate the @var{message} from the error string corresponding
Packit 6c4009
to @code{errno}.
Packit 6c4009
Packit 6c4009
The function @code{perror} is declared in @file{stdio.h}.
Packit 6c4009
@end deftypefun
Packit 6c4009
Packit 6c4009
@code{strerror} and @code{perror} produce the exact same message for any
Packit 6c4009
given error code; the precise text varies from system to system.  With
Packit 6c4009
@theglibc{}, the messages are fairly short; there are no multi-line
Packit 6c4009
messages or embedded newlines.  Each error message begins with a capital
Packit 6c4009
letter and does not include any terminating punctuation.
Packit 6c4009
Packit 6c4009
@cindex program name
Packit 6c4009
@cindex name of running program
Packit 6c4009
Many programs that don't read input from the terminal are designed to
Packit 6c4009
exit if any system call fails.  By convention, the error message from
Packit 6c4009
such a program should start with the program's name, sans directories.
Packit 6c4009
You can find that name in the variable
Packit 6c4009
@code{program_invocation_short_name}; the full file name is stored the
Packit 6c4009
variable @code{program_invocation_name}.
Packit 6c4009
Packit 6c4009
@deftypevar {char *} program_invocation_name
Packit 6c4009
@standards{GNU, errno.h}
Packit 6c4009
This variable's value is the name that was used to invoke the program
Packit 6c4009
running in the current process.  It is the same as @code{argv[0]}.  Note
Packit 6c4009
that this is not necessarily a useful file name; often it contains no
Packit 6c4009
directory names.  @xref{Program Arguments}.
Packit 6c4009
Packit 6c4009
This variable is a GNU extension and is declared in @file{errno.h}.
Packit 6c4009
@end deftypevar
Packit 6c4009
Packit 6c4009
@deftypevar {char *} program_invocation_short_name
Packit 6c4009
@standards{GNU, errno.h}
Packit 6c4009
This variable's value is the name that was used to invoke the program
Packit 6c4009
running in the current process, with directory names removed.  (That is
Packit 6c4009
to say, it is the same as @code{program_invocation_name} minus
Packit 6c4009
everything up to the last slash, if any.)
Packit 6c4009
Packit 6c4009
This variable is a GNU extension and is declared in @file{errno.h}.
Packit 6c4009
@end deftypevar
Packit 6c4009
Packit 6c4009
The library initialization code sets up both of these variables before
Packit 6c4009
calling @code{main}.
Packit 6c4009
Packit 6c4009
@strong{Portability Note:} If you want your program to work with
Packit 6c4009
non-GNU libraries, you must save the value of @code{argv[0]} in
Packit 6c4009
@code{main}, and then strip off the directory names yourself.  We
Packit 6c4009
added these extensions to make it possible to write self-contained
Packit 6c4009
error-reporting subroutines that require no explicit cooperation from
Packit 6c4009
@code{main}.
Packit 6c4009
Packit 6c4009
Here is an example showing how to handle failure to open a file
Packit 6c4009
correctly.  The function @code{open_sesame} tries to open the named file
Packit 6c4009
for reading and returns a stream if successful.  The @code{fopen}
Packit 6c4009
library function returns a null pointer if it couldn't open the file for
Packit 6c4009
some reason.  In that situation, @code{open_sesame} constructs an
Packit 6c4009
appropriate error message using the @code{strerror} function, and
Packit 6c4009
terminates the program.  If we were going to make some other library
Packit 6c4009
calls before passing the error code to @code{strerror}, we'd have to
Packit 6c4009
save it in a local variable instead, because those other library
Packit 6c4009
functions might overwrite @code{errno} in the meantime.
Packit 6c4009
Packit 6c4009
@smallexample
Packit 6c4009
#define _GNU_SOURCE
Packit 6c4009
Packit 6c4009
#include <errno.h>
Packit 6c4009
#include <stdio.h>
Packit 6c4009
#include <stdlib.h>
Packit 6c4009
#include <string.h>
Packit 6c4009
Packit 6c4009
FILE *
Packit 6c4009
open_sesame (char *name)
Packit 6c4009
@{
Packit 6c4009
  FILE *stream;
Packit 6c4009
Packit 6c4009
  errno = 0;
Packit 6c4009
  stream = fopen (name, "r");
Packit 6c4009
  if (stream == NULL)
Packit 6c4009
    @{
Packit 6c4009
      fprintf (stderr, "%s: Couldn't open file %s; %s\n",
Packit 6c4009
               program_invocation_short_name, name, strerror (errno));
Packit 6c4009
      exit (EXIT_FAILURE);
Packit 6c4009
    @}
Packit 6c4009
  else
Packit 6c4009
    return stream;
Packit 6c4009
@}
Packit 6c4009
@end smallexample
Packit 6c4009
Packit 6c4009
Using @code{perror} has the advantage that the function is portable and
Packit 6c4009
available on all systems implementing @w{ISO C}.  But often the text
Packit 6c4009
@code{perror} generates is not what is wanted and there is no way to
Packit 6c4009
extend or change what @code{perror} does.  The GNU coding standard, for
Packit 6c4009
instance, requires error messages to be preceded by the program name and
Packit 6c4009
programs which read some input files should provide information
Packit 6c4009
about the input file name and the line number in case an error is
Packit 6c4009
encountered while reading the file.  For these occasions there are two
Packit 6c4009
functions available which are widely used throughout the GNU project.
Packit 6c4009
These functions are declared in @file{error.h}.
Packit 6c4009
Packit 6c4009
@deftypefun void error (int @var{status}, int @var{errnum}, const char *@var{format}, @dots{})
Packit 6c4009
@standards{GNU, error.h}
Packit 6c4009
@safety{@prelim{}@mtsafe{@mtslocale{}}@asunsafe{@asucorrupt{} @asuheap{} @asuintl{}}@acsafe{}}
Packit 6c4009
@c Cancellation is disabled throughout the execution.  It flushes stdout
Packit 6c4009
@c and then holds a lock on stderr while printing the program name and
Packit 6c4009
@c then running error_tail.  The non-wide case just runs vfprintf; the
Packit 6c4009
@c wide case converts the message to an alloca/malloc-allocated buffer
Packit 6c4009
@c with mbsrtowcs, then prints it with vfwprintf.  Afterwards,
Packit 6c4009
@c print_errno_message calls strerror_r and fxprintf.
Packit 6c4009
The @code{error} function can be used to report general problems during
Packit 6c4009
program execution.  The @var{format} argument is a format string just
Packit 6c4009
like those given to the @code{printf} family of functions.  The
Packit 6c4009
arguments required for the format can follow the @var{format} parameter.
Packit 6c4009
Just like @code{perror}, @code{error} also can report an error code in
Packit 6c4009
textual form.  But unlike @code{perror} the error value is explicitly
Packit 6c4009
passed to the function in the @var{errnum} parameter.  This eliminates
Packit 6c4009
the problem mentioned above that the error reporting function must be
Packit 6c4009
called immediately after the function causing the error since otherwise
Packit 6c4009
@code{errno} might have a different value.
Packit 6c4009
Packit 6c4009
@code{error} prints first the program name.  If the application
Packit 6c4009
defined a global variable @code{error_print_progname} and points it to a
Packit 6c4009
function this function will be called to print the program name.
Packit 6c4009
Otherwise the string from the global variable @code{program_name} is
Packit 6c4009
used.  The program name is followed by a colon and a space which in turn
Packit 6c4009
is followed by the output produced by the format string.  If the
Packit 6c4009
@var{errnum} parameter is non-zero the format string output is followed
Packit 6c4009
by a colon and a space, followed by the error message for the error code
Packit 6c4009
@var{errnum}.  In any case is the output terminated with a newline.
Packit 6c4009
Packit 6c4009
The output is directed to the @code{stderr} stream.  If the
Packit 6c4009
@code{stderr} wasn't oriented before the call it will be narrow-oriented
Packit 6c4009
afterwards.
Packit 6c4009
Packit 6c4009
The function will return unless the @var{status} parameter has a
Packit 6c4009
non-zero value.  In this case the function will call @code{exit} with
Packit 6c4009
the @var{status} value for its parameter and therefore never return.  If
Packit 6c4009
@code{error} returns, the global variable @code{error_message_count} is
Packit 6c4009
incremented by one to keep track of the number of errors reported.
Packit 6c4009
@end deftypefun
Packit 6c4009
Packit 6c4009
@deftypefun void error_at_line (int @var{status}, int @var{errnum}, const char *@var{fname}, unsigned int @var{lineno}, const char *@var{format}, @dots{})
Packit 6c4009
@standards{GNU, error.h}
Packit 6c4009
@safety{@prelim{}@mtunsafe{@mtasurace{:error_at_line/error_one_per_line} @mtslocale{}}@asunsafe{@asucorrupt{} @asuheap{} @asuintl{}}@acunsafe{@acucorrupt{/error_one_per_line}}}
Packit 6c4009
@c The error_one_per_line variable is accessed (without any form of
Packit 6c4009
@c synchronization, but since it's an int used once, it should be safe
Packit 6c4009
@c enough) and, if this mode is enabled, static variables used to hold
Packit 6c4009
@c the last printed file name and line number are accessed and modified
Packit 6c4009
@c without synchronization; the update is not atomic and it occurs
Packit 6c4009
@c before disabling cancellation, so it can be interrupted after only
Packit 6c4009
@c one of the two variables is modified.  After that, it's very much
Packit 6c4009
@c like error.
Packit 6c4009
Packit 6c4009
The @code{error_at_line} function is very similar to the @code{error}
Packit 6c4009
function.  The only differences are the additional parameters @var{fname}
Packit 6c4009
and @var{lineno}.  The handling of the other parameters is identical to
Packit 6c4009
that of @code{error} except that between the program name and the string
Packit 6c4009
generated by the format string additional text is inserted.
Packit 6c4009
Packit 6c4009
Directly following the program name a colon, followed by the file name
Packit 6c4009
pointed to by @var{fname}, another colon, and the value of @var{lineno} is
Packit 6c4009
printed.
Packit 6c4009
Packit 6c4009
This additional output of course is meant to be used to locate an error
Packit 6c4009
in an input file (like a programming language source code file etc).
Packit 6c4009
Packit 6c4009
If the global variable @code{error_one_per_line} is set to a non-zero
Packit 6c4009
value @code{error_at_line} will avoid printing consecutive messages for
Packit 6c4009
the same file and line.  Repetition which are not directly following
Packit 6c4009
each other are not caught.
Packit 6c4009
Packit 6c4009
Just like @code{error} this function only returns if @var{status} is
Packit 6c4009
zero.  Otherwise @code{exit} is called with the non-zero value.  If
Packit 6c4009
@code{error} returns, the global variable @code{error_message_count} is
Packit 6c4009
incremented by one to keep track of the number of errors reported.
Packit 6c4009
@end deftypefun
Packit 6c4009
Packit 6c4009
As mentioned above, the @code{error} and @code{error_at_line} functions
Packit 6c4009
can be customized by defining a variable named
Packit 6c4009
@code{error_print_progname}.
Packit 6c4009
Packit 6c4009
@deftypevar {void (*error_print_progname)} (void)
Packit 6c4009
@standards{GNU, error.h}
Packit 6c4009
If the @code{error_print_progname} variable is defined to a non-zero
Packit 6c4009
value the function pointed to is called by @code{error} or
Packit 6c4009
@code{error_at_line}.  It is expected to print the program name or do
Packit 6c4009
something similarly useful.
Packit 6c4009
Packit 6c4009
The function is expected to print to the @code{stderr} stream and
Packit 6c4009
must be able to handle whatever orientation the stream has.
Packit 6c4009
Packit 6c4009
The variable is global and shared by all threads.
Packit 6c4009
@end deftypevar
Packit 6c4009
Packit 6c4009
@deftypevar {unsigned int} error_message_count
Packit 6c4009
@standards{GNU, error.h}
Packit 6c4009
The @code{error_message_count} variable is incremented whenever one of
Packit 6c4009
the functions @code{error} or @code{error_at_line} returns.  The
Packit 6c4009
variable is global and shared by all threads.
Packit 6c4009
@end deftypevar
Packit 6c4009
Packit 6c4009
@deftypevar int error_one_per_line
Packit 6c4009
@standards{GNU, error.h}
Packit 6c4009
The @code{error_one_per_line} variable influences only
Packit 6c4009
@code{error_at_line}.  Normally the @code{error_at_line} function
Packit 6c4009
creates output for every invocation.  If @code{error_one_per_line} is
Packit 6c4009
set to a non-zero value @code{error_at_line} keeps track of the last
Packit 6c4009
file name and line number for which an error was reported and avoids
Packit 6c4009
directly following messages for the same file and line.  This variable
Packit 6c4009
is global and shared by all threads.
Packit 6c4009
@end deftypevar
Packit 6c4009
Packit 6c4009
@noindent
Packit 6c4009
A program which read some input file and reports errors in it could look
Packit 6c4009
like this:
Packit 6c4009
Packit 6c4009
@smallexample
Packit 6c4009
@{
Packit 6c4009
  char *line = NULL;
Packit 6c4009
  size_t len = 0;
Packit 6c4009
  unsigned int lineno = 0;
Packit 6c4009
Packit 6c4009
  error_message_count = 0;
Packit 6c4009
  while (! feof_unlocked (fp))
Packit 6c4009
    @{
Packit 6c4009
      ssize_t n = getline (&line, &len, fp);
Packit 6c4009
      if (n <= 0)
Packit 6c4009
        /* @r{End of file or error.}  */
Packit 6c4009
        break;
Packit 6c4009
      ++lineno;
Packit 6c4009
Packit 6c4009
      /* @r{Process the line.}  */
Packit 6c4009
      @dots{}
Packit 6c4009
Packit 6c4009
      if (@r{Detect error in line})
Packit 6c4009
        error_at_line (0, errval, filename, lineno,
Packit 6c4009
                       "some error text %s", some_variable);
Packit 6c4009
    @}
Packit 6c4009
Packit 6c4009
  if (error_message_count != 0)
Packit 6c4009
    error (EXIT_FAILURE, 0, "%u errors found", error_message_count);
Packit 6c4009
@}
Packit 6c4009
@end smallexample
Packit 6c4009
Packit 6c4009
@code{error} and @code{error_at_line} are clearly the functions of
Packit 6c4009
choice and enable the programmer to write applications which follow the
Packit 6c4009
GNU coding standard.  @Theglibc{} additionally contains functions which
Packit 6c4009
are used in BSD for the same purpose.  These functions are declared in
Packit 6c4009
@file{err.h}.  It is generally advised to not use these functions.  They
Packit 6c4009
are included only for compatibility.
Packit 6c4009
Packit 6c4009
@deftypefun void warn (const char *@var{format}, @dots{})
Packit 6c4009
@standards{BSD, err.h}
Packit 6c4009
@safety{@prelim{}@mtsafe{@mtslocale{}}@asunsafe{@asucorrupt{} @ascuheap{} @ascuintl{}}@acunsafe{@acucorrupt{} @aculock{} @acsmem{}}}
Packit 6c4009
@c Just calls vwarn with the va_list.
Packit 6c4009
The @code{warn} function is roughly equivalent to a call like
Packit 6c4009
@smallexample
Packit 6c4009
  error (0, errno, format, @r{the parameters})
Packit 6c4009
@end smallexample
Packit 6c4009
@noindent
Packit 6c4009
except that the global variables @code{error} respects and modifies
Packit 6c4009
are not used.
Packit 6c4009
@end deftypefun
Packit 6c4009
Packit 6c4009
@deftypefun void vwarn (const char *@var{format}, va_list @var{ap})
Packit 6c4009
@standards{BSD, err.h}
Packit 6c4009
@safety{@prelim{}@mtsafe{@mtslocale{}}@asunsafe{@asucorrupt{} @ascuheap{} @ascuintl{}}@acunsafe{@acucorrupt{} @aculock{} @acsmem{}}}
Packit 6c4009
@c While holding stderr's recursive lock, it prints the programname, the
Packit 6c4009
@c given message, and the error string with fw?printf's %m.  When the
Packit 6c4009
@c stream is wide, convert_and_print converts the format string to an
Packit 6c4009
@c alloca/malloc-created buffer using mbsrtowcs and then calls fwprintf.
Packit 6c4009
The @code{vwarn} function is just like @code{warn} except that the
Packit 6c4009
parameters for the handling of the format string @var{format} are passed
Packit 6c4009
in as a value of type @code{va_list}.
Packit 6c4009
@end deftypefun
Packit 6c4009
Packit 6c4009
@deftypefun void warnx (const char *@var{format}, @dots{})
Packit 6c4009
@standards{BSD, err.h}
Packit 6c4009
@safety{@prelim{}@mtsafe{@mtslocale{}}@asunsafe{@asucorrupt{} @ascuheap{}}@acunsafe{@acucorrupt{} @aculock{} @acsmem{}}}
Packit 6c4009
@c Same as warn, but without the strerror translation issues.
Packit 6c4009
The @code{warnx} function is roughly equivalent to a call like
Packit 6c4009
@smallexample
Packit 6c4009
  error (0, 0, format, @r{the parameters})
Packit 6c4009
@end smallexample
Packit 6c4009
@noindent
Packit 6c4009
except that the global variables @code{error} respects and modifies
Packit 6c4009
are not used.  The difference to @code{warn} is that no error number
Packit 6c4009
string is printed.
Packit 6c4009
@end deftypefun
Packit 6c4009
Packit 6c4009
@deftypefun void vwarnx (const char *@var{format}, va_list @var{ap})
Packit 6c4009
@standards{BSD, err.h}
Packit 6c4009
@safety{@prelim{}@mtsafe{@mtslocale{}}@asunsafe{@asucorrupt{} @ascuheap{}}@acunsafe{@acucorrupt{} @aculock{} @acsmem{}}}
Packit 6c4009
@c Same as vwarn, but without the strerror translation issues.
Packit 6c4009
The @code{vwarnx} function is just like @code{warnx} except that the
Packit 6c4009
parameters for the handling of the format string @var{format} are passed
Packit 6c4009
in as a value of type @code{va_list}.
Packit 6c4009
@end deftypefun
Packit 6c4009
Packit 6c4009
@deftypefun void err (int @var{status}, const char *@var{format}, @dots{})
Packit 6c4009
@standards{BSD, err.h}
Packit 6c4009
@safety{@prelim{}@mtsafe{@mtslocale{}}@asunsafe{@asucorrupt{} @ascuheap{} @ascuintl{}}@acunsafe{@acucorrupt{} @aculock{} @acsmem{}}}
Packit 6c4009
@c Same as warn followed by exit.
Packit 6c4009
The @code{err} function is roughly equivalent to a call like
Packit 6c4009
@smallexample
Packit 6c4009
  error (status, errno, format, @r{the parameters})
Packit 6c4009
@end smallexample
Packit 6c4009
@noindent
Packit 6c4009
except that the global variables @code{error} respects and modifies
Packit 6c4009
are not used and that the program is exited even if @var{status} is zero.
Packit 6c4009
@end deftypefun
Packit 6c4009
Packit 6c4009
@deftypefun void verr (int @var{status}, const char *@var{format}, va_list @var{ap})
Packit 6c4009
@standards{BSD, err.h}
Packit 6c4009
@safety{@prelim{}@mtsafe{@mtslocale{}}@asunsafe{@asucorrupt{} @ascuheap{} @ascuintl{}}@acunsafe{@acucorrupt{} @aculock{} @acsmem{}}}
Packit 6c4009
@c Same as vwarn followed by exit.
Packit 6c4009
The @code{verr} function is just like @code{err} except that the
Packit 6c4009
parameters for the handling of the format string @var{format} are passed
Packit 6c4009
in as a value of type @code{va_list}.
Packit 6c4009
@end deftypefun
Packit 6c4009
Packit 6c4009
@deftypefun void errx (int @var{status}, const char *@var{format}, @dots{})
Packit 6c4009
@standards{BSD, err.h}
Packit 6c4009
@safety{@prelim{}@mtsafe{@mtslocale{}}@asunsafe{@asucorrupt{} @ascuheap{}}@acunsafe{@acucorrupt{} @aculock{} @acsmem{}}}
Packit 6c4009
@c Same as warnx followed by exit.
Packit 6c4009
The @code{errx} function is roughly equivalent to a call like
Packit 6c4009
@smallexample
Packit 6c4009
  error (status, 0, format, @r{the parameters})
Packit 6c4009
@end smallexample
Packit 6c4009
@noindent
Packit 6c4009
except that the global variables @code{error} respects and modifies
Packit 6c4009
are not used and that the program is exited even if @var{status}
Packit 6c4009
is zero.  The difference to @code{err} is that no error number
Packit 6c4009
string is printed.
Packit 6c4009
@end deftypefun
Packit 6c4009
Packit 6c4009
@deftypefun void verrx (int @var{status}, const char *@var{format}, va_list @var{ap})
Packit 6c4009
@standards{BSD, err.h}
Packit 6c4009
@safety{@prelim{}@mtsafe{@mtslocale{}}@asunsafe{@asucorrupt{} @ascuheap{}}@acunsafe{@acucorrupt{} @aculock{} @acsmem{}}}
Packit 6c4009
@c Same as vwarnx followed by exit.
Packit 6c4009
The @code{verrx} function is just like @code{errx} except that the
Packit 6c4009
parameters for the handling of the format string @var{format} are passed
Packit 6c4009
in as a value of type @code{va_list}.
Packit 6c4009
@end deftypefun