strerror-override.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. /* strerror-override.c --- POSIX compatible system error routine
  2. Copyright (C) 2010-2013 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. /* Written by Bruno Haible <bruno@clisp.org>, 2010. */
  14. #include <config.h>
  15. #include "strerror-override.h"
  16. #include <errno.h>
  17. #if GNULIB_defined_EWINSOCK /* native Windows platforms */
  18. # if HAVE_WINSOCK2_H
  19. # include <winsock2.h>
  20. # endif
  21. #endif
  22. /* If ERRNUM maps to an errno value defined by gnulib, return a string
  23. describing the error. Otherwise return NULL. */
  24. const char *
  25. strerror_override (int errnum)
  26. {
  27. /* These error messages are taken from glibc/sysdeps/gnu/errlist.c. */
  28. switch (errnum)
  29. {
  30. #if REPLACE_STRERROR_0
  31. case 0:
  32. return "Success";
  33. #endif
  34. #if GNULIB_defined_ESOCK /* native Windows platforms with older <errno.h> */
  35. case EINPROGRESS:
  36. return "Operation now in progress";
  37. case EALREADY:
  38. return "Operation already in progress";
  39. case ENOTSOCK:
  40. return "Socket operation on non-socket";
  41. case EDESTADDRREQ:
  42. return "Destination address required";
  43. case EMSGSIZE:
  44. return "Message too long";
  45. case EPROTOTYPE:
  46. return "Protocol wrong type for socket";
  47. case ENOPROTOOPT:
  48. return "Protocol not available";
  49. case EPROTONOSUPPORT:
  50. return "Protocol not supported";
  51. case EOPNOTSUPP:
  52. return "Operation not supported";
  53. case EAFNOSUPPORT:
  54. return "Address family not supported by protocol";
  55. case EADDRINUSE:
  56. return "Address already in use";
  57. case EADDRNOTAVAIL:
  58. return "Cannot assign requested address";
  59. case ENETDOWN:
  60. return "Network is down";
  61. case ENETUNREACH:
  62. return "Network is unreachable";
  63. case ECONNRESET:
  64. return "Connection reset by peer";
  65. case ENOBUFS:
  66. return "No buffer space available";
  67. case EISCONN:
  68. return "Transport endpoint is already connected";
  69. case ENOTCONN:
  70. return "Transport endpoint is not connected";
  71. case ETIMEDOUT:
  72. return "Connection timed out";
  73. case ECONNREFUSED:
  74. return "Connection refused";
  75. case ELOOP:
  76. return "Too many levels of symbolic links";
  77. case EHOSTUNREACH:
  78. return "No route to host";
  79. case EWOULDBLOCK:
  80. return "Operation would block";
  81. #endif
  82. #if GNULIB_defined_ESTREAMS /* native Windows platforms with older <errno.h> */
  83. case ETXTBSY:
  84. return "Text file busy";
  85. case ENODATA:
  86. return "No data available";
  87. case ENOSR:
  88. return "Out of streams resources";
  89. case ENOSTR:
  90. return "Device not a stream";
  91. case ETIME:
  92. return "Timer expired";
  93. case EOTHER:
  94. return "Other error";
  95. #endif
  96. #if GNULIB_defined_EWINSOCK /* native Windows platforms */
  97. case ESOCKTNOSUPPORT:
  98. return "Socket type not supported";
  99. case EPFNOSUPPORT:
  100. return "Protocol family not supported";
  101. case ESHUTDOWN:
  102. return "Cannot send after transport endpoint shutdown";
  103. case ETOOMANYREFS:
  104. return "Too many references: cannot splice";
  105. case EHOSTDOWN:
  106. return "Host is down";
  107. case EPROCLIM:
  108. return "Too many processes";
  109. case EUSERS:
  110. return "Too many users";
  111. case EDQUOT:
  112. return "Disk quota exceeded";
  113. case ESTALE:
  114. return "Stale NFS file handle";
  115. case EREMOTE:
  116. return "Object is remote";
  117. # if HAVE_WINSOCK2_H
  118. /* WSA_INVALID_HANDLE maps to EBADF */
  119. /* WSA_NOT_ENOUGH_MEMORY maps to ENOMEM */
  120. /* WSA_INVALID_PARAMETER maps to EINVAL */
  121. case WSA_OPERATION_ABORTED:
  122. return "Overlapped operation aborted";
  123. case WSA_IO_INCOMPLETE:
  124. return "Overlapped I/O event object not in signaled state";
  125. case WSA_IO_PENDING:
  126. return "Overlapped operations will complete later";
  127. /* WSAEINTR maps to EINTR */
  128. /* WSAEBADF maps to EBADF */
  129. /* WSAEACCES maps to EACCES */
  130. /* WSAEFAULT maps to EFAULT */
  131. /* WSAEINVAL maps to EINVAL */
  132. /* WSAEMFILE maps to EMFILE */
  133. /* WSAEWOULDBLOCK maps to EWOULDBLOCK */
  134. /* WSAEINPROGRESS maps to EINPROGRESS */
  135. /* WSAEALREADY maps to EALREADY */
  136. /* WSAENOTSOCK maps to ENOTSOCK */
  137. /* WSAEDESTADDRREQ maps to EDESTADDRREQ */
  138. /* WSAEMSGSIZE maps to EMSGSIZE */
  139. /* WSAEPROTOTYPE maps to EPROTOTYPE */
  140. /* WSAENOPROTOOPT maps to ENOPROTOOPT */
  141. /* WSAEPROTONOSUPPORT maps to EPROTONOSUPPORT */
  142. /* WSAESOCKTNOSUPPORT is ESOCKTNOSUPPORT */
  143. /* WSAEOPNOTSUPP maps to EOPNOTSUPP */
  144. /* WSAEPFNOSUPPORT is EPFNOSUPPORT */
  145. /* WSAEAFNOSUPPORT maps to EAFNOSUPPORT */
  146. /* WSAEADDRINUSE maps to EADDRINUSE */
  147. /* WSAEADDRNOTAVAIL maps to EADDRNOTAVAIL */
  148. /* WSAENETDOWN maps to ENETDOWN */
  149. /* WSAENETUNREACH maps to ENETUNREACH */
  150. /* WSAENETRESET maps to ENETRESET */
  151. /* WSAECONNABORTED maps to ECONNABORTED */
  152. /* WSAECONNRESET maps to ECONNRESET */
  153. /* WSAENOBUFS maps to ENOBUFS */
  154. /* WSAEISCONN maps to EISCONN */
  155. /* WSAENOTCONN maps to ENOTCONN */
  156. /* WSAESHUTDOWN is ESHUTDOWN */
  157. /* WSAETOOMANYREFS is ETOOMANYREFS */
  158. /* WSAETIMEDOUT maps to ETIMEDOUT */
  159. /* WSAECONNREFUSED maps to ECONNREFUSED */
  160. /* WSAELOOP maps to ELOOP */
  161. /* WSAENAMETOOLONG maps to ENAMETOOLONG */
  162. /* WSAEHOSTDOWN is EHOSTDOWN */
  163. /* WSAEHOSTUNREACH maps to EHOSTUNREACH */
  164. /* WSAENOTEMPTY maps to ENOTEMPTY */
  165. /* WSAEPROCLIM is EPROCLIM */
  166. /* WSAEUSERS is EUSERS */
  167. /* WSAEDQUOT is EDQUOT */
  168. /* WSAESTALE is ESTALE */
  169. /* WSAEREMOTE is EREMOTE */
  170. case WSASYSNOTREADY:
  171. return "Network subsystem is unavailable";
  172. case WSAVERNOTSUPPORTED:
  173. return "Winsock.dll version out of range";
  174. case WSANOTINITIALISED:
  175. return "Successful WSAStartup not yet performed";
  176. case WSAEDISCON:
  177. return "Graceful shutdown in progress";
  178. case WSAENOMORE: case WSA_E_NO_MORE:
  179. return "No more results";
  180. case WSAECANCELLED: case WSA_E_CANCELLED:
  181. return "Call was canceled";
  182. case WSAEINVALIDPROCTABLE:
  183. return "Procedure call table is invalid";
  184. case WSAEINVALIDPROVIDER:
  185. return "Service provider is invalid";
  186. case WSAEPROVIDERFAILEDINIT:
  187. return "Service provider failed to initialize";
  188. case WSASYSCALLFAILURE:
  189. return "System call failure";
  190. case WSASERVICE_NOT_FOUND:
  191. return "Service not found";
  192. case WSATYPE_NOT_FOUND:
  193. return "Class type not found";
  194. case WSAEREFUSED:
  195. return "Database query was refused";
  196. case WSAHOST_NOT_FOUND:
  197. return "Host not found";
  198. case WSATRY_AGAIN:
  199. return "Nonauthoritative host not found";
  200. case WSANO_RECOVERY:
  201. return "Nonrecoverable error";
  202. case WSANO_DATA:
  203. return "Valid name, no data record of requested type";
  204. /* WSA_QOS_* omitted */
  205. # endif
  206. #endif
  207. #if GNULIB_defined_ENOMSG
  208. case ENOMSG:
  209. return "No message of desired type";
  210. #endif
  211. #if GNULIB_defined_EIDRM
  212. case EIDRM:
  213. return "Identifier removed";
  214. #endif
  215. #if GNULIB_defined_ENOLINK
  216. case ENOLINK:
  217. return "Link has been severed";
  218. #endif
  219. #if GNULIB_defined_EPROTO
  220. case EPROTO:
  221. return "Protocol error";
  222. #endif
  223. #if GNULIB_defined_EMULTIHOP
  224. case EMULTIHOP:
  225. return "Multihop attempted";
  226. #endif
  227. #if GNULIB_defined_EBADMSG
  228. case EBADMSG:
  229. return "Bad message";
  230. #endif
  231. #if GNULIB_defined_EOVERFLOW
  232. case EOVERFLOW:
  233. return "Value too large for defined data type";
  234. #endif
  235. #if GNULIB_defined_ENOTSUP
  236. case ENOTSUP:
  237. return "Not supported";
  238. #endif
  239. #if GNULIB_defined_ENETRESET
  240. case ENETRESET:
  241. return "Network dropped connection on reset";
  242. #endif
  243. #if GNULIB_defined_ECONNABORTED
  244. case ECONNABORTED:
  245. return "Software caused connection abort";
  246. #endif
  247. #if GNULIB_defined_ESTALE
  248. case ESTALE:
  249. return "Stale NFS file handle";
  250. #endif
  251. #if GNULIB_defined_EDQUOT
  252. case EDQUOT:
  253. return "Disk quota exceeded";
  254. #endif
  255. #if GNULIB_defined_ECANCELED
  256. case ECANCELED:
  257. return "Operation canceled";
  258. #endif
  259. #if GNULIB_defined_EOWNERDEAD
  260. case EOWNERDEAD:
  261. return "Owner died";
  262. #endif
  263. #if GNULIB_defined_ENOTRECOVERABLE
  264. case ENOTRECOVERABLE:
  265. return "State not recoverable";
  266. #endif
  267. #if GNULIB_defined_EILSEQ
  268. case EILSEQ:
  269. return "Invalid or incomplete multibyte or wide character";
  270. #endif
  271. default:
  272. return NULL;
  273. }
  274. }