You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

strerror_005fr.html 5.8KB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <title>strerror_r (The Red Hat newlib C Library)</title>
  7. <meta name="description" content="strerror_r (The Red Hat newlib C Library)">
  8. <meta name="keywords" content="strerror_r (The Red Hat newlib C Library)">
  9. <meta name="resource-type" content="document">
  10. <meta name="distribution" content="global">
  11. <meta name="Generator" content="makeinfo">
  12. <link href="index.html#Top" rel="start" title="Top">
  13. <link href="Document-Index.html#Document-Index" rel="index" title="Document Index">
  14. <link href="Document-Index.html#SEC_Contents" rel="contents" title="Table of Contents">
  15. <link href="Strings.html#Strings" rel="up" title="Strings">
  16. <link href="strlen.html#strlen" rel="next" title="strlen">
  17. <link href="strerror.html#strerror" rel="prev" title="strerror">
  18. <style type="text/css">
  19. <!--
  20. a.summary-letter {text-decoration: none}
  21. blockquote.indentedblock {margin-right: 0em}
  22. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  23. blockquote.smallquotation {font-size: smaller}
  24. div.display {margin-left: 3.2em}
  25. div.example {margin-left: 3.2em}
  26. div.lisp {margin-left: 3.2em}
  27. div.smalldisplay {margin-left: 3.2em}
  28. div.smallexample {margin-left: 3.2em}
  29. div.smalllisp {margin-left: 3.2em}
  30. kbd {font-style: oblique}
  31. pre.display {font-family: inherit}
  32. pre.format {font-family: inherit}
  33. pre.menu-comment {font-family: serif}
  34. pre.menu-preformatted {font-family: serif}
  35. pre.smalldisplay {font-family: inherit; font-size: smaller}
  36. pre.smallexample {font-size: smaller}
  37. pre.smallformat {font-family: inherit; font-size: smaller}
  38. pre.smalllisp {font-size: smaller}
  39. span.nolinebreak {white-space: nowrap}
  40. span.roman {font-family: initial; font-weight: normal}
  41. span.sansserif {font-family: sans-serif; font-weight: normal}
  42. ul.no-bullet {list-style: none}
  43. -->
  44. </style>
  45. </head>
  46. <body lang="en">
  47. <a name="strerror_005fr"></a>
  48. <div class="header">
  49. <p>
  50. Next: <a href="strlen.html#strlen" accesskey="n" rel="next">strlen</a>, Previous: <a href="strerror.html#strerror" accesskey="p" rel="prev">strerror</a>, Up: <a href="Strings.html#Strings" accesskey="u" rel="up">Strings</a> &nbsp; [<a href="Document-Index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Document-Index.html#Document-Index" title="Index" rel="index">Index</a>]</p>
  51. </div>
  52. <hr>
  53. <a name="strerror_005fr_002d_002d_002dconvert-error-number-to-string-and-copy-to-buffer"></a>
  54. <h3 class="section">5.28 <code>strerror_r</code>&mdash;convert error number to string and copy to buffer</h3>
  55. <a name="index-strerror_005fr"></a>
  56. <p><strong>Synopsis</strong>
  57. </p><div class="example">
  58. <pre class="example">#include &lt;string.h&gt;
  59. #ifdef _GNU_SOURCE
  60. char *strerror_r(int <var>errnum</var>, char *<var>buffer</var>, size_t <var>n</var>);
  61. #else
  62. int strerror_r(int <var>errnum</var>, char *<var>buffer</var>, size_t <var>n</var>);
  63. #endif
  64. </pre></div>
  65. <p><strong>Description</strong><br>
  66. <code>strerror_r</code> converts the error number <var>errnum</var> into a
  67. string and copies the result into the supplied <var>buffer</var> for
  68. a length up to <var>n</var>, including the NUL terminator. The value of
  69. <var>errnum</var> is usually a copy of <code>errno</code>. If <code>errnum</code> is not a known
  70. error number, the result is the empty string.
  71. </p>
  72. <p>See <code>strerror</code> for how strings are mapped to <code>errnum</code>.
  73. </p>
  74. <br>
  75. <p><strong>Returns</strong><br>
  76. There are two variants: the GNU version always returns a NUL-terminated
  77. string, which is <var>buffer</var> if all went well, but which is another
  78. pointer if <var>n</var> was too small (leaving <var>buffer</var> untouched). If the
  79. return is not <var>buffer</var>, your application must not modify that string.
  80. The POSIX version returns 0 on success, <var>EINVAL</var> if <code>errnum</code> was not
  81. recognized, and <var>ERANGE</var> if <var>n</var> was too small. The variant chosen
  82. depends on macros that you define before inclusion of <code>string.h</code>.
  83. </p>
  84. <br>
  85. <p><strong>Portability</strong><br>
  86. <code>strerror_r</code> with a <var>char *</var> result is a GNU extension.
  87. <code>strerror_r</code> with an <var>int</var> result is required by POSIX 2001.
  88. This function is compliant only if <code>_user_strerror</code> is not provided,
  89. or if it is thread-safe and uses separate storage according to whether
  90. the second argument of that function is non-zero. For more details
  91. on <code>_user_strerror</code>, see the <code>strerror</code> documentation.
  92. </p>
  93. <p>POSIX states that the contents of <var>buf</var> are unspecified on error,
  94. although this implementation guarantees a NUL-terminated string for
  95. all except <var>n</var> of 0.
  96. </p>
  97. <p>POSIX recommends that unknown <var>errnum</var> result in a message including
  98. that value, however it is not a requirement and this implementation
  99. provides only an empty string (unless you provide <code>_user_strerror</code>).
  100. POSIX also recommends that unknown <var>errnum</var> fail with EINVAL even
  101. when providing such a message, however it is not a requirement and
  102. this implementation will return success if <code>_user_strerror</code> provided
  103. a non-empty alternate string without assigning into its third argument.
  104. </p>
  105. <p><code>strerror_r</code> requires no supporting OS subroutines.
  106. </p>
  107. <br>
  108. <hr>
  109. <div class="header">
  110. <p>
  111. Next: <a href="strlen.html#strlen" accesskey="n" rel="next">strlen</a>, Previous: <a href="strerror.html#strerror" accesskey="p" rel="prev">strerror</a>, Up: <a href="Strings.html#Strings" accesskey="u" rel="up">Strings</a> &nbsp; [<a href="Document-Index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Document-Index.html#Document-Index" title="Index" rel="index">Index</a>]</p>
  112. </div>
  113. </body>
  114. </html>