NAME
strerror
,
strerror_l
, strerror_r
— get error message
string
SYNOPSIS
#include
<string.h>
char *
strerror
(int
errnum);
char *
strerror_l
(int
errnum, locale_t
locale);
int
strerror_r
(int
errnum, char
*strerrbuf, size_t
buflen);
DESCRIPTION
These functions map the error number errnum to an error message string.
strerror
()
and
strerror_l
()
return a string containing a maximum of NL_TEXTMAX
characters, including the trailing NUL. This string is not to be modified by
the calling program. The string returned by
strerror
() may be overwritten by subsequent calls to
strerror
() in any thread. The string returned by
strerror_l
() may be overwritten by subsequent calls
to strerror_l
() in the same thread.
strerror_r
()
is a thread safe version of strerror
() that places
the error message in the specified buffer
strerrbuf.
On OpenBSD, the global locale, the thread-specific locale, and the locale argument are ignored.
RETURN VALUES
strerror
() and
strerror_l
() return a pointer to the error message
string. If an error occurs, the error code is stored in
errno.
strerror_r
() returns zero upon successful
completion. If an error occurs, the error code is stored in
errno and the error code is returned.
ENVIRONMENT
On other operating systems, the behaviour of
strerror
() and strerror_r
()
may depend on the LC_MESSAGES
locale(1).
ERRORS
All these functions may fail if:
- [
EINVAL
] - errnum is not a valid error number. The returned error string will consist of an error message that includes errnum.
strerror_r
() may also fail if:
- [
ERANGE
] - The error message is larger than buflen characters. The message will be truncated to fit.
SEE ALSO
STANDARDS
The strerror
() function conforms to
ISO/IEC 9899:1999 (“ISO C99”).
The strerror_l
() and
strerror_r
() functions conform to
IEEE Std 1003.1-2008 (“POSIX.1”).
HISTORY
The strerror
() function has been available
since 4.3BSD-Reno,
strerror_r
() since OpenBSD
3.3, and strerror_l
() since
OpenBSD 6.2.