1200fbe8dSJohn Marino /* strerror-override.c --- POSIX compatible system error routine 2200fbe8dSJohn Marino 3*09d4459fSDaniel Fojt Copyright (C) 2010-2020 Free Software Foundation, Inc. 4200fbe8dSJohn Marino 5200fbe8dSJohn Marino This program is free software: you can redistribute it and/or modify 6200fbe8dSJohn Marino it under the terms of the GNU General Public License as published by 7200fbe8dSJohn Marino the Free Software Foundation; either version 3 of the License, or 8200fbe8dSJohn Marino (at your option) any later version. 9200fbe8dSJohn Marino 10200fbe8dSJohn Marino This program is distributed in the hope that it will be useful, 11200fbe8dSJohn Marino but WITHOUT ANY WARRANTY; without even the implied warranty of 12200fbe8dSJohn Marino MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13200fbe8dSJohn Marino GNU General Public License for more details. 14200fbe8dSJohn Marino 15200fbe8dSJohn Marino You should have received a copy of the GNU General Public License 16*09d4459fSDaniel Fojt along with this program. If not, see <https://www.gnu.org/licenses/>. */ 17200fbe8dSJohn Marino 18200fbe8dSJohn Marino /* Written by Bruno Haible <bruno@clisp.org>, 2010. */ 19200fbe8dSJohn Marino 20200fbe8dSJohn Marino #include <config.h> 21200fbe8dSJohn Marino 22200fbe8dSJohn Marino #include "strerror-override.h" 23200fbe8dSJohn Marino 24200fbe8dSJohn Marino #include <errno.h> 25200fbe8dSJohn Marino 26cf28ed85SJohn Marino #if GNULIB_defined_EWINSOCK /* native Windows platforms */ 27200fbe8dSJohn Marino # if HAVE_WINSOCK2_H 28200fbe8dSJohn Marino # include <winsock2.h> 29200fbe8dSJohn Marino # endif 30200fbe8dSJohn Marino #endif 31200fbe8dSJohn Marino 32200fbe8dSJohn Marino /* If ERRNUM maps to an errno value defined by gnulib, return a string 33200fbe8dSJohn Marino describing the error. Otherwise return NULL. */ 34200fbe8dSJohn Marino const char * strerror_override(int errnum)35200fbe8dSJohn Marinostrerror_override (int errnum) 36200fbe8dSJohn Marino { 37200fbe8dSJohn Marino /* These error messages are taken from glibc/sysdeps/gnu/errlist.c. */ 38200fbe8dSJohn Marino switch (errnum) 39200fbe8dSJohn Marino { 40cf28ed85SJohn Marino #if REPLACE_STRERROR_0 41cf28ed85SJohn Marino case 0: 42cf28ed85SJohn Marino return "Success"; 43200fbe8dSJohn Marino #endif 44200fbe8dSJohn Marino 45cf28ed85SJohn Marino #if GNULIB_defined_ESOCK /* native Windows platforms with older <errno.h> */ 46200fbe8dSJohn Marino case EINPROGRESS: 47cf28ed85SJohn Marino return "Operation now in progress"; 48200fbe8dSJohn Marino case EALREADY: 49cf28ed85SJohn Marino return "Operation already in progress"; 50200fbe8dSJohn Marino case ENOTSOCK: 51cf28ed85SJohn Marino return "Socket operation on non-socket"; 52200fbe8dSJohn Marino case EDESTADDRREQ: 53cf28ed85SJohn Marino return "Destination address required"; 54200fbe8dSJohn Marino case EMSGSIZE: 55cf28ed85SJohn Marino return "Message too long"; 56200fbe8dSJohn Marino case EPROTOTYPE: 57cf28ed85SJohn Marino return "Protocol wrong type for socket"; 58200fbe8dSJohn Marino case ENOPROTOOPT: 59cf28ed85SJohn Marino return "Protocol not available"; 60200fbe8dSJohn Marino case EPROTONOSUPPORT: 61cf28ed85SJohn Marino return "Protocol not supported"; 62200fbe8dSJohn Marino case EOPNOTSUPP: 63cf28ed85SJohn Marino return "Operation not supported"; 64200fbe8dSJohn Marino case EAFNOSUPPORT: 65cf28ed85SJohn Marino return "Address family not supported by protocol"; 66200fbe8dSJohn Marino case EADDRINUSE: 67cf28ed85SJohn Marino return "Address already in use"; 68200fbe8dSJohn Marino case EADDRNOTAVAIL: 69cf28ed85SJohn Marino return "Cannot assign requested address"; 70200fbe8dSJohn Marino case ENETDOWN: 71cf28ed85SJohn Marino return "Network is down"; 72200fbe8dSJohn Marino case ENETUNREACH: 73cf28ed85SJohn Marino return "Network is unreachable"; 74200fbe8dSJohn Marino case ECONNRESET: 75cf28ed85SJohn Marino return "Connection reset by peer"; 76200fbe8dSJohn Marino case ENOBUFS: 77cf28ed85SJohn Marino return "No buffer space available"; 78200fbe8dSJohn Marino case EISCONN: 79cf28ed85SJohn Marino return "Transport endpoint is already connected"; 80200fbe8dSJohn Marino case ENOTCONN: 81cf28ed85SJohn Marino return "Transport endpoint is not connected"; 82200fbe8dSJohn Marino case ETIMEDOUT: 83cf28ed85SJohn Marino return "Connection timed out"; 84200fbe8dSJohn Marino case ECONNREFUSED: 85cf28ed85SJohn Marino return "Connection refused"; 86200fbe8dSJohn Marino case ELOOP: 87cf28ed85SJohn Marino return "Too many levels of symbolic links"; 88200fbe8dSJohn Marino case EHOSTUNREACH: 89cf28ed85SJohn Marino return "No route to host"; 90cf28ed85SJohn Marino case EWOULDBLOCK: 91cf28ed85SJohn Marino return "Operation would block"; 92a8597f6cSJohn Marino #endif 93a8597f6cSJohn Marino #if GNULIB_defined_ESTREAMS /* native Windows platforms with older <errno.h> */ 94cf28ed85SJohn Marino case ETXTBSY: 95cf28ed85SJohn Marino return "Text file busy"; 96cf28ed85SJohn Marino case ENODATA: 97cf28ed85SJohn Marino return "No data available"; 98cf28ed85SJohn Marino case ENOSR: 99cf28ed85SJohn Marino return "Out of streams resources"; 100cf28ed85SJohn Marino case ENOSTR: 101cf28ed85SJohn Marino return "Device not a stream"; 102cf28ed85SJohn Marino case ETIME: 103cf28ed85SJohn Marino return "Timer expired"; 104cf28ed85SJohn Marino case EOTHER: 105cf28ed85SJohn Marino return "Other error"; 106cf28ed85SJohn Marino #endif 107cf28ed85SJohn Marino #if GNULIB_defined_EWINSOCK /* native Windows platforms */ 108cf28ed85SJohn Marino case ESOCKTNOSUPPORT: 109cf28ed85SJohn Marino return "Socket type not supported"; 110cf28ed85SJohn Marino case EPFNOSUPPORT: 111cf28ed85SJohn Marino return "Protocol family not supported"; 112cf28ed85SJohn Marino case ESHUTDOWN: 113cf28ed85SJohn Marino return "Cannot send after transport endpoint shutdown"; 114cf28ed85SJohn Marino case ETOOMANYREFS: 115cf28ed85SJohn Marino return "Too many references: cannot splice"; 116cf28ed85SJohn Marino case EHOSTDOWN: 117cf28ed85SJohn Marino return "Host is down"; 118200fbe8dSJohn Marino case EPROCLIM: 119cf28ed85SJohn Marino return "Too many processes"; 120200fbe8dSJohn Marino case EUSERS: 121cf28ed85SJohn Marino return "Too many users"; 122200fbe8dSJohn Marino case EDQUOT: 123cf28ed85SJohn Marino return "Disk quota exceeded"; 124200fbe8dSJohn Marino case ESTALE: 125cf28ed85SJohn Marino return "Stale NFS file handle"; 126200fbe8dSJohn Marino case EREMOTE: 127cf28ed85SJohn Marino return "Object is remote"; 128200fbe8dSJohn Marino # if HAVE_WINSOCK2_H 129200fbe8dSJohn Marino /* WSA_INVALID_HANDLE maps to EBADF */ 130200fbe8dSJohn Marino /* WSA_NOT_ENOUGH_MEMORY maps to ENOMEM */ 131200fbe8dSJohn Marino /* WSA_INVALID_PARAMETER maps to EINVAL */ 132200fbe8dSJohn Marino case WSA_OPERATION_ABORTED: 133cf28ed85SJohn Marino return "Overlapped operation aborted"; 134200fbe8dSJohn Marino case WSA_IO_INCOMPLETE: 135cf28ed85SJohn Marino return "Overlapped I/O event object not in signaled state"; 136200fbe8dSJohn Marino case WSA_IO_PENDING: 137cf28ed85SJohn Marino return "Overlapped operations will complete later"; 138200fbe8dSJohn Marino /* WSAEINTR maps to EINTR */ 139200fbe8dSJohn Marino /* WSAEBADF maps to EBADF */ 140200fbe8dSJohn Marino /* WSAEACCES maps to EACCES */ 141200fbe8dSJohn Marino /* WSAEFAULT maps to EFAULT */ 142200fbe8dSJohn Marino /* WSAEINVAL maps to EINVAL */ 143200fbe8dSJohn Marino /* WSAEMFILE maps to EMFILE */ 144200fbe8dSJohn Marino /* WSAEWOULDBLOCK maps to EWOULDBLOCK */ 145cf28ed85SJohn Marino /* WSAEINPROGRESS maps to EINPROGRESS */ 146cf28ed85SJohn Marino /* WSAEALREADY maps to EALREADY */ 147cf28ed85SJohn Marino /* WSAENOTSOCK maps to ENOTSOCK */ 148cf28ed85SJohn Marino /* WSAEDESTADDRREQ maps to EDESTADDRREQ */ 149cf28ed85SJohn Marino /* WSAEMSGSIZE maps to EMSGSIZE */ 150cf28ed85SJohn Marino /* WSAEPROTOTYPE maps to EPROTOTYPE */ 151cf28ed85SJohn Marino /* WSAENOPROTOOPT maps to ENOPROTOOPT */ 152cf28ed85SJohn Marino /* WSAEPROTONOSUPPORT maps to EPROTONOSUPPORT */ 153200fbe8dSJohn Marino /* WSAESOCKTNOSUPPORT is ESOCKTNOSUPPORT */ 154cf28ed85SJohn Marino /* WSAEOPNOTSUPP maps to EOPNOTSUPP */ 155200fbe8dSJohn Marino /* WSAEPFNOSUPPORT is EPFNOSUPPORT */ 156cf28ed85SJohn Marino /* WSAEAFNOSUPPORT maps to EAFNOSUPPORT */ 157cf28ed85SJohn Marino /* WSAEADDRINUSE maps to EADDRINUSE */ 158cf28ed85SJohn Marino /* WSAEADDRNOTAVAIL maps to EADDRNOTAVAIL */ 159cf28ed85SJohn Marino /* WSAENETDOWN maps to ENETDOWN */ 160cf28ed85SJohn Marino /* WSAENETUNREACH maps to ENETUNREACH */ 161cf28ed85SJohn Marino /* WSAENETRESET maps to ENETRESET */ 162cf28ed85SJohn Marino /* WSAECONNABORTED maps to ECONNABORTED */ 163cf28ed85SJohn Marino /* WSAECONNRESET maps to ECONNRESET */ 164cf28ed85SJohn Marino /* WSAENOBUFS maps to ENOBUFS */ 165cf28ed85SJohn Marino /* WSAEISCONN maps to EISCONN */ 166cf28ed85SJohn Marino /* WSAENOTCONN maps to ENOTCONN */ 167200fbe8dSJohn Marino /* WSAESHUTDOWN is ESHUTDOWN */ 168200fbe8dSJohn Marino /* WSAETOOMANYREFS is ETOOMANYREFS */ 169cf28ed85SJohn Marino /* WSAETIMEDOUT maps to ETIMEDOUT */ 170cf28ed85SJohn Marino /* WSAECONNREFUSED maps to ECONNREFUSED */ 171cf28ed85SJohn Marino /* WSAELOOP maps to ELOOP */ 172200fbe8dSJohn Marino /* WSAENAMETOOLONG maps to ENAMETOOLONG */ 173200fbe8dSJohn Marino /* WSAEHOSTDOWN is EHOSTDOWN */ 174cf28ed85SJohn Marino /* WSAEHOSTUNREACH maps to EHOSTUNREACH */ 175200fbe8dSJohn Marino /* WSAENOTEMPTY maps to ENOTEMPTY */ 176200fbe8dSJohn Marino /* WSAEPROCLIM is EPROCLIM */ 177200fbe8dSJohn Marino /* WSAEUSERS is EUSERS */ 178200fbe8dSJohn Marino /* WSAEDQUOT is EDQUOT */ 179200fbe8dSJohn Marino /* WSAESTALE is ESTALE */ 180200fbe8dSJohn Marino /* WSAEREMOTE is EREMOTE */ 181200fbe8dSJohn Marino case WSASYSNOTREADY: 182cf28ed85SJohn Marino return "Network subsystem is unavailable"; 183200fbe8dSJohn Marino case WSAVERNOTSUPPORTED: 184cf28ed85SJohn Marino return "Winsock.dll version out of range"; 185200fbe8dSJohn Marino case WSANOTINITIALISED: 186cf28ed85SJohn Marino return "Successful WSAStartup not yet performed"; 187200fbe8dSJohn Marino case WSAEDISCON: 188cf28ed85SJohn Marino return "Graceful shutdown in progress"; 189200fbe8dSJohn Marino case WSAENOMORE: case WSA_E_NO_MORE: 190cf28ed85SJohn Marino return "No more results"; 191200fbe8dSJohn Marino case WSAECANCELLED: case WSA_E_CANCELLED: 192cf28ed85SJohn Marino return "Call was canceled"; 193200fbe8dSJohn Marino case WSAEINVALIDPROCTABLE: 194cf28ed85SJohn Marino return "Procedure call table is invalid"; 195200fbe8dSJohn Marino case WSAEINVALIDPROVIDER: 196cf28ed85SJohn Marino return "Service provider is invalid"; 197200fbe8dSJohn Marino case WSAEPROVIDERFAILEDINIT: 198cf28ed85SJohn Marino return "Service provider failed to initialize"; 199200fbe8dSJohn Marino case WSASYSCALLFAILURE: 200cf28ed85SJohn Marino return "System call failure"; 201200fbe8dSJohn Marino case WSASERVICE_NOT_FOUND: 202cf28ed85SJohn Marino return "Service not found"; 203200fbe8dSJohn Marino case WSATYPE_NOT_FOUND: 204cf28ed85SJohn Marino return "Class type not found"; 205200fbe8dSJohn Marino case WSAEREFUSED: 206cf28ed85SJohn Marino return "Database query was refused"; 207200fbe8dSJohn Marino case WSAHOST_NOT_FOUND: 208cf28ed85SJohn Marino return "Host not found"; 209200fbe8dSJohn Marino case WSATRY_AGAIN: 210cf28ed85SJohn Marino return "Nonauthoritative host not found"; 211200fbe8dSJohn Marino case WSANO_RECOVERY: 212cf28ed85SJohn Marino return "Nonrecoverable error"; 213200fbe8dSJohn Marino case WSANO_DATA: 214cf28ed85SJohn Marino return "Valid name, no data record of requested type"; 215200fbe8dSJohn Marino /* WSA_QOS_* omitted */ 216200fbe8dSJohn Marino # endif 217200fbe8dSJohn Marino #endif 218200fbe8dSJohn Marino 219200fbe8dSJohn Marino #if GNULIB_defined_ENOMSG 220200fbe8dSJohn Marino case ENOMSG: 221cf28ed85SJohn Marino return "No message of desired type"; 222200fbe8dSJohn Marino #endif 223200fbe8dSJohn Marino 224200fbe8dSJohn Marino #if GNULIB_defined_EIDRM 225200fbe8dSJohn Marino case EIDRM: 226cf28ed85SJohn Marino return "Identifier removed"; 227200fbe8dSJohn Marino #endif 228200fbe8dSJohn Marino 229200fbe8dSJohn Marino #if GNULIB_defined_ENOLINK 230200fbe8dSJohn Marino case ENOLINK: 231cf28ed85SJohn Marino return "Link has been severed"; 232200fbe8dSJohn Marino #endif 233200fbe8dSJohn Marino 234200fbe8dSJohn Marino #if GNULIB_defined_EPROTO 235200fbe8dSJohn Marino case EPROTO: 236cf28ed85SJohn Marino return "Protocol error"; 237200fbe8dSJohn Marino #endif 238200fbe8dSJohn Marino 239200fbe8dSJohn Marino #if GNULIB_defined_EMULTIHOP 240200fbe8dSJohn Marino case EMULTIHOP: 241cf28ed85SJohn Marino return "Multihop attempted"; 242200fbe8dSJohn Marino #endif 243200fbe8dSJohn Marino 244200fbe8dSJohn Marino #if GNULIB_defined_EBADMSG 245200fbe8dSJohn Marino case EBADMSG: 246cf28ed85SJohn Marino return "Bad message"; 247200fbe8dSJohn Marino #endif 248200fbe8dSJohn Marino 249200fbe8dSJohn Marino #if GNULIB_defined_EOVERFLOW 250200fbe8dSJohn Marino case EOVERFLOW: 251cf28ed85SJohn Marino return "Value too large for defined data type"; 252200fbe8dSJohn Marino #endif 253200fbe8dSJohn Marino 254200fbe8dSJohn Marino #if GNULIB_defined_ENOTSUP 255200fbe8dSJohn Marino case ENOTSUP: 256cf28ed85SJohn Marino return "Not supported"; 257cf28ed85SJohn Marino #endif 258cf28ed85SJohn Marino 259cf28ed85SJohn Marino #if GNULIB_defined_ENETRESET 260cf28ed85SJohn Marino case ENETRESET: 261cf28ed85SJohn Marino return "Network dropped connection on reset"; 262cf28ed85SJohn Marino #endif 263cf28ed85SJohn Marino 264cf28ed85SJohn Marino #if GNULIB_defined_ECONNABORTED 265cf28ed85SJohn Marino case ECONNABORTED: 266cf28ed85SJohn Marino return "Software caused connection abort"; 267200fbe8dSJohn Marino #endif 268200fbe8dSJohn Marino 269200fbe8dSJohn Marino #if GNULIB_defined_ESTALE 270200fbe8dSJohn Marino case ESTALE: 271cf28ed85SJohn Marino return "Stale NFS file handle"; 272200fbe8dSJohn Marino #endif 273200fbe8dSJohn Marino 274200fbe8dSJohn Marino #if GNULIB_defined_EDQUOT 275200fbe8dSJohn Marino case EDQUOT: 276cf28ed85SJohn Marino return "Disk quota exceeded"; 277200fbe8dSJohn Marino #endif 278200fbe8dSJohn Marino 279200fbe8dSJohn Marino #if GNULIB_defined_ECANCELED 280200fbe8dSJohn Marino case ECANCELED: 281cf28ed85SJohn Marino return "Operation canceled"; 282200fbe8dSJohn Marino #endif 283200fbe8dSJohn Marino 284a8597f6cSJohn Marino #if GNULIB_defined_EOWNERDEAD 285a8597f6cSJohn Marino case EOWNERDEAD: 286a8597f6cSJohn Marino return "Owner died"; 287a8597f6cSJohn Marino #endif 288a8597f6cSJohn Marino 289a8597f6cSJohn Marino #if GNULIB_defined_ENOTRECOVERABLE 290a8597f6cSJohn Marino case ENOTRECOVERABLE: 291a8597f6cSJohn Marino return "State not recoverable"; 292a8597f6cSJohn Marino #endif 293a8597f6cSJohn Marino 294680a9cb8SJohn Marino #if GNULIB_defined_EILSEQ 295680a9cb8SJohn Marino case EILSEQ: 296680a9cb8SJohn Marino return "Invalid or incomplete multibyte or wide character"; 297680a9cb8SJohn Marino #endif 298680a9cb8SJohn Marino 299cf28ed85SJohn Marino default: 300cf28ed85SJohn Marino return NULL; 301cf28ed85SJohn Marino } 302200fbe8dSJohn Marino } 303