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.html 14KB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  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 (The Red Hat newlib C Library)</title>
  7. <meta name="description" content="strerror (The Red Hat newlib C Library)">
  8. <meta name="keywords" content="strerror (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="strerror_005fr.html#strerror_005fr" rel="next" title="strerror_r">
  17. <link href="strcspn.html#strcspn" rel="prev" title="strcspn">
  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"></a>
  48. <div class="header">
  49. <p>
  50. Next: <a href="strerror_005fr.html#strerror_005fr" accesskey="n" rel="next">strerror_r</a>, Previous: <a href="strcspn.html#strcspn" accesskey="p" rel="prev">strcspn</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_002c-strerror_005fl_002d_002d_002dconvert-error-number-to-string"></a>
  54. <h3 class="section">5.27 <code>strerror</code>, <code>strerror_l</code>&mdash;convert error number to string</h3>
  55. <a name="index-strerror"></a>
  56. <a name="index-strerror_005fl"></a>
  57. <p><strong>Synopsis</strong>
  58. </p><div class="example">
  59. <pre class="example">#include &lt;string.h&gt;
  60. char *strerror(int <var>errnum</var>);
  61. char *strerror_l(int <var>errnum</var>, locale_t <var>locale</var>);
  62. char *_strerror_r(struct _reent <var>ptr</var>, int <var>errnum</var>,
  63. int <var>internal</var>, int *<var>error</var>);
  64. </pre></div>
  65. <p><strong>Description</strong><br>
  66. <code>strerror</code> converts the error number <var>errnum</var> into a
  67. string. The value of <var>errnum</var> is usually a copy of <code>errno</code>.
  68. If <code>errnum</code> is not a known error number, the result points to an
  69. empty string.
  70. </p>
  71. <p><code>strerror_l</code> is like <code>strerror</code> but creates a string in a format
  72. as expected in locale <var>locale</var>. If <var>locale</var> is LC_GLOBAL_LOCALE or
  73. not a valid locale object, the behaviour is undefined.
  74. </p>
  75. <p>This implementation of <code>strerror</code> prints out the following strings
  76. for each of the values defined in &lsquo;<code>errno.h</code>&rsquo;:
  77. </p>
  78. <dl compact="compact">
  79. <dt><code>0</code></dt>
  80. <dd><p>Success
  81. </p>
  82. </dd>
  83. <dt><code>E2BIG</code></dt>
  84. <dd><p>Arg list too long
  85. </p>
  86. </dd>
  87. <dt><code>EACCES</code></dt>
  88. <dd><p>Permission denied
  89. </p>
  90. </dd>
  91. <dt><code>EADDRINUSE</code></dt>
  92. <dd><p>Address already in use
  93. </p>
  94. </dd>
  95. <dt><code>EADDRNOTAVAIL</code></dt>
  96. <dd><p>Address not available
  97. </p>
  98. </dd>
  99. <dt><code>EADV</code></dt>
  100. <dd><p>Advertise error
  101. </p>
  102. </dd>
  103. <dt><code>EAFNOSUPPORT</code></dt>
  104. <dd><p>Address family not supported by protocol family
  105. </p>
  106. </dd>
  107. <dt><code>EAGAIN</code></dt>
  108. <dd><p>No more processes
  109. </p>
  110. </dd>
  111. <dt><code>EALREADY</code></dt>
  112. <dd><p>Socket already connected
  113. </p>
  114. </dd>
  115. <dt><code>EBADF</code></dt>
  116. <dd><p>Bad file number
  117. </p>
  118. </dd>
  119. <dt><code>EBADMSG</code></dt>
  120. <dd><p>Bad message
  121. </p>
  122. </dd>
  123. <dt><code>EBUSY</code></dt>
  124. <dd><p>Device or resource busy
  125. </p>
  126. </dd>
  127. <dt><code>ECANCELED</code></dt>
  128. <dd><p>Operation canceled
  129. </p>
  130. </dd>
  131. <dt><code>ECHILD</code></dt>
  132. <dd><p>No children
  133. </p>
  134. </dd>
  135. <dt><code>ECOMM</code></dt>
  136. <dd><p>Communication error
  137. </p>
  138. </dd>
  139. <dt><code>ECONNABORTED</code></dt>
  140. <dd><p>Software caused connection abort
  141. </p>
  142. </dd>
  143. <dt><code>ECONNREFUSED</code></dt>
  144. <dd><p>Connection refused
  145. </p>
  146. </dd>
  147. <dt><code>ECONNRESET</code></dt>
  148. <dd><p>Connection reset by peer
  149. </p>
  150. </dd>
  151. <dt><code>EDEADLK</code></dt>
  152. <dd><p>Deadlock
  153. </p>
  154. </dd>
  155. <dt><code>EDESTADDRREQ</code></dt>
  156. <dd><p>Destination address required
  157. </p>
  158. </dd>
  159. <dt><code>EEXIST</code></dt>
  160. <dd><p>File exists
  161. </p>
  162. </dd>
  163. <dt><code>EDOM</code></dt>
  164. <dd><p>Mathematics argument out of domain of function
  165. </p>
  166. </dd>
  167. <dt><code>EFAULT</code></dt>
  168. <dd><p>Bad address
  169. </p>
  170. </dd>
  171. <dt><code>EFBIG</code></dt>
  172. <dd><p>File too large
  173. </p>
  174. </dd>
  175. <dt><code>EHOSTDOWN</code></dt>
  176. <dd><p>Host is down
  177. </p>
  178. </dd>
  179. <dt><code>EHOSTUNREACH</code></dt>
  180. <dd><p>Host is unreachable
  181. </p>
  182. </dd>
  183. <dt><code>EIDRM</code></dt>
  184. <dd><p>Identifier removed
  185. </p>
  186. </dd>
  187. <dt><code>EILSEQ</code></dt>
  188. <dd><p>Illegal byte sequence
  189. </p>
  190. </dd>
  191. <dt><code>EINPROGRESS</code></dt>
  192. <dd><p>Connection already in progress
  193. </p>
  194. </dd>
  195. <dt><code>EINTR</code></dt>
  196. <dd><p>Interrupted system call
  197. </p>
  198. </dd>
  199. <dt><code>EINVAL</code></dt>
  200. <dd><p>Invalid argument
  201. </p>
  202. </dd>
  203. <dt><code>EIO</code></dt>
  204. <dd><p>I/O error
  205. </p>
  206. </dd>
  207. <dt><code>EISCONN</code></dt>
  208. <dd><p>Socket is already connected
  209. </p>
  210. </dd>
  211. <dt><code>EISDIR</code></dt>
  212. <dd><p>Is a directory
  213. </p>
  214. </dd>
  215. <dt><code>ELIBACC</code></dt>
  216. <dd><p>Cannot access a needed shared library
  217. </p>
  218. </dd>
  219. <dt><code>ELIBBAD</code></dt>
  220. <dd><p>Accessing a corrupted shared library
  221. </p>
  222. </dd>
  223. <dt><code>ELIBEXEC</code></dt>
  224. <dd><p>Cannot exec a shared library directly
  225. </p>
  226. </dd>
  227. <dt><code>ELIBMAX</code></dt>
  228. <dd><p>Attempting to link in more shared libraries than system limit
  229. </p>
  230. </dd>
  231. <dt><code>ELIBSCN</code></dt>
  232. <dd><p><code>.lib</code> section in a.out corrupted
  233. </p>
  234. </dd>
  235. <dt><code>EMFILE</code></dt>
  236. <dd><p>File descriptor value too large
  237. </p>
  238. </dd>
  239. <dt><code>EMLINK</code></dt>
  240. <dd><p>Too many links
  241. </p>
  242. </dd>
  243. <dt><code>EMSGSIZE</code></dt>
  244. <dd><p>Message too long
  245. </p>
  246. </dd>
  247. <dt><code>EMULTIHOP</code></dt>
  248. <dd><p>Multihop attempted
  249. </p>
  250. </dd>
  251. <dt><code>ENAMETOOLONG</code></dt>
  252. <dd><p>File or path name too long
  253. </p>
  254. </dd>
  255. <dt><code>ENETDOWN</code></dt>
  256. <dd><p>Network interface is not configured
  257. </p>
  258. </dd>
  259. <dt><code>ENETRESET</code></dt>
  260. <dd><p>Connection aborted by network
  261. </p>
  262. </dd>
  263. <dt><code>ENETUNREACH</code></dt>
  264. <dd><p>Network is unreachable
  265. </p>
  266. </dd>
  267. <dt><code>ENFILE</code></dt>
  268. <dd><p>Too many open files in system
  269. </p>
  270. </dd>
  271. <dt><code>ENOBUFS</code></dt>
  272. <dd><p>No buffer space available
  273. </p>
  274. </dd>
  275. <dt><code>ENODATA</code></dt>
  276. <dd><p>No data
  277. </p>
  278. </dd>
  279. <dt><code>ENODEV</code></dt>
  280. <dd><p>No such device
  281. </p>
  282. </dd>
  283. <dt><code>ENOENT</code></dt>
  284. <dd><p>No such file or directory
  285. </p>
  286. </dd>
  287. <dt><code>ENOEXEC</code></dt>
  288. <dd><p>Exec format error
  289. </p>
  290. </dd>
  291. <dt><code>ENOLCK</code></dt>
  292. <dd><p>No lock
  293. </p>
  294. </dd>
  295. <dt><code>ENOLINK</code></dt>
  296. <dd><p>Virtual circuit is gone
  297. </p>
  298. </dd>
  299. <dt><code>ENOMEM</code></dt>
  300. <dd><p>Not enough space
  301. </p>
  302. </dd>
  303. <dt><code>ENOMSG</code></dt>
  304. <dd><p>No message of desired type
  305. </p>
  306. </dd>
  307. <dt><code>ENONET</code></dt>
  308. <dd><p>Machine is not on the network
  309. </p>
  310. </dd>
  311. <dt><code>ENOPKG</code></dt>
  312. <dd><p>No package
  313. </p>
  314. </dd>
  315. <dt><code>ENOPROTOOPT</code></dt>
  316. <dd><p>Protocol not available
  317. </p>
  318. </dd>
  319. <dt><code>ENOSPC</code></dt>
  320. <dd><p>No space left on device
  321. </p>
  322. </dd>
  323. <dt><code>ENOSR</code></dt>
  324. <dd><p>No stream resources
  325. </p>
  326. </dd>
  327. <dt><code>ENOSTR</code></dt>
  328. <dd><p>Not a stream
  329. </p>
  330. </dd>
  331. <dt><code>ENOSYS</code></dt>
  332. <dd><p>Function not implemented
  333. </p>
  334. </dd>
  335. <dt><code>ENOTBLK</code></dt>
  336. <dd><p>Block device required
  337. </p>
  338. </dd>
  339. <dt><code>ENOTCONN</code></dt>
  340. <dd><p>Socket is not connected
  341. </p>
  342. </dd>
  343. <dt><code>ENOTDIR</code></dt>
  344. <dd><p>Not a directory
  345. </p>
  346. </dd>
  347. <dt><code>ENOTEMPTY</code></dt>
  348. <dd><p>Directory not empty
  349. </p>
  350. </dd>
  351. <dt><code>ENOTRECOVERABLE</code></dt>
  352. <dd><p>State not recoverable
  353. </p>
  354. </dd>
  355. <dt><code>ENOTSOCK</code></dt>
  356. <dd><p>Socket operation on non-socket
  357. </p>
  358. </dd>
  359. <dt><code>ENOTSUP</code></dt>
  360. <dd><p>Not supported
  361. </p>
  362. </dd>
  363. <dt><code>ENOTTY</code></dt>
  364. <dd><p>Not a character device
  365. </p>
  366. </dd>
  367. <dt><code>ENXIO</code></dt>
  368. <dd><p>No such device or address
  369. </p>
  370. </dd>
  371. <dt><code>EOPNOTSUPP</code></dt>
  372. <dd><p>Operation not supported on socket
  373. </p>
  374. </dd>
  375. <dt><code>EOVERFLOW</code></dt>
  376. <dd><p>Value too large for defined data type
  377. </p>
  378. </dd>
  379. <dt><code>EOWNERDEAD</code></dt>
  380. <dd><p>Previous owner died
  381. </p>
  382. </dd>
  383. <dt><code>EPERM</code></dt>
  384. <dd><p>Not owner
  385. </p>
  386. </dd>
  387. <dt><code>EPIPE</code></dt>
  388. <dd><p>Broken pipe
  389. </p>
  390. </dd>
  391. <dt><code>EPROTO</code></dt>
  392. <dd><p>Protocol error
  393. </p>
  394. </dd>
  395. <dt><code>EPROTOTYPE</code></dt>
  396. <dd><p>Protocol wrong type for socket
  397. </p>
  398. </dd>
  399. <dt><code>EPROTONOSUPPORT</code></dt>
  400. <dd><p>Unknown protocol
  401. </p>
  402. </dd>
  403. <dt><code>ERANGE</code></dt>
  404. <dd><p>Result too large
  405. </p>
  406. </dd>
  407. <dt><code>EREMOTE</code></dt>
  408. <dd><p>Resource is remote
  409. </p>
  410. </dd>
  411. <dt><code>EROFS</code></dt>
  412. <dd><p>Read-only file system
  413. </p>
  414. </dd>
  415. <dt><code>ESHUTDOWN</code></dt>
  416. <dd><p>Can&rsquo;t send after socket shutdown
  417. </p>
  418. </dd>
  419. <dt><code>ESOCKTNOSUPPORT</code></dt>
  420. <dd><p>Socket type not supported
  421. </p>
  422. </dd>
  423. <dt><code>ESPIPE</code></dt>
  424. <dd><p>Illegal seek
  425. </p>
  426. </dd>
  427. <dt><code>ESRCH</code></dt>
  428. <dd><p>No such process
  429. </p>
  430. </dd>
  431. <dt><code>ESRMNT</code></dt>
  432. <dd><p>Srmount error
  433. </p>
  434. </dd>
  435. <dt><code>ESTRPIPE</code></dt>
  436. <dd><p>Strings pipe error
  437. </p>
  438. </dd>
  439. <dt><code>ETIME</code></dt>
  440. <dd><p>Stream ioctl timeout
  441. </p>
  442. </dd>
  443. <dt><code>ETIMEDOUT</code></dt>
  444. <dd><p>Connection timed out
  445. </p>
  446. </dd>
  447. <dt><code>ETXTBSY</code></dt>
  448. <dd><p>Text file busy
  449. </p>
  450. </dd>
  451. <dt><code>EWOULDBLOCK</code></dt>
  452. <dd><p>Operation would block (usually same as EAGAIN)
  453. </p>
  454. </dd>
  455. <dt><code>EXDEV</code></dt>
  456. <dd><p>Cross-device link
  457. </p>
  458. </dd>
  459. </dl>
  460. <p><code>_strerror_r</code> is a reentrant version of the above.
  461. </p>
  462. <br>
  463. <p><strong>Returns</strong><br>
  464. This function returns a pointer to a string. Your application must
  465. not modify that string.
  466. </p>
  467. <br>
  468. <p><strong>Portability</strong><br>
  469. ANSI C requires <code>strerror</code>, but does not specify the strings used
  470. for each error number.
  471. </p>
  472. <p><code>strerror_l</code> is POSIX-1.2008.
  473. </p>
  474. <p>Although this implementation of <code>strerror</code> is reentrant (depending
  475. on <code>_user_strerror</code>), ANSI C declares that subsequent calls to
  476. <code>strerror</code> may overwrite the result string; therefore portable
  477. code cannot depend on the reentrancy of this subroutine.
  478. </p>
  479. <p>Although this implementation of <code>strerror</code> guarantees a non-null
  480. result with a NUL-terminator, some implementations return <code>NULL</code>
  481. on failure. Although POSIX allows <code>strerror</code> to set <code>errno</code>
  482. to EINVAL on failure, this implementation does not do so (unless
  483. you provide <code>_user_strerror</code>).
  484. </p>
  485. <p>POSIX recommends that unknown <var>errnum</var> result in a message
  486. including that value, however it is not a requirement and this
  487. implementation does not provide that information (unless you
  488. provide <code>_user_strerror</code>).
  489. </p>
  490. <p>This implementation of <code>strerror</code> provides for user-defined
  491. extensibility. <code>errno.h</code> defines <var>__ELASTERROR</var>, which can be
  492. used as a base for user-defined error values. If the user supplies a
  493. routine named <code>_user_strerror</code>, and <var>errnum</var> passed to
  494. <code>strerror</code> does not match any of the supported values,
  495. <code>_user_strerror</code> is called with three arguments. The first is of
  496. type <var>int</var>, and is the <var>errnum</var> value unknown to <code>strerror</code>.
  497. The second is of type <var>int</var>, and matches the <var>internal</var> argument
  498. of <code>_strerror_r</code>; this should be zero if called from <code>strerror</code>
  499. and non-zero if called from any other function; <code>_user_strerror</code> can
  500. use this information to satisfy the POSIX rule that no other
  501. standardized function can overwrite a static buffer reused by
  502. <code>strerror</code>. The third is of type <var>int *</var>, and matches the
  503. <var>error</var> argument of <code>_strerror_r</code>; if a non-zero value is stored
  504. into that location (usually <var>EINVAL</var>), then <code>strerror</code> will set
  505. <code>errno</code> to that value, and the XPG variant of <code>strerror_r</code> will
  506. return that value instead of zero or <var>ERANGE</var>. <code>_user_strerror</code>
  507. returns a <var>char *</var> value; returning <var>NULL</var> implies that the user
  508. function did not choose to handle <var>errnum</var>. The default
  509. <code>_user_strerror</code> returns <var>NULL</var> for all input values. Note that
  510. <code>_user_sterror</code> must be thread-safe, and only denote errors via the
  511. third argument rather than modifying <code>errno</code>, if <code>strerror</code> and
  512. <code>strerror_r</code> are are to comply with POSIX.
  513. </p>
  514. <p><code>strerror</code> requires no supporting OS subroutines.
  515. </p>
  516. <br>
  517. <hr>
  518. <div class="header">
  519. <p>
  520. Next: <a href="strerror_005fr.html#strerror_005fr" accesskey="n" rel="next">strerror_r</a>, Previous: <a href="strcspn.html#strcspn" accesskey="p" rel="prev">strcspn</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>
  521. </div>
  522. </body>
  523. </html>