
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
        "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- MyFirstUnitAd -->
<ins class="adsbygoogle"
     style="display:inline-block;width:970px;height:250px"
     data-ad-client="ca-pub-5778386704669218"
     data-ad-slot="1503492166"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <link rel="stylesheet" type="text/css" href="../../../style.css" title="style" />
    <link rel="stylesheet" type="text/css" href="../style.css" title="style" />
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />

    <title>strerror.3p - Linux manual page</title>
</head>

<body>

<div class="page-top"><a id="top_of_page"></a></div>
<!--%%%TOP_BAR%%%-->
    <div class="nav-bar">
        <table class="nav-table">
            <tr>
                <td class="nav-cell">
                    <p class="nav-text">
                        <a href="http://man7.org/index.html">man7.org</a> &gt; Linux &gt; <a href="../index.html">man-pages</a>
                    </p>
                </td>
                <td class="training-cell">
                    <p class="training-text"><a class="training-link" href="http://man7.org/training/">Linux/UNIX system programming training</a></p>
                </td>
            </tr>
        </table>
    </div>

<hr class="nav-end" />

<!--%%%PAGE_START%%%-->


<table class="sec-table">
<tr>
    <td>
        <p class="section-dir">
<a href="strerror.3p.html#PROLOG">PROLOG</a> | <a href="strerror.3p.html#NAME">NAME</a> | <a href="strerror.3p.html#SYNOPSIS">SYNOPSIS</a> | <a href="strerror.3p.html#DESCRIPTION">DESCRIPTION</a> | <a href="strerror.3p.html#RETURN_VALUE">RETURN&nbsp;VALUE</a> | <a href="strerror.3p.html#ERRORS">ERRORS</a> | <a href="strerror.3p.html#EXAMPLES">EXAMPLES</a> | <a href="strerror.3p.html#APPLICATION_USAGE">APPLICATION&nbsp;USAGE</a> | <a href="strerror.3p.html#RATIONALE">RATIONALE</a> | <a href="strerror.3p.html#FUTURE_DIRECTIONS">FUTURE&nbsp;DIRECTIONS</a> | <a href="strerror.3p.html#SEE_ALSO">SEE&nbsp;ALSO</a> | <a href="strerror.3p.html#COPYRIGHT">COPYRIGHT</a>
        </p>
    </td>
    <td class="search-box">
        <div class="man-search-box">

            <form method="get" action="http://www.google.com/search">
                <fieldset class="man-search">
                    <input type="text" name="q" size="10" maxlength="255" value="" />
                    <input type="hidden" name="sitesearch" value="man7.org/linux/man-pages" />
                    <input type="submit" name="sa" value="Search online pages" />
                </fieldset>
            </form>

        </div>
    </td>
    <td> </td>
</tr>
</table>

<pre>
<span class="headline">STRERROR(3P)              POSIX Programmer's Manual             STRERROR(3P)</span>
</pre>
<h2><a id="PROLOG" href="strerror.3p.html#PROLOG"></a>PROLOG  &nbsp; &nbsp; &nbsp; &nbsp; <a href="strerror.3p.html#top_of_page"><span class="top-link">top</span></a></h2><pre>
       This manual page is part of the POSIX Programmer's Manual.  The Linux
       implementation of this interface may differ (consult the
       corresponding Linux manual page for details of Linux behavior), or
       the interface may not be implemented on Linux.
</pre>
<h2><a id="NAME" href="strerror.3p.html#NAME"></a>NAME  &nbsp; &nbsp; &nbsp; &nbsp; <a href="strerror.3p.html#top_of_page"><span class="top-link">top</span></a></h2><pre>
       strerror, strerror_l, strerror_r — get error message string
</pre>
<h2><a id="SYNOPSIS" href="strerror.3p.html#SYNOPSIS"></a>SYNOPSIS  &nbsp; &nbsp; &nbsp; &nbsp; <a href="strerror.3p.html#top_of_page"><span class="top-link">top</span></a></h2><pre>
       #include &lt;string.h&gt;

       char *strerror(int <i>errnum</i>);
       char *strerror_l(int <i>errnum</i>, locale_t <i>locale</i>);
       int strerror_r(int <i>errnum</i>, char *<i>strerrbuf</i>, size_t <i>buflen</i>);
</pre>
<h2><a id="DESCRIPTION" href="strerror.3p.html#DESCRIPTION"></a>DESCRIPTION  &nbsp; &nbsp; &nbsp; &nbsp; <a href="strerror.3p.html#top_of_page"><span class="top-link">top</span></a></h2><pre>
       For <i>strerror</i>(): The functionality described on this reference page is
       aligned with the ISO C standard. Any conflict between the
       requirements described here and the ISO C standard is unintentional.
       This volume of POSIX.1‐2008 defers to the ISO C standard.

       The <i>strerror</i>() function shall map the error number in <i>errnum</i> to a
       locale-dependent error message string and shall return a pointer to
       it. Typically, the values for <i>errnum</i> come from <i><a href="errno.3.html">errno</a></i>, but <i>strerror</i>()
       shall map any value of type <b>int </b>to a message.

       The application shall not modify the string returned.  The returned
       string pointer might be invalidated or the string content might be
       overwritten by a subsequent call to <i>strerror</i>(), or by a subsequent
       call to <i>strerror_l</i>() in the same thread.

       The string may be overwritten by a subsequent call to <i>strerror_l</i>() in
       the same thread.

       The contents of the error message strings returned by <i>strerror</i>()
       should be determined by the setting of the <i>LC_MESSAGES</i> category in
       the current locale.

       The implementation shall behave as if no function defined in this
       volume of POSIX.1‐2008 calls <i>strerror</i>().

       The <i>strerror</i>() and <i>strerror_l</i>() functions shall not change the
       setting of <i><a href="errno.3.html">errno</a></i> if successful.

       Since no return value is reserved to indicate an error of <i>strerror</i>(),
       an application wishing to check for error situations should set <i><a href="errno.3.html">errno</a></i>
       to 0, then call <i>strerror</i>(), then check <i><a href="errno.3.html">errno</a></i>.  Similarly, since
       <i>strerror_l</i>() is required to return a string for some errors, an
       application wishing to check for all error situations should set
       <i><a href="errno.3.html">errno</a></i> to 0, then call <i>strerror_l</i>(), then check <i><a href="errno.3.html">errno</a></i>.

       The <i>strerror</i>() function need not be thread-safe.

       The <i>strerror_l</i>() function shall map the error number in <i>errnum</i> to a
       locale-dependent error message string in the locale represented by
       <i>locale</i> and shall return a pointer to it.

       The <i>strerror_r</i>() function shall map the error number in <i>errnum</i> to a
       locale-dependent error message string and shall return the string in
       the buffer pointed to by <i>strerrbuf</i>, with length <i>buflen</i>.

       If the value of <i>errnum</i> is a valid error number, the message string
       shall indicate what error occurred; if the value of <i>errnum</i> is zero,
       the message string shall either be an empty string or indicate that
       no error occurred; otherwise, if these functions complete
       successfully, the message string shall indicate that an unknown error
       occurred.

       The behavior is undefined if the <i>locale</i> argument to <i>strerror_l</i>() is
       the special locale object LC_GLOBAL_LOCALE or is not a valid locale
       object handle.
</pre>
<h2><a id="RETURN_VALUE" href="strerror.3p.html#RETURN_VALUE"></a>RETURN VALUE  &nbsp; &nbsp; &nbsp; &nbsp; <a href="strerror.3p.html#top_of_page"><span class="top-link">top</span></a></h2><pre>
       Upon completion, whether successful or not, <i>strerror</i>() shall return a
       pointer to the generated message string.  On error <i><a href="errno.3.html">errno</a></i> may be set,
       but no return value is reserved to indicate an error.

       Upon successful completion, <i>strerror_l</i>() shall return a pointer to
       the generated message string. If <i>errnum</i> is not a valid error number,
       <i><a href="errno.3.html">errno</a></i> may be set to <b>[EINVAL]</b>, but a pointer to a message string shall
       still be returned. If any other error occurs, <i><a href="errno.3.html">errno</a></i> shall be set to
       indicate the error and a null pointer shall be returned.

       Upon successful completion, <i>strerror_r</i>() shall return 0. Otherwise,
       an error number shall be returned to indicate the error.
</pre>
<h2><a id="ERRORS" href="strerror.3p.html#ERRORS"></a>ERRORS  &nbsp; &nbsp; &nbsp; &nbsp; <a href="strerror.3p.html#top_of_page"><span class="top-link">top</span></a></h2><pre>
       These functions may fail if:

       <b>EINVAL </b>The value of <i>errnum</i> is neither a valid error number nor zero.

       The <i>strerror_r</i>() function may fail if:

       <b>ERANGE </b>Insufficient storage was supplied via <i>strerrbuf</i> and <i>buflen</i> to
              contain the generated message string.

       <i>The following sections are informative.</i>
</pre>
<h2><a id="EXAMPLES" href="strerror.3p.html#EXAMPLES"></a>EXAMPLES  &nbsp; &nbsp; &nbsp; &nbsp; <a href="strerror.3p.html#top_of_page"><span class="top-link">top</span></a></h2><pre>
       None.
</pre>
<h2><a id="APPLICATION_USAGE" href="strerror.3p.html#APPLICATION_USAGE"></a>APPLICATION USAGE  &nbsp; &nbsp; &nbsp; &nbsp; <a href="strerror.3p.html#top_of_page"><span class="top-link">top</span></a></h2><pre>
       Historically in some implementations, calls to <i>perror</i>() would
       overwrite the string that the pointer returned by <i>strerror</i>() points
       to. Such implementations did not conform to the ISO C standard;
       however, application developers should be aware of this behavior if
       they wish their applications to be portable to such implementations.
</pre>
<h2><a id="RATIONALE" href="strerror.3p.html#RATIONALE"></a>RATIONALE  &nbsp; &nbsp; &nbsp; &nbsp; <a href="strerror.3p.html#top_of_page"><span class="top-link">top</span></a></h2><pre>
       The <i>strerror_l</i>() function is required to be thread-safe, thereby
       eliminating the need for an equivalent to the <i>strerror_r</i>() function.

       Earlier versions of this standard did not explicitly require that the
       error message strings returned by <i>strerror</i>() and <i>strerror_r</i>() provide
       any information about the error. This version of the standard
       requires a meaningful message for any successful completion.

       Since no return value is reserved to indicate a <i>strerror</i>() error, but
       all calls (whether successful or not) must return a pointer to a
       message string, on error <i>strerror</i>() can return a pointer to an empty
       string or a pointer to a meaningful string that can be printed.

       Note that the <b>[EINVAL] </b>error condition is a may fail error. If an
       invalid error number is supplied as the value of <i>errnum</i>, applications
       should be prepared to handle any of the following:

        1. Error (with no meaningful message): <i><a href="errno.3.html">errno</a></i> is set to <b>[EINVAL]</b>, the
           return value is a pointer to an empty string.

        2. Successful completion: <i><a href="errno.3.html">errno</a></i> is unchanged and the return value
           points to a string like <b>"unknown</b>error" or <b>"error</b>number<b>xxx" </b>(where
           <i>xxx</i> is the value of <i>errnum</i>).

        3. Combination of #1 and #2: <i><a href="errno.3.html">errno</a></i> is set to <b>[EINVAL] </b>and the return
           value points to a string like <b>"unknown</b>error" or <b>"error</b>number<b>xxx"</b>
           (where <i>xxx</i> is the value of <i>errnum</i>).  Since applications
           frequently use the return value of <i>strerror</i>() as an argument to
           functions like <i>fprintf</i>() (without checking the return value) and
           since applications have no way to parse an error message string
           to determine whether <i>errnum</i> represents a valid error number,
           implementations are encouraged to implement #3. Similarly,
           implementations are encouraged to have <i>strerror_r</i>() return
           <b>[EINVAL] </b>and put a string like <b>"unknown</b>error" or <b>"error</b>number<b>xxx"</b>
           in the buffer pointed to by <i>strerrbuf</i> when the value of <i>errnum</i> is
           not a valid error number.

       Some applications rely on being able to set <i><a href="errno.3.html">errno</a></i> to 0 before calling
       a function with no reserved value to indicate an error, then call
       <i>strerror</i>(<i><a href="errno.3.html">errno</a></i>) afterwards to detect whether an error occurred
       (because <i><a href="errno.3.html">errno</a></i> changed) or to indicate success (because <i><a href="errno.3.html">errno</a></i>
       remained zero). This usage pattern requires that <b>strerror</b>(0) succeed
       with useful results. Previous versions of the standard did not
       specify the behavior when <i>errnum</i> is zero.
</pre>
<h2><a id="FUTURE_DIRECTIONS" href="strerror.3p.html#FUTURE_DIRECTIONS"></a>FUTURE DIRECTIONS  &nbsp; &nbsp; &nbsp; &nbsp; <a href="strerror.3p.html#top_of_page"><span class="top-link">top</span></a></h2><pre>
       None.
</pre>
<h2><a id="SEE_ALSO" href="strerror.3p.html#SEE_ALSO"></a>SEE ALSO  &nbsp; &nbsp; &nbsp; &nbsp; <a href="strerror.3p.html#top_of_page"><span class="top-link">top</span></a></h2><pre>
       <a href="perror.3p.html">perror(3p)</a>

       The Base Definitions volume of POSIX.1‐2008, <a href="../man0/string.h.0p.html">string.h(0p)</a>
</pre>
<h2><a id="COPYRIGHT" href="strerror.3p.html#COPYRIGHT"></a>COPYRIGHT  &nbsp; &nbsp; &nbsp; &nbsp; <a href="strerror.3p.html#top_of_page"><span class="top-link">top</span></a></h2><pre>
       Portions of this text are reprinted and reproduced in electronic form
       from IEEE Std 1003.1, 2013 Edition, Standard for Information
       Technology -- Portable Operating System Interface (POSIX), The Open
       Group Base Specifications Issue 7, Copyright (C) 2013 by the
       Institute of Electrical and Electronics Engineers, Inc and The Open
       Group.  (This is POSIX.1-2008 with the 2013 Technical Corrigendum 1
       applied.) In the event of any discrepancy between this version and
       the original IEEE and The Open Group Standard, the original IEEE and
       The Open Group Standard is the referee document. The original
       Standard can be obtained online at <a href="http://www.unix.org/online.html">http://www.unix.org/online.html</a> .

       Any typographical or formatting errors that appear in this page are
       most likely to have been introduced during the conversion of the
       source files to man page format. To report such errors, see
       <a href="https://www.kernel.org/doc/man-pages/reporting_bugs.html">https://www.kernel.org/doc/man-pages/reporting_bugs.html</a> .

<span class="footline">IEEE/The Open Group                 2013                        STRERROR(3P)</span>
</pre>

<hr class="end-man-text" />
<p>Pages that refer to this page: 
    <a href="../man0/string.h.0p.html">string.h(0p)</a>,&nbsp; 
    <a href="perror.3p.html">perror(3p)</a>,&nbsp; 
    <a href="setlocale.3p.html">setlocale(3p)</a>
</p>
<hr/>

 
<hr class="start-footer" />

<div class="footer"> 

<table class="colophon-table">
    <tr>
    <td class="pub-info">
        <p>
            HTML rendering created 2018-02-02
            by <a href="http://man7.org/mtk/index.html">Michael Kerrisk</a>, 
            author of 
            <a href="http://man7.org/tlpi/"><em>The Linux Programming Interface</em></a>, 
            maintainer of the 
            <a href="https://www.kernel.org/doc/man-pages/">Linux <em>man-pages</em> project</a>.
        </p>
        <p>
            For details of in-depth
            <strong>Linux/UNIX system programming training courses</strong>
            that I teach, look <a href="http://man7.org/training/">here</a>.
        </p>
        <p>
            Hosting by <a href="http://www.jambit.com/index_en.html">jambit GmbH</a>.
        </p>
        <p>
            <a href="http://validator.w3.org/check?uri=referer">
            <img src="http://www.w3.org/Icons/valid-xhtml11"
                alt="Valid XHTML 1.1" height="31" width="88" />
            </a>
        </p>
    </td>
    <td class="colophon-divider">
    </td>
    <td class="tlpi-cover">
        <a href="http://man7.org/tlpi/"><img src="../../../tlpi/cover/TLPI-front-cover-vsmall.png" alt="Cover of TLPI" /></a>
    </td>
    </tr>
</table>

</div>

<hr class="end-footer" />



<!--BEGIN-SITETRACKING-->
<!-- SITETRACKING.man7.org_linux_man-pages -->

<!-- Start of StatCounter Code (xhtml) -->

<script type="text/javascript">
//<![CDATA[
var sc_project=7422636; 
var sc_invisible=1; 
var sc_security="9b6714ff"; 
//]]>
</script>
<script type="text/javascript"
src="http://www.statcounter.com/counter/counter_xhtml.js"></script>
<noscript><div class="statcounter"><a title="website
statistics" href="http://statcounter.com/"
class="statcounter"><img class="statcounter"
src="http://c.statcounter.com/7422636/0/9b6714ff/1/"
alt="website statistics" /></a></div></noscript>

<!-- End of StatCounter Code -->


<!-- Start of Google Analytics Code -->

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-9830363-8']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

<!-- End of Google Analytics Code -->

<!--END-SITETRACKING-->

</body>
</html>
