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