strerror.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /* strerror.c --- POSIX compatible system error routine
  2. Copyright (C) 2007-2008 Free Software Foundation, Inc.
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. #include <config.h>
  14. #include <string.h>
  15. #if REPLACE_STRERROR
  16. # include <errno.h>
  17. # include <stdio.h>
  18. # if GNULIB_defined_ESOCK /* native Windows platforms */
  19. # if HAVE_WINSOCK2_H
  20. # include <winsock2.h>
  21. # endif
  22. # endif
  23. # include "intprops.h"
  24. # undef strerror
  25. # if ! HAVE_DECL_STRERROR
  26. # define strerror(n) NULL
  27. # endif
  28. char *
  29. rpl_strerror (int n)
  30. {
  31. /* These error messages are taken from glibc/sysdeps/gnu/errlist.c. */
  32. switch (n)
  33. {
  34. # if GNULIB_defined_ETXTBSY
  35. case ETXTBSY:
  36. return "Text file busy";
  37. # endif
  38. # if GNULIB_defined_ESOCK /* native Windows platforms */
  39. /* EWOULDBLOCK is the same as EAGAIN. */
  40. case EINPROGRESS:
  41. return "Operation now in progress";
  42. case EALREADY:
  43. return "Operation already in progress";
  44. case ENOTSOCK:
  45. return "Socket operation on non-socket";
  46. case EDESTADDRREQ:
  47. return "Destination address required";
  48. case EMSGSIZE:
  49. return "Message too long";
  50. case EPROTOTYPE:
  51. return "Protocol wrong type for socket";
  52. case ENOPROTOOPT:
  53. return "Protocol not available";
  54. case EPROTONOSUPPORT:
  55. return "Protocol not supported";
  56. case ESOCKTNOSUPPORT:
  57. return "Socket type not supported";
  58. case EOPNOTSUPP:
  59. return "Operation not supported";
  60. case EPFNOSUPPORT:
  61. return "Protocol family not supported";
  62. case EAFNOSUPPORT:
  63. return "Address family not supported by protocol";
  64. case EADDRINUSE:
  65. return "Address already in use";
  66. case EADDRNOTAVAIL:
  67. return "Cannot assign requested address";
  68. case ENETDOWN:
  69. return "Network is down";
  70. case ENETUNREACH:
  71. return "Network is unreachable";
  72. case ENETRESET:
  73. return "Network dropped connection on reset";
  74. case ECONNABORTED:
  75. return "Software caused connection abort";
  76. case ECONNRESET:
  77. return "Connection reset by peer";
  78. case ENOBUFS:
  79. return "No buffer space available";
  80. case EISCONN:
  81. return "Transport endpoint is already connected";
  82. case ENOTCONN:
  83. return "Transport endpoint is not connected";
  84. case ESHUTDOWN:
  85. return "Cannot send after transport endpoint shutdown";
  86. case ETOOMANYREFS:
  87. return "Too many references: cannot splice";
  88. case ETIMEDOUT:
  89. return "Connection timed out";
  90. case ECONNREFUSED:
  91. return "Connection refused";
  92. case ELOOP:
  93. return "Too many levels of symbolic links";
  94. case EHOSTDOWN:
  95. return "Host is down";
  96. case EHOSTUNREACH:
  97. return "No route to host";
  98. case EPROCLIM:
  99. return "Too many processes";
  100. case EUSERS:
  101. return "Too many users";
  102. case EDQUOT:
  103. return "Disk quota exceeded";
  104. case ESTALE:
  105. return "Stale NFS file handle";
  106. case EREMOTE:
  107. return "Object is remote";
  108. # if HAVE_WINSOCK2_H
  109. /* WSA_INVALID_HANDLE maps to EBADF */
  110. /* WSA_NOT_ENOUGH_MEMORY maps to ENOMEM */
  111. /* WSA_INVALID_PARAMETER maps to EINVAL */
  112. case WSA_OPERATION_ABORTED:
  113. return "Overlapped operation aborted";
  114. case WSA_IO_INCOMPLETE:
  115. return "Overlapped I/O event object not in signaled state";
  116. case WSA_IO_PENDING:
  117. return "Overlapped operations will complete later";
  118. /* WSAEINTR maps to EINTR */
  119. /* WSAEBADF maps to EBADF */
  120. /* WSAEACCES maps to EACCES */
  121. /* WSAEFAULT maps to EFAULT */
  122. /* WSAEINVAL maps to EINVAL */
  123. /* WSAEMFILE maps to EMFILE */
  124. /* WSAEWOULDBLOCK maps to EWOULDBLOCK */
  125. /* WSAEINPROGRESS is EINPROGRESS */
  126. /* WSAEALREADY is EALREADY */
  127. /* WSAENOTSOCK is ENOTSOCK */
  128. /* WSAEDESTADDRREQ is EDESTADDRREQ */
  129. /* WSAEMSGSIZE is EMSGSIZE */
  130. /* WSAEPROTOTYPE is EPROTOTYPE */
  131. /* WSAENOPROTOOPT is ENOPROTOOPT */
  132. /* WSAEPROTONOSUPPORT is EPROTONOSUPPORT */
  133. /* WSAESOCKTNOSUPPORT is ESOCKTNOSUPPORT */
  134. /* WSAEOPNOTSUPP is EOPNOTSUPP */
  135. /* WSAEPFNOSUPPORT is EPFNOSUPPORT */
  136. /* WSAEAFNOSUPPORT is EAFNOSUPPORT */
  137. /* WSAEADDRINUSE is EADDRINUSE */
  138. /* WSAEADDRNOTAVAIL is EADDRNOTAVAIL */
  139. /* WSAENETDOWN is ENETDOWN */
  140. /* WSAENETUNREACH is ENETUNREACH */
  141. /* WSAENETRESET is ENETRESET */
  142. /* WSAECONNABORTED is ECONNABORTED */
  143. /* WSAECONNRESET is ECONNRESET */
  144. /* WSAENOBUFS is ENOBUFS */
  145. /* WSAEISCONN is EISCONN */
  146. /* WSAENOTCONN is ENOTCONN */
  147. /* WSAESHUTDOWN is ESHUTDOWN */
  148. /* WSAETOOMANYREFS is ETOOMANYREFS */
  149. /* WSAETIMEDOUT is ETIMEDOUT */
  150. /* WSAECONNREFUSED is ECONNREFUSED */
  151. /* WSAELOOP is ELOOP */
  152. /* WSAENAMETOOLONG maps to ENAMETOOLONG */
  153. /* WSAEHOSTDOWN is EHOSTDOWN */
  154. /* WSAEHOSTUNREACH is EHOSTUNREACH */
  155. /* WSAENOTEMPTY maps to ENOTEMPTY */
  156. /* WSAEPROCLIM is EPROCLIM */
  157. /* WSAEUSERS is EUSERS */
  158. /* WSAEDQUOT is EDQUOT */
  159. /* WSAESTALE is ESTALE */
  160. /* WSAEREMOTE is EREMOTE */
  161. case WSASYSNOTREADY:
  162. return "Network subsystem is unavailable";
  163. case WSAVERNOTSUPPORTED:
  164. return "Winsock.dll version out of range";
  165. case WSANOTINITIALISED:
  166. return "Successful WSAStartup not yet performed";
  167. case WSAEDISCON:
  168. return "Graceful shutdown in progress";
  169. case WSAENOMORE: case WSA_E_NO_MORE:
  170. return "No more results";
  171. case WSAECANCELLED: case WSA_E_CANCELLED:
  172. return "Call was canceled";
  173. case WSAEINVALIDPROCTABLE:
  174. return "Procedure call table is invalid";
  175. case WSAEINVALIDPROVIDER:
  176. return "Service provider is invalid";
  177. case WSAEPROVIDERFAILEDINIT:
  178. return "Service provider failed to initialize";
  179. case WSASYSCALLFAILURE:
  180. return "System call failure";
  181. case WSASERVICE_NOT_FOUND:
  182. return "Service not found";
  183. case WSATYPE_NOT_FOUND:
  184. return "Class type not found";
  185. case WSAEREFUSED:
  186. return "Database query was refused";
  187. case WSAHOST_NOT_FOUND:
  188. return "Host not found";
  189. case WSATRY_AGAIN:
  190. return "Nonauthoritative host not found";
  191. case WSANO_RECOVERY:
  192. return "Nonrecoverable error";
  193. case WSANO_DATA:
  194. return "Valid name, no data record of requested type";
  195. /* WSA_QOS_* omitted */
  196. # endif
  197. # endif
  198. # if GNULIB_defined_ENOMSG
  199. case ENOMSG:
  200. return "No message of desired type";
  201. # endif
  202. # if GNULIB_defined_EIDRM
  203. case EIDRM:
  204. return "Identifier removed";
  205. # endif
  206. # if GNULIB_defined_ENOLINK
  207. case ENOLINK:
  208. return "Link has been severed";
  209. # endif
  210. # if GNULIB_defined_EPROTO
  211. case EPROTO:
  212. return "Protocol error";
  213. # endif
  214. # if GNULIB_defined_EMULTIHOP
  215. case EMULTIHOP:
  216. return "Multihop attempted";
  217. # endif
  218. # if GNULIB_defined_EBADMSG
  219. case EBADMSG:
  220. return "Bad message";
  221. # endif
  222. # if GNULIB_defined_EOVERFLOW
  223. case EOVERFLOW:
  224. return "Value too large for defined data type";
  225. # endif
  226. # if GNULIB_defined_ENOTSUP
  227. case ENOTSUP:
  228. return "Not supported";
  229. # endif
  230. # if GNULIB_defined_
  231. case ECANCELED:
  232. return "Operation canceled";
  233. # endif
  234. }
  235. {
  236. char *result = strerror (n);
  237. if (result == NULL || result[0] == '\0')
  238. {
  239. static char const fmt[] = "Unknown error (%d)";
  240. static char mesg[sizeof fmt + INT_STRLEN_BOUND (n)];
  241. sprintf (mesg, fmt, n);
  242. return mesg;
  243. }
  244. return result;
  245. }
  246. }
  247. #endif