388 lines
8.0 KiB
HTML
388 lines
8.0 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of STRERROR</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>STRERROR</H1>
|
|
Section: Linux Programmer's Manual (3)<BR>Updated: 2019-03-06<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
strerror, strerror_r, strerror_l - return string describing error number
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<PRE>
|
|
<B>#include <<A HREF="file:///usr/include/string.h">string.h</A>></B>
|
|
|
|
<B>char *strerror(int </B><I>errnum</I><B>);</B>
|
|
|
|
<B>int strerror_r(int </B><I>errnum</I><B>, char *</B><I>buf</I><B>, size_t </B><I>buflen</I><B>);</B>
|
|
/* XSI-compliant */
|
|
|
|
<B>char *strerror_r(int </B><I>errnum</I><B>, char *</B><I>buf</I><B>, size_t </B><I>buflen</I><B>);</B>
|
|
/* GNU-specific */
|
|
|
|
<B>char *strerror_l(int </B><I>errnum</I><B>, locale_t </B><I>locale</I><B>);</B>
|
|
</PRE>
|
|
|
|
<P>
|
|
|
|
|
|
Feature Test Macro Requirements for glibc (see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)):
|
|
|
|
|
|
|
|
<P>
|
|
|
|
<B>strerror_r</B>():
|
|
|
|
<DL COMPACT><DT id="1"><DD>
|
|
The XSI-compliant version is provided if:
|
|
<BR>
|
|
|
|
(_POSIX_C_SOURCE >= 200112L) && ! _GNU_SOURCE
|
|
<BR>
|
|
|
|
Otherwise, the GNU-specific version is provided.
|
|
</DL>
|
|
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
The
|
|
<B>strerror</B>()
|
|
|
|
function returns a pointer to a string that describes the error
|
|
code passed in the argument
|
|
<I>errnum</I>,
|
|
|
|
possibly using the
|
|
<B>LC_MESSAGES</B>
|
|
|
|
part of the current locale to select the appropriate language.
|
|
(For example, if
|
|
<I>errnum</I>
|
|
|
|
is
|
|
<B>EINVAL</B>,
|
|
|
|
the returned description will be "Invalid argument".)
|
|
This string must not be modified by the application, but may be
|
|
modified by a subsequent call to
|
|
<B>strerror</B>()
|
|
|
|
or
|
|
<B>strerror_l</B>().
|
|
|
|
No other library function, including
|
|
<B><A HREF="/cgi-bin/man/man2html?3+perror">perror</A></B>(3),
|
|
|
|
will modify this string.
|
|
|
|
<A NAME="lbAE"> </A>
|
|
<H3>strerror_r()</H3>
|
|
|
|
The
|
|
<B>strerror_r</B>()
|
|
|
|
function is similar to
|
|
<B>strerror</B>(),
|
|
|
|
but is
|
|
thread safe.
|
|
This function is available in two versions:
|
|
an XSI-compliant version specified in POSIX.1-2001
|
|
(available since glibc 2.3.4, but not POSIX-compliant until glibc 2.13),
|
|
and a GNU-specific version (available since glibc 2.0).
|
|
The XSI-compliant version is provided with the feature test macros
|
|
settings shown in the SYNOPSIS;
|
|
otherwise the GNU-specific version is provided.
|
|
If no feature test macros are explicitly defined,
|
|
then (since glibc 2.4)
|
|
<B>_POSIX_C_SOURCE</B>
|
|
|
|
is defined by default with the value
|
|
200112L, so that the XSI-compliant version of
|
|
<B>strerror_r</B>()
|
|
|
|
is provided by default.
|
|
<P>
|
|
|
|
The XSI-compliant
|
|
<B>strerror_r</B>()
|
|
|
|
is preferred for portable applications.
|
|
It returns the error string in the user-supplied buffer
|
|
<I>buf</I>
|
|
|
|
of length
|
|
<I>buflen</I>.
|
|
|
|
<P>
|
|
|
|
The GNU-specific
|
|
<B>strerror_r</B>()
|
|
|
|
returns a pointer to a string containing the error message.
|
|
This may be either a pointer to a string that the function stores in
|
|
<I>buf</I>,
|
|
|
|
or a pointer to some (immutable) static string
|
|
(in which case
|
|
<I>buf</I>
|
|
|
|
is unused).
|
|
If the function stores a string in
|
|
<I>buf</I>,
|
|
|
|
then at most
|
|
<I>buflen</I>
|
|
|
|
bytes are stored (the string may be truncated if
|
|
<I>buflen</I>
|
|
|
|
is too small and
|
|
<I>errnum</I>
|
|
|
|
is unknown).
|
|
The string always includes a terminating null byte ('\0').
|
|
|
|
<A NAME="lbAF"> </A>
|
|
<H3>strerror_l()</H3>
|
|
|
|
<B>strerror_l</B>()
|
|
|
|
is like
|
|
<B>strerror</B>(),
|
|
|
|
but maps
|
|
<I>errnum</I>
|
|
|
|
to a locale-dependent error message in the locale specified by
|
|
<I>locale</I>.
|
|
|
|
The behavior of
|
|
<B>strerror_l</B>()
|
|
|
|
is undefined if
|
|
<I>locale</I>
|
|
|
|
is the special locale object
|
|
<B>LC_GLOBAL_LOCALE</B>
|
|
|
|
or is not a valid locale object handle.
|
|
<A NAME="lbAG"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
The
|
|
<B>strerror</B>(),
|
|
|
|
<B>strerror_l</B>(),
|
|
|
|
and the GNU-specific
|
|
<B>strerror_r</B>()
|
|
|
|
functions return
|
|
the appropriate error description string,
|
|
or an "Unknown error nnn" message if the error number is unknown.
|
|
<P>
|
|
|
|
The XSI-compliant
|
|
<B>strerror_r</B>()
|
|
|
|
function returns 0 on success.
|
|
On error,
|
|
a (positive) error number is returned (since glibc 2.13),
|
|
or -1 is returned and
|
|
<I>errno</I>
|
|
|
|
is set to indicate the error (glibc versions before 2.13).
|
|
<P>
|
|
|
|
POSIX.1-2001 and POSIX.1-2008 require that a successful call to
|
|
<B>strerror</B>()
|
|
|
|
or
|
|
<B>strerror_l</B>()
|
|
|
|
shall leave
|
|
<I>errno</I>
|
|
|
|
unchanged, and note that,
|
|
since no function return value is reserved to indicate an error,
|
|
an application that wishes to check for errors should initialize
|
|
<I>errno</I>
|
|
|
|
to zero before the call,
|
|
and then check
|
|
<I>errno</I>
|
|
|
|
after the call.
|
|
<A NAME="lbAH"> </A>
|
|
<H2>ERRORS</H2>
|
|
|
|
<DL COMPACT>
|
|
<DT id="2"><B>EINVAL</B>
|
|
|
|
<DD>
|
|
The value of
|
|
<I>errnum</I>
|
|
|
|
is not a valid error number.
|
|
<DT id="3"><B>ERANGE</B>
|
|
|
|
<DD>
|
|
Insufficient storage was supplied to contain the error description string.
|
|
</DL>
|
|
<A NAME="lbAI"> </A>
|
|
<H2>VERSIONS</H2>
|
|
|
|
The
|
|
<B>strerror_l</B>()
|
|
|
|
function first appeared in glibc 2.6.
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>ATTRIBUTES</H2>
|
|
|
|
For an explanation of the terms used in this section, see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
|
|
|
|
<TABLE BORDER>
|
|
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>strerror</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>MT-Unsafe race:strerror<BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>strerror_r</B>(),
|
|
|
|
<BR>
|
|
|
|
<B>strerror_l</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>MT-Safe<BR></TD></TR>
|
|
</TABLE>
|
|
|
|
<A NAME="lbAK"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
<B>strerror</B>()
|
|
|
|
is specified by POSIX.1-2001, POSIX.1-2008, C89, and C99.
|
|
<B>strerror_r</B>()
|
|
|
|
is specified by POSIX.1-2001 and POSIX.1-2008.
|
|
|
|
|
|
|
|
|
|
<P>
|
|
|
|
<B>strerror_l</B>()
|
|
|
|
is specified in POSIX.1-2008.
|
|
<P>
|
|
|
|
The GNU-specific
|
|
<B>strerror_r</B>()
|
|
|
|
function is a nonstandard extension.
|
|
<P>
|
|
|
|
POSIX.1-2001 permits
|
|
<B>strerror</B>()
|
|
|
|
to set
|
|
<I>errno</I>
|
|
|
|
if the call encounters an error, but does not specify what
|
|
value should be returned as the function result in the event of an error.
|
|
On some systems,
|
|
|
|
<B>strerror</B>()
|
|
|
|
returns NULL if the error number is unknown.
|
|
On other systems,
|
|
|
|
<B>strerror</B>()
|
|
|
|
returns a string something like "Error nnn occurred" and sets
|
|
<I>errno</I>
|
|
|
|
to
|
|
<B>EINVAL</B>
|
|
|
|
if the error number is unknown.
|
|
C99 and POSIX.1-2008 require the return value to be non-NULL.
|
|
<A NAME="lbAL"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
The GNU C Library uses a buffer of 1024 characters for
|
|
<B>strerror</B>().
|
|
|
|
This buffer size therefore should be sufficient to avoid an
|
|
<B>ERANGE</B>
|
|
|
|
error when calling
|
|
<B>strerror_r</B>().
|
|
|
|
<A NAME="lbAM"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+err">err</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+errno">errno</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+error">error</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+perror">perror</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+strsignal">strsignal</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?7+locale">locale</A></B>(7)
|
|
|
|
<A NAME="lbAN"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="4"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="5"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="6"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DL>
|
|
<DT id="7"><A HREF="#lbAE">strerror_r()</A><DD>
|
|
<DT id="8"><A HREF="#lbAF">strerror_l()</A><DD>
|
|
</DL>
|
|
<DT id="9"><A HREF="#lbAG">RETURN VALUE</A><DD>
|
|
<DT id="10"><A HREF="#lbAH">ERRORS</A><DD>
|
|
<DT id="11"><A HREF="#lbAI">VERSIONS</A><DD>
|
|
<DT id="12"><A HREF="#lbAJ">ATTRIBUTES</A><DD>
|
|
<DT id="13"><A HREF="#lbAK">CONFORMING TO</A><DD>
|
|
<DT id="14"><A HREF="#lbAL">NOTES</A><DD>
|
|
<DT id="15"><A HREF="#lbAM">SEE ALSO</A><DD>
|
|
<DT id="16"><A HREF="#lbAN">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:58 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|