1 /* strerror.c --- POSIX compatible system error routine
3 Copyright (C) 2007-2008 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 /* These error messages are taken from glibc/sysdeps/gnu/errlist.c. */
46 # if GNULIB_defined_ETXTBSY
48 return "Text file busy";
51 # if GNULIB_defined_ESOCK /* native Windows platforms */
52 /* EWOULDBLOCK is the same as EAGAIN. */
54 return "Operation now in progress";
56 return "Operation already in progress";
58 return "Socket operation on non-socket";
60 return "Destination address required";
62 return "Message too long";
64 return "Protocol wrong type for socket";
66 return "Protocol not available";
68 return "Protocol not supported";
70 return "Socket type not supported";
72 return "Operation not supported";
74 return "Protocol family not supported";
76 return "Address family not supported by protocol";
78 return "Address already in use";
80 return "Cannot assign requested address";
82 return "Network is down";
84 return "Network is unreachable";
86 return "Network dropped connection on reset";
88 return "Software caused connection abort";
90 return "Connection reset by peer";
92 return "No buffer space available";
94 return "Transport endpoint is already connected";
96 return "Transport endpoint is not connected";
98 return "Cannot send after transport endpoint shutdown";
100 return "Too many references: cannot splice";
102 return "Connection timed out";
104 return "Connection refused";
106 return "Too many levels of symbolic links";
108 return "Host is down";
110 return "No route to host";
112 return "Too many processes";
114 return "Too many users";
116 return "Disk quota exceeded";
118 return "Stale NFS file handle";
120 return "Object is remote";
122 /* WSA_INVALID_HANDLE maps to EBADF */
123 /* WSA_NOT_ENOUGH_MEMORY maps to ENOMEM */
124 /* WSA_INVALID_PARAMETER maps to EINVAL */
125 case WSA_OPERATION_ABORTED:
126 return "Overlapped operation aborted";
127 case WSA_IO_INCOMPLETE:
128 return "Overlapped I/O event object not in signaled state";
130 return "Overlapped operations will complete later";
131 /* WSAEINTR maps to EINTR */
132 /* WSAEBADF maps to EBADF */
133 /* WSAEACCES maps to EACCES */
134 /* WSAEFAULT maps to EFAULT */
135 /* WSAEINVAL maps to EINVAL */
136 /* WSAEMFILE maps to EMFILE */
137 /* WSAEWOULDBLOCK maps to EWOULDBLOCK */
138 /* WSAEINPROGRESS is EINPROGRESS */
139 /* WSAEALREADY is EALREADY */
140 /* WSAENOTSOCK is ENOTSOCK */
141 /* WSAEDESTADDRREQ is EDESTADDRREQ */
142 /* WSAEMSGSIZE is EMSGSIZE */
143 /* WSAEPROTOTYPE is EPROTOTYPE */
144 /* WSAENOPROTOOPT is ENOPROTOOPT */
145 /* WSAEPROTONOSUPPORT is EPROTONOSUPPORT */
146 /* WSAESOCKTNOSUPPORT is ESOCKTNOSUPPORT */
147 /* WSAEOPNOTSUPP is EOPNOTSUPP */
148 /* WSAEPFNOSUPPORT is EPFNOSUPPORT */
149 /* WSAEAFNOSUPPORT is EAFNOSUPPORT */
150 /* WSAEADDRINUSE is EADDRINUSE */
151 /* WSAEADDRNOTAVAIL is EADDRNOTAVAIL */
152 /* WSAENETDOWN is ENETDOWN */
153 /* WSAENETUNREACH is ENETUNREACH */
154 /* WSAENETRESET is ENETRESET */
155 /* WSAECONNABORTED is ECONNABORTED */
156 /* WSAECONNRESET is ECONNRESET */
157 /* WSAENOBUFS is ENOBUFS */
158 /* WSAEISCONN is EISCONN */
159 /* WSAENOTCONN is ENOTCONN */
160 /* WSAESHUTDOWN is ESHUTDOWN */
161 /* WSAETOOMANYREFS is ETOOMANYREFS */
162 /* WSAETIMEDOUT is ETIMEDOUT */
163 /* WSAECONNREFUSED is ECONNREFUSED */
164 /* WSAELOOP is ELOOP */
165 /* WSAENAMETOOLONG maps to ENAMETOOLONG */
166 /* WSAEHOSTDOWN is EHOSTDOWN */
167 /* WSAEHOSTUNREACH is EHOSTUNREACH */
168 /* WSAENOTEMPTY maps to ENOTEMPTY */
169 /* WSAEPROCLIM is EPROCLIM */
170 /* WSAEUSERS is EUSERS */
171 /* WSAEDQUOT is EDQUOT */
172 /* WSAESTALE is ESTALE */
173 /* WSAEREMOTE is EREMOTE */
175 return "Network subsystem is unavailable";
176 case WSAVERNOTSUPPORTED:
177 return "Winsock.dll version out of range";
178 case WSANOTINITIALISED:
179 return "Successful WSAStartup not yet performed";
181 return "Graceful shutdown in progress";
182 case WSAENOMORE: case WSA_E_NO_MORE:
183 return "No more results";
184 case WSAECANCELLED: case WSA_E_CANCELLED:
185 return "Call was canceled";
186 case WSAEINVALIDPROCTABLE:
187 return "Procedure call table is invalid";
188 case WSAEINVALIDPROVIDER:
189 return "Service provider is invalid";
190 case WSAEPROVIDERFAILEDINIT:
191 return "Service provider failed to initialize";
192 case WSASYSCALLFAILURE:
193 return "System call failure";
194 case WSASERVICE_NOT_FOUND:
195 return "Service not found";
196 case WSATYPE_NOT_FOUND:
197 return "Class type not found";
199 return "Database query was refused";
200 case WSAHOST_NOT_FOUND:
201 return "Host not found";
203 return "Nonauthoritative host not found";
205 return "Nonrecoverable error";
207 return "Valid name, no data record of requested type";
208 /* WSA_QOS_* omitted */
212 # if GNULIB_defined_ENOMSG
214 return "No message of desired type";
217 # if GNULIB_defined_EIDRM
219 return "Identifier removed";
222 # if GNULIB_defined_ENOLINK
224 return "Link has been severed";
227 # if GNULIB_defined_EPROTO
229 return "Protocol error";
232 # if GNULIB_defined_EMULTIHOP
234 return "Multihop attempted";
237 # if GNULIB_defined_EBADMSG
239 return "Bad message";
242 # if GNULIB_defined_EOVERFLOW
244 return "Value too large for defined data type";
247 # if GNULIB_defined_ENOTSUP
249 return "Not supported";
254 return "Operation canceled";
259 char *result = strerror (n);
261 if (result == NULL || result[0] == '\0')
263 static char const fmt[] = "Unknown error (%d)";
264 static char mesg[sizeof fmt + INT_STRLEN_BOUND (n)];
265 sprintf (mesg, fmt, n);