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