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