Subversion Repositories Kolibri OS

Rev

Rev 4872 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /***
  2. **** CAUTION!!! KEEP DOC CONSISTENT---if you change text of a message
  3. ****            here, change two places:
  4. ****            1) the leading doc section (alphabetized by macro)
  5. ****            2) the real text inside switch(errnum)
  6. ***/
  7.  
  8. /*
  9. FUNCTION
  10.         <<strerror>>---convert error number to string
  11.  
  12. INDEX
  13.         strerror
  14.  
  15. ANSI_SYNOPSIS
  16.         #include <string.h>
  17.         char *strerror(int <[errnum]>);
  18.         char *_strerror_r(struct _reent <[ptr]>, int <[errnum]>,
  19.                           int <[internal]>, int *<[error]>);
  20.  
  21. TRAD_SYNOPSIS
  22.         #include <string.h>
  23.         char *strerror(<[errnum]>)
  24.         int <[errnum]>;
  25.  
  26. DESCRIPTION
  27. <<strerror>> converts the error number <[errnum]> into a
  28. string.  The value of <[errnum]> is usually a copy of <<errno>>.
  29. If <<errnum>> is not a known error number, the result points to an
  30. empty string.
  31.  
  32. This implementation of <<strerror>> prints out the following strings
  33. for each of the values defined in `<<errno.h>>':
  34.  
  35. o+
  36. o 0
  37. Success
  38.  
  39. o E2BIG
  40. Arg list too long
  41.  
  42. o EACCES
  43. Permission denied
  44.  
  45. o EADDRINUSE
  46. Address already in use
  47.  
  48. o EADV
  49. Advertise error
  50.  
  51. o EAFNOSUPPORT
  52. Address family not supported by protocol family
  53.  
  54. o EAGAIN
  55. No more processes
  56.  
  57. o EALREADY
  58. Socket already connected
  59.  
  60. o EBADF
  61. Bad file number
  62.  
  63. o EBADMSG
  64. Bad message
  65.  
  66. o EBUSY
  67. Device or resource busy
  68.  
  69. o ECHILD
  70. No children
  71.  
  72. o ECOMM
  73. Communication error
  74.  
  75. o ECONNABORTED
  76. Software caused connection abort
  77.  
  78. o ECONNREFUSED
  79. Connection refused
  80.  
  81. o EDEADLK
  82. Deadlock
  83.  
  84. o EDESTADDRREQ
  85. Destination address required
  86.  
  87. o EEXIST
  88. File exists
  89.  
  90. o EDOM
  91. Math argument
  92.  
  93. o EFAULT
  94. Bad address
  95.  
  96. o EFBIG
  97. File too large
  98.  
  99. o EHOSTDOWN
  100. Host is down
  101.  
  102. o EHOSTUNREACH
  103. Host is unreachable
  104.  
  105. o EIDRM
  106. Identifier removed
  107.  
  108. o EINPROGRESS
  109. Connection already in progress
  110.  
  111. o EINTR
  112. Interrupted system call
  113.  
  114. o EINVAL
  115. Invalid argument
  116.  
  117. o EIO
  118. I/O error
  119.  
  120. o EISCONN
  121. Socket is already connected
  122.  
  123. o EISDIR
  124. Is a directory
  125.  
  126. o ELIBACC
  127. Cannot access a needed shared library
  128.  
  129. o ELIBBAD
  130. Accessing a corrupted shared library
  131.  
  132. o ELIBEXEC
  133. Cannot exec a shared library directly
  134.  
  135. o ELIBMAX
  136. Attempting to link in more shared libraries than system limit
  137.  
  138. o ELIBSCN
  139. <<.lib>> section in a.out corrupted
  140.  
  141. o EMFILE
  142. Too many open files
  143.  
  144. o EMLINK
  145. Too many links
  146.  
  147. o EMSGSIZE
  148. Message too long
  149.  
  150. o EMULTIHOP
  151. Multihop attempted
  152.  
  153. o ENAMETOOLONG
  154. File or path name too long
  155.  
  156. o ENETDOWN
  157. Network interface not configured
  158.  
  159. o ENETUNREACH
  160. Network is unreachable
  161.  
  162. o ENFILE
  163. Too many open files in system
  164.  
  165. o ENODEV
  166. No such device
  167.  
  168. o ENOENT
  169. No such file or directory
  170.  
  171. o ENOEXEC
  172. Exec format error
  173.  
  174. o ENOLCK
  175. No lock
  176.  
  177. o ENOLINK
  178. Virtual circuit is gone
  179.  
  180. o ENOMEM
  181. Not enough space
  182.  
  183. o ENOMSG
  184. No message of desired type
  185.  
  186. o ENONET
  187. Machine is not on the network
  188.  
  189. o ENOPKG
  190. No package
  191.  
  192. o ENOPROTOOPT
  193. Protocol not available
  194.  
  195. o ENOSPC
  196. No space left on device
  197.  
  198. o ENOSR
  199. No stream resources
  200.  
  201. o ENOSTR
  202. Not a stream
  203.  
  204. o ENOSYS
  205. Function not implemented
  206.  
  207. o ENOTBLK
  208. Block device required
  209.  
  210. o ENOTCONN
  211. Socket is not connected
  212.  
  213. o ENOTDIR
  214. Not a directory
  215.  
  216. o ENOTEMPTY
  217. Directory not empty
  218.  
  219. o ENOTSOCK
  220. Socket operation on non-socket
  221.  
  222. o ENOTSUP
  223. Not supported
  224.  
  225. o ENOTTY
  226. Not a character device
  227.  
  228. o ENXIO
  229. No such device or address
  230.  
  231. o EPERM
  232. Not owner
  233.  
  234. o EPIPE
  235. Broken pipe
  236.  
  237. o EPROTO
  238. Protocol error
  239.  
  240. o EPROTOTYPE
  241. Protocol wrong type for socket
  242.  
  243. o EPROTONOSUPPORT
  244. Unknown protocol
  245.  
  246. o ERANGE
  247. Result too large
  248.  
  249. o EREMOTE
  250. Resource is remote
  251.  
  252. o EROFS
  253. Read-only file system
  254.  
  255. o ESHUTDOWN
  256. Can't send after socket shutdown
  257.  
  258. o ESOCKTNOSUPPORT
  259. Socket type not supported
  260.  
  261. o ESPIPE
  262. Illegal seek
  263.  
  264. o ESRCH
  265. No such process
  266.  
  267. o ESRMNT
  268. Srmount error
  269.  
  270. o ETIME
  271. Stream ioctl timeout
  272.  
  273. o ETIMEDOUT
  274. Connection timed out
  275.  
  276. o ETXTBSY
  277. Text file busy
  278.  
  279. o EXDEV
  280. Cross-device link
  281.  
  282. o ECANCELED
  283. Operation canceled
  284.  
  285. o ENOTRECOVERABLE
  286. State not recoverable
  287.  
  288. o EOWNERDEAD
  289. Previous owner died
  290.  
  291. o ESTRPIPE
  292. Strings pipe error
  293.  
  294. o-
  295.  
  296. <<_strerror_r>> is a reentrant version of the above.
  297.  
  298. RETURNS
  299. This function returns a pointer to a string.  Your application must
  300. not modify that string.
  301.  
  302. PORTABILITY
  303. ANSI C requires <<strerror>>, but does not specify the strings used
  304. for each error number.
  305.  
  306. Although this implementation of <<strerror>> is reentrant (depending
  307. on <<_user_strerror>>), ANSI C declares that subsequent calls to
  308. <<strerror>> may overwrite the result string; therefore portable
  309. code cannot depend on the reentrancy of this subroutine.
  310.  
  311. Although this implementation of <<strerror>> guarantees a non-null
  312. result with a NUL-terminator, some implementations return <<NULL>>
  313. on failure.  Although POSIX allows <<strerror>> to set <<errno>>
  314. to EINVAL on failure, this implementation does not do so (unless
  315. you provide <<_user_strerror>>).
  316.  
  317. POSIX recommends that unknown <[errnum]> result in a message
  318. including that value, however it is not a requirement and this
  319. implementation does not provide that information (unless you
  320. provide <<_user_strerror>>).
  321.  
  322. This implementation of <<strerror>> provides for user-defined
  323. extensibility.  <<errno.h>> defines <[__ELASTERROR]>, which can be
  324. used as a base for user-defined error values.  If the user supplies a
  325. routine named <<_user_strerror>>, and <[errnum]> passed to
  326. <<strerror>> does not match any of the supported values,
  327. <<_user_strerror>> is called with three arguments.  The first is of
  328. type <[int]>, and is the <[errnum]> value unknown to <<strerror>>.
  329. The second is of type <[int]>, and matches the <[internal]> argument
  330. of <<_strerror_r>>; this should be zero if called from <<strerror>>
  331. and non-zero if called from any other function; <<_user_strerror>> can
  332. use this information to satisfy the POSIX rule that no other
  333. standardized function can overwrite a static buffer reused by
  334. <<strerror>>.  The third is of type <[int *]>, and matches the
  335. <[error]> argument of <<_strerror_r>>; if a non-zero value is stored
  336. into that location (usually <[EINVAL]>), then <<strerror>> will set
  337. <<errno>> to that value, and the XPG variant of <<strerror_r>> will
  338. return that value instead of zero or <[ERANGE]>.  <<_user_strerror>>
  339. returns a <[char *]> value; returning <[NULL]> implies that the user
  340. function did not choose to handle <[errnum]>.  The default
  341. <<_user_strerror>> returns <[NULL]> for all input values.  Note that
  342. <<_user_sterror>> must be thread-safe, and only denote errors via the
  343. third argument rather than modifying <<errno>>, if <<strerror>> and
  344. <<strerror_r>> are are to comply with POSIX.
  345.  
  346. <<strerror>> requires no supporting OS subroutines.
  347.  
  348. QUICKREF
  349.         strerror ansi pure
  350. */
  351.  
  352. #include <errno.h>
  353. #include <string.h>
  354.  
  355. char *
  356. _DEFUN (_strerror_r, (ptr, errnum, internal, errptr),
  357.         struct _reent *ptr _AND
  358.         int errnum _AND
  359.         int internal _AND
  360.         int *errptr)
  361. {
  362.   char *error;
  363.   extern char *_user_strerror _PARAMS ((int, int, int *));
  364.  
  365.   switch (errnum)
  366.     {
  367.     case 0:
  368.       error = "Success";
  369.       break;
  370. /* go32 defines EPERM as EACCES */
  371. #if defined (EPERM) && (!defined (EACCES) || (EPERM != EACCES))
  372.     case EPERM:
  373.       error = "Not owner";
  374.       break;
  375. #endif
  376. #ifdef ENOENT
  377.     case ENOENT:
  378.       error = "No such file or directory";
  379.       break;
  380. #endif
  381. #ifdef ESRCH
  382.     case ESRCH:
  383.       error = "No such process";
  384.       break;
  385. #endif
  386. #ifdef EINTR
  387.     case EINTR:
  388.       error = "Interrupted system call";
  389.       break;
  390. #endif
  391. #ifdef EIO
  392.     case EIO:
  393.       error = "I/O error";
  394.       break;
  395. #endif
  396. /* go32 defines ENXIO as ENODEV */
  397. #if defined (ENXIO) && (!defined (ENODEV) || (ENXIO != ENODEV))
  398.     case ENXIO:
  399.       error = "No such device or address";
  400.       break;
  401. #endif
  402. #ifdef E2BIG
  403.     case E2BIG:
  404.       error = "Arg list too long";
  405.       break;
  406. #endif
  407. #ifdef ENOEXEC
  408.     case ENOEXEC:
  409.       error = "Exec format error";
  410.       break;
  411. #endif
  412. #ifdef EALREADY
  413.     case EALREADY:
  414.       error = "Socket already connected";
  415.       break;
  416. #endif
  417. #ifdef EBADF
  418.     case EBADF:
  419.       error = "Bad file number";
  420.       break;
  421. #endif
  422. #ifdef ECHILD
  423.     case ECHILD:
  424.       error = "No children";
  425.       break;
  426. #endif
  427. #ifdef EDESTADDRREQ
  428.     case EDESTADDRREQ:
  429.       error = "Destination address required";
  430.       break;
  431. #endif
  432. #ifdef EAGAIN
  433.     case EAGAIN:
  434.       error = "No more processes";
  435.       break;
  436. #endif
  437. #ifdef ENOMEM
  438.     case ENOMEM:
  439.       error = "Not enough space";
  440.       break;
  441. #endif
  442. #ifdef EACCES
  443.     case EACCES:
  444.       error = "Permission denied";
  445.       break;
  446. #endif
  447. #ifdef EFAULT
  448.     case EFAULT:
  449.       error = "Bad address";
  450.       break;
  451. #endif
  452. #ifdef ENOTBLK
  453.     case ENOTBLK:
  454.       error = "Block device required";
  455.       break;
  456. #endif
  457. #ifdef EBUSY
  458.     case EBUSY:
  459.       error = "Device or resource busy";
  460.       break;
  461. #endif
  462. #ifdef EEXIST
  463.     case EEXIST:
  464.       error = "File exists";
  465.       break;
  466. #endif
  467. #ifdef EXDEV
  468.     case EXDEV:
  469.       error = "Cross-device link";
  470.       break;
  471. #endif
  472. #ifdef ENODEV
  473.     case ENODEV:
  474.       error = "No such device";
  475.       break;
  476. #endif
  477. #ifdef ENOTDIR
  478.     case ENOTDIR:
  479.       error = "Not a directory";
  480.       break;
  481. #endif
  482. #ifdef EHOSTDOWN
  483.     case EHOSTDOWN:
  484.       error = "Host is down";
  485.       break;
  486. #endif
  487. #ifdef EINPROGRESS
  488.     case EINPROGRESS:
  489.       error = "Connection already in progress";
  490.       break;
  491. #endif
  492. #ifdef EISDIR
  493.     case EISDIR:
  494.       error = "Is a directory";
  495.       break;
  496. #endif
  497. #ifdef EINVAL
  498.     case EINVAL:
  499.       error = "Invalid argument";
  500.       break;
  501. #endif
  502. #ifdef ENETDOWN
  503.     case ENETDOWN:
  504.       error = "Network interface is not configured";
  505.       break;
  506. #endif
  507. #ifdef ENFILE
  508.     case ENFILE:
  509.       error = "Too many open files in system";
  510.       break;
  511. #endif
  512. #ifdef EMFILE
  513.     case EMFILE:
  514.       error = "Too many open files";
  515.       break;
  516. #endif
  517. #ifdef ENOTTY
  518.     case ENOTTY:
  519.       error = "Not a character device";
  520.       break;
  521. #endif
  522. #ifdef ETXTBSY
  523.     case ETXTBSY:
  524.       error = "Text file busy";
  525.       break;
  526. #endif
  527. #ifdef EFBIG
  528.     case EFBIG:
  529.       error = "File too large";
  530.       break;
  531. #endif
  532. #ifdef EHOSTUNREACH
  533.     case EHOSTUNREACH:
  534.       error = "Host is unreachable";
  535.       break;
  536. #endif
  537. #ifdef ENOSPC
  538.     case ENOSPC:
  539.       error = "No space left on device";
  540.       break;
  541. #endif
  542. #ifdef ENOTSUP
  543.     case ENOTSUP:
  544.       error = "Not supported";
  545.       break;
  546. #endif
  547. #ifdef ESPIPE
  548.     case ESPIPE:
  549.       error = "Illegal seek";
  550.       break;
  551. #endif
  552. #ifdef EROFS
  553.     case EROFS:
  554.       error = "Read-only file system";
  555.       break;
  556. #endif
  557. #ifdef EMLINK
  558.     case EMLINK:
  559.       error = "Too many links";
  560.       break;
  561. #endif
  562. #ifdef EPIPE
  563.     case EPIPE:
  564.       error = "Broken pipe";
  565.       break;
  566. #endif
  567. #ifdef EDOM
  568.     case EDOM:
  569.       error = "Math argument";
  570.       break;
  571. #endif
  572. #ifdef ERANGE
  573.     case ERANGE:
  574.       error = "Result too large";
  575.       break;
  576. #endif
  577. #ifdef ENOMSG
  578.     case ENOMSG:
  579.       error = "No message of desired type";
  580.       break;
  581. #endif
  582. #ifdef EIDRM
  583.     case EIDRM:
  584.       error = "Identifier removed";
  585.       break;
  586. #endif
  587. #ifdef EDEADLK
  588.     case EDEADLK:
  589.       error = "Deadlock";
  590.       break;
  591. #endif
  592. #ifdef ENETUNREACH
  593.     case  ENETUNREACH:
  594.       error = "Network is unreachable";
  595.       break;
  596. #endif
  597. #ifdef ENOLCK
  598.     case ENOLCK:
  599.       error = "No lock";
  600.       break;
  601. #endif
  602. #ifdef ENOSTR
  603.     case ENOSTR:
  604.       error = "Not a stream";
  605.       break;
  606. #endif
  607. #ifdef ETIME
  608.     case ETIME:
  609.       error = "Stream ioctl timeout";
  610.       break;
  611. #endif
  612. #ifdef ENOSR
  613.     case ENOSR:
  614.       error = "No stream resources";
  615.       break;
  616. #endif
  617. #ifdef ENONET
  618.     case ENONET:
  619.       error = "Machine is not on the network";
  620.       break;
  621. #endif
  622. #ifdef ENOPKG
  623.     case ENOPKG:
  624.       error = "No package";
  625.       break;
  626. #endif
  627. #ifdef EREMOTE
  628.     case EREMOTE:
  629.       error = "Resource is remote";
  630.       break;
  631. #endif
  632. #ifdef ENOLINK
  633.     case ENOLINK:
  634.       error = "Virtual circuit is gone";
  635.       break;
  636. #endif
  637. #ifdef EADV
  638.     case EADV:
  639.       error = "Advertise error";
  640.       break;
  641. #endif
  642. #ifdef ESRMNT
  643.     case ESRMNT:
  644.       error = "Srmount error";
  645.       break;
  646. #endif
  647. #ifdef ECOMM
  648.     case ECOMM:
  649.       error = "Communication error";
  650.       break;
  651. #endif
  652. #ifdef EPROTO
  653.     case EPROTO:
  654.       error = "Protocol error";
  655.       break;
  656. #endif
  657. #ifdef EPROTONOSUPPORT
  658.     case EPROTONOSUPPORT:
  659.       error = "Unknown protocol";
  660.       break;
  661. #endif
  662. #ifdef EMULTIHOP
  663.     case EMULTIHOP:
  664.       error = "Multihop attempted";
  665.       break;
  666. #endif
  667. #ifdef EBADMSG
  668.     case EBADMSG:
  669.       error = "Bad message";
  670.       break;
  671. #endif
  672. #ifdef ELIBACC
  673.     case ELIBACC:
  674.       error = "Cannot access a needed shared library";
  675.       break;
  676. #endif
  677. #ifdef ELIBBAD
  678.     case ELIBBAD:
  679.       error = "Accessing a corrupted shared library";
  680.       break;
  681. #endif
  682. #ifdef ELIBSCN
  683.     case ELIBSCN:
  684.       error = ".lib section in a.out corrupted";
  685.       break;
  686. #endif
  687. #ifdef ELIBMAX
  688.     case ELIBMAX:
  689.       error = "Attempting to link in more shared libraries than system limit";
  690.       break;
  691. #endif
  692. #ifdef ELIBEXEC
  693.     case ELIBEXEC:
  694.       error = "Cannot exec a shared library directly";
  695.       break;
  696. #endif
  697. #ifdef ENOSYS
  698.     case ENOSYS:
  699.       error = "Function not implemented";
  700.       break;
  701. #endif
  702. #ifdef ENMFILE
  703.     case ENMFILE:
  704.       error = "No more files";
  705.       break;
  706. #endif
  707. #ifdef ENOTEMPTY
  708.     case ENOTEMPTY:
  709.       error = "Directory not empty";
  710.       break;
  711. #endif
  712. #ifdef ENAMETOOLONG
  713.     case ENAMETOOLONG:
  714.       error = "File or path name too long";
  715.       break;
  716. #endif
  717. #ifdef ELOOP
  718.     case ELOOP:
  719.       error = "Too many symbolic links";
  720.       break;
  721. #endif
  722. #ifdef ENOBUFS
  723.     case ENOBUFS:
  724.       error = "No buffer space available";
  725.       break;
  726. #endif
  727. #ifdef EAFNOSUPPORT
  728.     case EAFNOSUPPORT:
  729.       error = "Address family not supported by protocol family";
  730.       break;
  731. #endif
  732. #ifdef EPROTOTYPE
  733.     case EPROTOTYPE:
  734.       error = "Protocol wrong type for socket";
  735.       break;
  736. #endif
  737. #ifdef ENOTSOCK
  738.     case ENOTSOCK:
  739.       error = "Socket operation on non-socket";
  740.       break;
  741. #endif
  742. #ifdef ENOPROTOOPT
  743.     case ENOPROTOOPT:
  744.       error = "Protocol not available";
  745.       break;
  746. #endif
  747. #ifdef ESHUTDOWN
  748.     case ESHUTDOWN:
  749.       error = "Can't send after socket shutdown";
  750.       break;
  751. #endif
  752. #ifdef ECONNREFUSED
  753.     case ECONNREFUSED:
  754.       error = "Connection refused";
  755.       break;
  756. #endif
  757. #ifdef EADDRINUSE
  758.     case EADDRINUSE:
  759.       error = "Address already in use";
  760.       break;
  761. #endif
  762. #ifdef ECONNABORTED
  763.     case ECONNABORTED:
  764.       error = "Software caused connection abort";
  765.       break;
  766. #endif
  767. #if (defined(EWOULDBLOCK) && (!defined (EAGAIN) || (EWOULDBLOCK != EAGAIN)))
  768.     case EWOULDBLOCK:
  769.         error = "Operation would block";
  770.         break;
  771. #endif
  772. #ifdef ENOTCONN
  773.     case ENOTCONN:
  774.         error = "Socket is not connected";
  775.         break;
  776. #endif
  777. #ifdef ESOCKTNOSUPPORT
  778.     case ESOCKTNOSUPPORT:
  779.         error = "Socket type not supported";
  780.         break;
  781. #endif
  782. #ifdef EISCONN
  783.     case EISCONN:
  784.         error = "Socket is already connected";
  785.         break;
  786. #endif
  787. #ifdef ECANCELED
  788.     case ECANCELED:
  789.         error = "Operation canceled";
  790.         break;
  791. #endif
  792. #ifdef ENOTRECOVERABLE
  793.     case ENOTRECOVERABLE:
  794.         error = "State not recoverable";
  795.         break;
  796. #endif
  797. #ifdef EOWNERDEAD
  798.     case EOWNERDEAD:
  799.         error = "Previous owner died";
  800.         break;
  801. #endif
  802. #ifdef ESTRPIPE
  803.     case ESTRPIPE:
  804.         error = "Streams pipe error";
  805.         break;
  806. #endif
  807. #if defined(EOPNOTSUPP) && (!defined(ENOTSUP) || (ENOTSUP != EOPNOTSUPP))
  808.     case EOPNOTSUPP:
  809.         error = "Operation not supported on socket";
  810.         break;
  811. #endif
  812. #ifdef EMSGSIZE
  813.     case EMSGSIZE:
  814.         error = "Message too long";
  815.         break;
  816. #endif
  817. #ifdef ETIMEDOUT
  818.     case ETIMEDOUT:
  819.         error = "Connection timed out";
  820.         break;
  821. #endif
  822.     default:
  823.       if (!errptr)
  824.         errptr = &ptr->_errno;
  825.       if ((error = _user_strerror (errnum, internal, errptr)) == 0)
  826.         error = "";
  827.       break;
  828.     }
  829.  
  830.   return error;
  831. }
  832.  
  833. char *
  834. _DEFUN(strerror, (int),
  835.        int errnum)
  836. {
  837.   return _strerror_r (_REENT, errnum, 0, NULL);
  838. }
  839.