1 /* strerror.c --- POSIX compatible system error routine
3 Copyright (C) 2007-2009 Free Software Foundation, Inc.
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.
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.
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/>. */
27 # if GNULIB_defined_ESOCK /* native Windows platforms */
29 # include <winsock2.h>
33 # include "intprops.h"
36 # if ! HAVE_DECL_STRERROR
37 # define strerror(n) NULL
43 char const *msg
= NULL
;
44 /* These error messages are taken from glibc/sysdeps/gnu/errlist.c. */
47 # if GNULIB_defined_ETXTBSY
49 msg
= "Text file busy";
53 # if GNULIB_defined_ESOCK /* native Windows platforms */
54 /* EWOULDBLOCK is the same as EAGAIN. */
56 msg
= "Operation now in progress";
59 msg
= "Operation already in progress";
62 msg
= "Socket operation on non-socket";
65 msg
= "Destination address required";
68 msg
= "Message too long";
71 msg
= "Protocol wrong type for socket";
74 msg
= "Protocol not available";
77 msg
= "Protocol not supported";
80 msg
= "Socket type not supported";
83 msg
= "Operation not supported";
86 msg
= "Protocol family not supported";
89 msg
= "Address family not supported by protocol";
92 msg
= "Address already in use";
95 msg
= "Cannot assign requested address";
98 msg
= "Network is down";
101 msg
= "Network is unreachable";
104 msg
= "Network dropped connection on reset";
107 msg
= "Software caused connection abort";
110 msg
= "Connection reset by peer";
113 msg
= "No buffer space available";
116 msg
= "Transport endpoint is already connected";
119 msg
= "Transport endpoint is not connected";
122 msg
= "Cannot send after transport endpoint shutdown";
125 msg
= "Too many references: cannot splice";
128 msg
= "Connection timed out";
131 msg
= "Connection refused";
134 msg
= "Too many levels of symbolic links";
137 msg
= "Host is down";
140 msg
= "No route to host";
143 msg
= "Too many processes";
146 msg
= "Too many users";
149 msg
= "Disk quota exceeded";
152 msg
= "Stale NFS file handle";
155 msg
= "Object is remote";
158 /* WSA_INVALID_HANDLE maps to EBADF */
159 /* WSA_NOT_ENOUGH_MEMORY maps to ENOMEM */
160 /* WSA_INVALID_PARAMETER maps to EINVAL */
161 case WSA_OPERATION_ABORTED
:
162 msg
= "Overlapped operation aborted";
164 case WSA_IO_INCOMPLETE
:
165 msg
= "Overlapped I/O event object not in signaled state";
168 msg
= "Overlapped operations will complete later";
170 /* WSAEINTR maps to EINTR */
171 /* WSAEBADF maps to EBADF */
172 /* WSAEACCES maps to EACCES */
173 /* WSAEFAULT maps to EFAULT */
174 /* WSAEINVAL maps to EINVAL */
175 /* WSAEMFILE maps to EMFILE */
176 /* WSAEWOULDBLOCK maps to EWOULDBLOCK */
177 /* WSAEINPROGRESS is EINPROGRESS */
178 /* WSAEALREADY is EALREADY */
179 /* WSAENOTSOCK is ENOTSOCK */
180 /* WSAEDESTADDRREQ is EDESTADDRREQ */
181 /* WSAEMSGSIZE is EMSGSIZE */
182 /* WSAEPROTOTYPE is EPROTOTYPE */
183 /* WSAENOPROTOOPT is ENOPROTOOPT */
184 /* WSAEPROTONOSUPPORT is EPROTONOSUPPORT */
185 /* WSAESOCKTNOSUPPORT is ESOCKTNOSUPPORT */
186 /* WSAEOPNOTSUPP is EOPNOTSUPP */
187 /* WSAEPFNOSUPPORT is EPFNOSUPPORT */
188 /* WSAEAFNOSUPPORT is EAFNOSUPPORT */
189 /* WSAEADDRINUSE is EADDRINUSE */
190 /* WSAEADDRNOTAVAIL is EADDRNOTAVAIL */
191 /* WSAENETDOWN is ENETDOWN */
192 /* WSAENETUNREACH is ENETUNREACH */
193 /* WSAENETRESET is ENETRESET */
194 /* WSAECONNABORTED is ECONNABORTED */
195 /* WSAECONNRESET is ECONNRESET */
196 /* WSAENOBUFS is ENOBUFS */
197 /* WSAEISCONN is EISCONN */
198 /* WSAENOTCONN is ENOTCONN */
199 /* WSAESHUTDOWN is ESHUTDOWN */
200 /* WSAETOOMANYREFS is ETOOMANYREFS */
201 /* WSAETIMEDOUT is ETIMEDOUT */
202 /* WSAECONNREFUSED is ECONNREFUSED */
203 /* WSAELOOP is ELOOP */
204 /* WSAENAMETOOLONG maps to ENAMETOOLONG */
205 /* WSAEHOSTDOWN is EHOSTDOWN */
206 /* WSAEHOSTUNREACH is EHOSTUNREACH */
207 /* WSAENOTEMPTY maps to ENOTEMPTY */
208 /* WSAEPROCLIM is EPROCLIM */
209 /* WSAEUSERS is EUSERS */
210 /* WSAEDQUOT is EDQUOT */
211 /* WSAESTALE is ESTALE */
212 /* WSAEREMOTE is EREMOTE */
214 msg
= "Network subsystem is unavailable";
216 case WSAVERNOTSUPPORTED
:
217 msg
= "Winsock.dll version out of range";
219 case WSANOTINITIALISED
:
220 msg
= "Successful WSAStartup not yet performed";
223 msg
= "Graceful shutdown in progress";
225 case WSAENOMORE
: case WSA_E_NO_MORE
:
226 msg
= "No more results";
228 case WSAECANCELLED
: case WSA_E_CANCELLED
:
229 msg
= "Call was canceled";
231 case WSAEINVALIDPROCTABLE
:
232 msg
= "Procedure call table is invalid";
234 case WSAEINVALIDPROVIDER
:
235 msg
= "Service provider is invalid";
237 case WSAEPROVIDERFAILEDINIT
:
238 msg
= "Service provider failed to initialize";
240 case WSASYSCALLFAILURE
:
241 msg
= "System call failure";
243 case WSASERVICE_NOT_FOUND
:
244 msg
= "Service not found";
246 case WSATYPE_NOT_FOUND
:
247 msg
= "Class type not found";
250 msg
= "Database query was refused";
252 case WSAHOST_NOT_FOUND
:
253 msg
= "Host not found";
256 msg
= "Nonauthoritative host not found";
259 msg
= "Nonrecoverable error";
262 msg
= "Valid name, no data record of requested type";
264 /* WSA_QOS_* omitted */
268 # if GNULIB_defined_ENOMSG
270 msg
= "No message of desired type";
274 # if GNULIB_defined_EIDRM
276 msg
= "Identifier removed";
280 # if GNULIB_defined_ENOLINK
282 msg
= "Link has been severed";
286 # if GNULIB_defined_EPROTO
288 msg
= "Protocol error";
292 # if GNULIB_defined_EMULTIHOP
294 msg
= "Multihop attempted";
298 # if GNULIB_defined_EBADMSG
304 # if GNULIB_defined_EOVERFLOW
306 msg
= "Value too large for defined data type";
310 # if GNULIB_defined_ENOTSUP
312 msg
= "Not supported";
318 msg
= "Operation canceled";
327 char *result
= strerror (n
);
329 if (result
== NULL
|| result
[0] == '\0')
331 static char const fmt
[] = "Unknown error (%d)";
332 static char msg_buf
[sizeof fmt
+ INT_STRLEN_BOUND (n
)];
333 sprintf (msg_buf
, fmt
, n
);