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