Next: strerror_r, Previous: strcspn, Up: Strings
strerror
—convert error number to string#include <string.h> char *strerror(int errnum); char *_strerror_r(struct _reent ptr, int errnum, int internal, int *error);
Description
strerror
converts the error number errnum into a
string. The value of errnum is usually a copy of errno
.
If errnum
is not a known error number, the result points to an
empty string.
This implementation of strerror
prints out the following strings
for each of the values defined in `errno.h
':
0
E2BIG
EACCES
EADDRINUSE
EADDRNOTAVAIL
EADV
EAFNOSUPPORT
EAGAIN
EALREADY
EBADF
EBADMSG
EBUSY
ECANCELED
ECHILD
ECOMM
ECONNABORTED
ECONNREFUSED
ECONNRESET
EDEADLK
EDESTADDRREQ
EEXIST
EDOM
EFAULT
EFBIG
EHOSTDOWN
EHOSTUNREACH
EIDRM
EILSEQ
EINPROGRESS
EINTR
EINVAL
EIO
EISCONN
EISDIR
ELIBACC
ELIBBAD
ELIBEXEC
ELIBMAX
ELIBSCN
.lib
section in a.out corrupted
EMFILE
EMLINK
EMSGSIZE
EMULTIHOP
ENAMETOOLONG
ENETDOWN
ENETRESET
ENETUNREACH
ENFILE
ENOBUFS
ENODATA
ENODEV
ENOENT
ENOEXEC
ENOLCK
ENOLINK
ENOMEM
ENOMSG
ENONET
ENOPKG
ENOPROTOOPT
ENOSPC
ENOSR
ENOSTR
ENOSYS
ENOTBLK
ENOTCONN
ENOTDIR
ENOTEMPTY
ENOTRECOVERABLE
ENOTSOCK
ENOTSUP
ENOTTY
ENXIO
EOPNOTSUPP
EOVERFLOW
EOWNERDEAD
EPERM
EPIPE
EPROTO
EPROTOTYPE
EPROTONOSUPPORT
ERANGE
EREMOTE
EROFS
ESHUTDOWN
ESOCKTNOSUPPORT
ESPIPE
ESRCH
ESRMNT
ESTRPIPE
ETIME
ETIMEDOUT
ETXTBSY
EWOULDBLOCK
EXDEV
_strerror_r
is a reentrant version of the above.
Returns
Portability
strerror
, but does not specify the strings used
for each error number.
Although this implementation of strerror
is reentrant (depending
on _user_strerror
), ANSI C declares that subsequent calls to
strerror
may overwrite the result string; therefore portable
code cannot depend on the reentrancy of this subroutine.
Although this implementation of strerror
guarantees a non-null
result with a NUL-terminator, some implementations return NULL
on failure. Although POSIX allows strerror
to set errno
to EINVAL on failure, this implementation does not do so (unless
you provide _user_strerror
).
POSIX recommends that unknown errnum result in a message
including that value, however it is not a requirement and this
implementation does not provide that information (unless you
provide _user_strerror
).
This implementation of strerror
provides for user-defined
extensibility. errno.h
defines __ELASTERROR, which can be
used as a base for user-defined error values. If the user supplies a
routine named _user_strerror
, and errnum passed to
strerror
does not match any of the supported values,
_user_strerror
is called with three arguments. The first is of
type int, and is the errnum value unknown to strerror
.
The second is of type int, and matches the internal argument
of _strerror_r
; this should be zero if called from strerror
and non-zero if called from any other function; _user_strerror
can
use this information to satisfy the POSIX rule that no other
standardized function can overwrite a static buffer reused by
strerror
. The third is of type int *, and matches the
error argument of _strerror_r
; if a non-zero value is stored
into that location (usually EINVAL), then strerror
will set
errno
to that value, and the XPG variant of strerror_r
will
return that value instead of zero or ERANGE. _user_strerror
returns a char * value; returning NULL implies that the user
function did not choose to handle errnum. The default
_user_strerror
returns NULL for all input values. Note that
_user_sterror
must be thread-safe, and only denote errors via the
third argument rather than modifying errno
, if strerror
and
strerror_r
are are to comply with POSIX.
strerror
requires no supporting OS subroutines.