1<html lang="en"> 2<head> 3<title>strerror_r - Untitled</title> 4<meta http-equiv="Content-Type" content="text/html"> 5<meta name="description" content="Untitled"> 6<meta name="generator" content="makeinfo 4.13"> 7<link title="Top" rel="start" href="index.html#Top"> 8<link rel="up" href="Strings.html#Strings" title="Strings"> 9<link rel="prev" href="strerror.html#strerror" title="strerror"> 10<link rel="next" href="strlen.html#strlen" title="strlen"> 11<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> 12<meta http-equiv="Content-Style-Type" content="text/css"> 13<style type="text/css"><!-- 14 pre.display { font-family:inherit } 15 pre.format { font-family:inherit } 16 pre.smalldisplay { font-family:inherit; font-size:smaller } 17 pre.smallformat { font-family:inherit; font-size:smaller } 18 pre.smallexample { font-size:smaller } 19 pre.smalllisp { font-size:smaller } 20 span.sc { font-variant:small-caps } 21 span.roman { font-family:serif; font-weight:normal; } 22 span.sansserif { font-family:sans-serif; font-weight:normal; } 23--></style> 24<link rel="stylesheet" type="text/css" href="../cs.css"> 25</head> 26<body> 27<div class="node"> 28<a name="strerror_r"></a> 29<a name="strerror_005fr"></a> 30<p> 31Next: <a rel="next" accesskey="n" href="strlen.html#strlen">strlen</a>, 32Previous: <a rel="previous" accesskey="p" href="strerror.html#strerror">strerror</a>, 33Up: <a rel="up" accesskey="u" href="Strings.html#Strings">Strings</a> 34<hr> 35</div> 36 37<h3 class="section">5.25 <code>strerror_r</code>—convert error number to string and copy to buffer</h3> 38 39<p><a name="index-strerror_005fr-393"></a><strong>Synopsis</strong> 40<pre class="example"> #include <string.h> 41 #ifdef _GNU_SOURCE 42 char *strerror_r(int <var>errnum</var>, char *<var>buffer</var>, size_t <var>n</var>); 43 #else 44 int strerror_r(int <var>errnum</var>, char *<var>buffer</var>, size_t <var>n</var>); 45 #endif 46 47</pre> 48 <p><strong>Description</strong><br> 49<code>strerror_r</code> converts the error number <var>errnum</var> into a 50string and copies the result into the supplied <var>buffer</var> for 51a length up to <var>n</var>, including the NUL terminator. The value of 52<var>errnum</var> is usually a copy of <code>errno</code>. If <code>errnum</code> is not a known 53error number, the result is the empty string. 54 55 <p>See <code>strerror</code> for how strings are mapped to <code>errnum</code>. 56 57 <p><br> 58<strong>Returns</strong><br> 59There are two variants: the GNU version always returns a NUL-terminated 60string, which is <var>buffer</var> if all went well, but which is another 61pointer if <var>n</var> was too small (leaving <var>buffer</var> untouched). If the 62return is not <var>buffer</var>, your application must not modify that string. 63The POSIX version returns 0 on success, <var>EINVAL</var> if <code>errnum</code> was not 64recognized, and <var>ERANGE</var> if <var>n</var> was too small. The variant chosen 65depends on macros that you define before inclusion of <code>string.h</code>. 66 67 <p><br> 68<strong>Portability</strong><br> 69<code>strerror_r</code> with a <var>char *</var> result is a GNU extension. 70<code>strerror_r</code> with an <var>int</var> result is required by POSIX 2001. 71This function is compliant only if <code>_user_strerror</code> is not provided, 72or if it is thread-safe and uses separate storage according to whether 73the second argument of that function is non-zero. For more details 74on <code>_user_strerror</code>, see the <code>strerror</code> documentation. 75 76 <p>POSIX states that the contents of <var>buf</var> are unspecified on error, 77although this implementation guarantees a NUL-terminated string for 78all except <var>n</var> of 0. 79 80 <p>POSIX recommends that unknown <var>errnum</var> result in a message including 81that value, however it is not a requirement and this implementation 82provides only an empty string (unless you provide <code>_user_strerror</code>). 83POSIX also recommends that unknown <var>errnum</var> fail with EINVAL even 84when providing such a message, however it is not a requirement and 85this implementation will return success if <code>_user_strerror</code> provided 86a non-empty alternate string without assigning into its third argument. 87 88 <p><code>strerror_r</code> requires no supporting OS subroutines. 89 90 <p><br> 91 92 </body></html> 93 94