~ubuntu-branches/ubuntu/trusty/grub2/trusty-updates

« back to all changes in this revision

Viewing changes to grub-core/gnulib/strerror.c

Tags: upstream-1.99~20101122
ImportĀ upstreamĀ versionĀ 1.99~20101122

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* strerror.c --- POSIX compatible system error routine
 
2
 
 
3
   Copyright (C) 2007-2010 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
/* Use the system functions, not the gnulib overrides in this file.  */
 
36
# undef sprintf
 
37
 
 
38
# undef strerror
 
39
# if ! HAVE_DECL_STRERROR
 
40
#  define strerror(n) NULL
 
41
# endif
 
42
 
 
43
char *
 
44
rpl_strerror (int n)
 
45
{
 
46
  char const *msg = NULL;
 
47
  /* These error messages are taken from glibc/sysdeps/gnu/errlist.c.  */
 
48
  switch (n)
 
49
    {
 
50
# if GNULIB_defined_ETXTBSY
 
51
    case ETXTBSY:
 
52
      msg = "Text file busy";
 
53
      break;
 
54
# endif
 
55
 
 
56
# if GNULIB_defined_ESOCK /* native Windows platforms */
 
57
    /* EWOULDBLOCK is the same as EAGAIN.  */
 
58
    case EINPROGRESS:
 
59
      msg = "Operation now in progress";
 
60
      break;
 
61
    case EALREADY:
 
62
      msg = "Operation already in progress";
 
63
      break;
 
64
    case ENOTSOCK:
 
65
      msg = "Socket operation on non-socket";
 
66
      break;
 
67
    case EDESTADDRREQ:
 
68
      msg = "Destination address required";
 
69
      break;
 
70
    case EMSGSIZE:
 
71
      msg = "Message too long";
 
72
      break;
 
73
    case EPROTOTYPE:
 
74
      msg = "Protocol wrong type for socket";
 
75
      break;
 
76
    case ENOPROTOOPT:
 
77
      msg = "Protocol not available";
 
78
      break;
 
79
    case EPROTONOSUPPORT:
 
80
      msg = "Protocol not supported";
 
81
      break;
 
82
    case ESOCKTNOSUPPORT:
 
83
      msg = "Socket type not supported";
 
84
      break;
 
85
    case EOPNOTSUPP:
 
86
      msg = "Operation not supported";
 
87
      break;
 
88
    case EPFNOSUPPORT:
 
89
      msg = "Protocol family not supported";
 
90
      break;
 
91
    case EAFNOSUPPORT:
 
92
      msg = "Address family not supported by protocol";
 
93
      break;
 
94
    case EADDRINUSE:
 
95
      msg = "Address already in use";
 
96
      break;
 
97
    case EADDRNOTAVAIL:
 
98
      msg = "Cannot assign requested address";
 
99
      break;
 
100
    case ENETDOWN:
 
101
      msg = "Network is down";
 
102
      break;
 
103
    case ENETUNREACH:
 
104
      msg = "Network is unreachable";
 
105
      break;
 
106
    case ENETRESET:
 
107
      msg = "Network dropped connection on reset";
 
108
      break;
 
109
    case ECONNABORTED:
 
110
      msg = "Software caused connection abort";
 
111
      break;
 
112
    case ECONNRESET:
 
113
      msg = "Connection reset by peer";
 
114
      break;
 
115
    case ENOBUFS:
 
116
      msg = "No buffer space available";
 
117
      break;
 
118
    case EISCONN:
 
119
      msg = "Transport endpoint is already connected";
 
120
      break;
 
121
    case ENOTCONN:
 
122
      msg = "Transport endpoint is not connected";
 
123
      break;
 
124
    case ESHUTDOWN:
 
125
      msg = "Cannot send after transport endpoint shutdown";
 
126
      break;
 
127
    case ETOOMANYREFS:
 
128
      msg = "Too many references: cannot splice";
 
129
      break;
 
130
    case ETIMEDOUT:
 
131
      msg = "Connection timed out";
 
132
      break;
 
133
    case ECONNREFUSED:
 
134
      msg = "Connection refused";
 
135
      break;
 
136
    case ELOOP:
 
137
      msg = "Too many levels of symbolic links";
 
138
      break;
 
139
    case EHOSTDOWN:
 
140
      msg = "Host is down";
 
141
      break;
 
142
    case EHOSTUNREACH:
 
143
      msg = "No route to host";
 
144
      break;
 
145
    case EPROCLIM:
 
146
      msg = "Too many processes";
 
147
      break;
 
148
    case EUSERS:
 
149
      msg = "Too many users";
 
150
      break;
 
151
    case EDQUOT:
 
152
      msg = "Disk quota exceeded";
 
153
      break;
 
154
    case ESTALE:
 
155
      msg = "Stale NFS file handle";
 
156
      break;
 
157
    case EREMOTE:
 
158
      msg = "Object is remote";
 
159
      break;
 
160
#  if HAVE_WINSOCK2_H
 
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";
 
166
      break;
 
167
    case WSA_IO_INCOMPLETE:
 
168
      msg = "Overlapped I/O event object not in signaled state";
 
169
      break;
 
170
    case WSA_IO_PENDING:
 
171
      msg = "Overlapped operations will complete later";
 
172
      break;
 
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 */
 
216
    case WSASYSNOTREADY:
 
217
      msg = "Network subsystem is unavailable";
 
218
      break;
 
219
    case WSAVERNOTSUPPORTED:
 
220
      msg = "Winsock.dll version out of range";
 
221
      break;
 
222
    case WSANOTINITIALISED:
 
223
      msg = "Successful WSAStartup not yet performed";
 
224
      break;
 
225
    case WSAEDISCON:
 
226
      msg = "Graceful shutdown in progress";
 
227
      break;
 
228
    case WSAENOMORE: case WSA_E_NO_MORE:
 
229
      msg = "No more results";
 
230
      break;
 
231
    case WSAECANCELLED: case WSA_E_CANCELLED:
 
232
      msg = "Call was canceled";
 
233
      break;
 
234
    case WSAEINVALIDPROCTABLE:
 
235
      msg = "Procedure call table is invalid";
 
236
      break;
 
237
    case WSAEINVALIDPROVIDER:
 
238
      msg = "Service provider is invalid";
 
239
      break;
 
240
    case WSAEPROVIDERFAILEDINIT:
 
241
      msg = "Service provider failed to initialize";
 
242
      break;
 
243
    case WSASYSCALLFAILURE:
 
244
      msg = "System call failure";
 
245
      break;
 
246
    case WSASERVICE_NOT_FOUND:
 
247
      msg = "Service not found";
 
248
      break;
 
249
    case WSATYPE_NOT_FOUND:
 
250
      msg = "Class type not found";
 
251
      break;
 
252
    case WSAEREFUSED:
 
253
      msg = "Database query was refused";
 
254
      break;
 
255
    case WSAHOST_NOT_FOUND:
 
256
      msg = "Host not found";
 
257
      break;
 
258
    case WSATRY_AGAIN:
 
259
      msg = "Nonauthoritative host not found";
 
260
      break;
 
261
    case WSANO_RECOVERY:
 
262
      msg = "Nonrecoverable error";
 
263
      break;
 
264
    case WSANO_DATA:
 
265
      msg = "Valid name, no data record of requested type";
 
266
      break;
 
267
    /* WSA_QOS_* omitted */
 
268
#  endif
 
269
# endif
 
270
 
 
271
# if GNULIB_defined_ENOMSG
 
272
    case ENOMSG:
 
273
      msg = "No message of desired type";
 
274
      break;
 
275
# endif
 
276
 
 
277
# if GNULIB_defined_EIDRM
 
278
    case EIDRM:
 
279
      msg = "Identifier removed";
 
280
      break;
 
281
# endif
 
282
 
 
283
# if GNULIB_defined_ENOLINK
 
284
    case ENOLINK:
 
285
      msg = "Link has been severed";
 
286
      break;
 
287
# endif
 
288
 
 
289
# if GNULIB_defined_EPROTO
 
290
    case EPROTO:
 
291
      msg = "Protocol error";
 
292
      break;
 
293
# endif
 
294
 
 
295
# if GNULIB_defined_EMULTIHOP
 
296
    case EMULTIHOP:
 
297
      msg = "Multihop attempted";
 
298
      break;
 
299
# endif
 
300
 
 
301
# if GNULIB_defined_EBADMSG
 
302
    case EBADMSG:
 
303
      msg = "Bad message";
 
304
      break;
 
305
# endif
 
306
 
 
307
# if GNULIB_defined_EOVERFLOW
 
308
    case EOVERFLOW:
 
309
      msg = "Value too large for defined data type";
 
310
      break;
 
311
# endif
 
312
 
 
313
# if GNULIB_defined_ENOTSUP
 
314
    case ENOTSUP:
 
315
      msg = "Not supported";
 
316
      break;
 
317
# endif
 
318
 
 
319
# if GNULIB_defined_ESTALE
 
320
    case ESTALE:
 
321
      msg = "Stale NFS file handle";
 
322
      break;
 
323
# endif
 
324
 
 
325
# if GNULIB_defined_ECANCELED
 
326
    case ECANCELED:
 
327
      msg = "Operation canceled";
 
328
      break;
 
329
# endif
 
330
    }
 
331
 
 
332
  if (msg)
 
333
    return (char *) msg;
 
334
 
 
335
  {
 
336
    char *result = strerror (n);
 
337
 
 
338
    if (result == NULL || result[0] == '\0')
 
339
      {
 
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);
 
343
        return msg_buf;
 
344
      }
 
345
 
 
346
    return result;
 
347
  }
 
348
}
 
349
 
 
350
#endif