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