summaryrefslogtreecommitdiffstats
path: root/lib/errno_names.c
blob: 3c1ff23ce67286aa3fcf668054134009a5d5fe5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
/* Mapping Error Numbers to their names
 * Copyright (C) 2010 Chris Hall (GMCH), Highwayman
 *
 * This file is part of GNU Zebra.
 *
 * GNU Zebra is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published
 * by the Free Software Foundation; either version 2, or (at your
 * option) any later version.
 *
 * GNU Zebra is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GNU Zebra; see the file COPYING.  If not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */
#include "misc.h"

#include <errno.h>
#include <netdb.h>

#include "errno_names.h"

/*==============================================================================
 * Table to map error number to its name
 */
#define ERRNO(err) [err] = #err

static const char* errno_name_table[] =
{
  /* Error number for no error
   *
   *   (123456789012345), /-- no name is more than 15 characters
   */
  ERRNO(EOK),             /* No error                                         */

  /* POSIX Error Numbers -- taken Open Group Base Specifications Issue 7
   *                        IEEE Std 1003.1-2008
   *
   * Stream related stuff does not seeem to be fully supported.
   */
  ERRNO(E2BIG),           /* Argument list too long.                          */
  ERRNO(EACCES),          /* Permission denied.                               */
  ERRNO(EADDRINUSE),      /* Address in use.                                  */
  ERRNO(EADDRNOTAVAIL),   /* Address not available.                           */
  ERRNO(EAFNOSUPPORT),    /* Address family not supported.                    */
#if EAGAIN != EWOULDBLOCK
  ERRNO(EAGAIN),          /* Resource unavailable, try again
                                    (may be the same value as [EWOULDBLOCK]). */
#endif
  ERRNO(EALREADY),        /* Connection already in progress.                  */
  ERRNO(EBADF),           /* Bad file descriptor.                             */
  ERRNO(EBADMSG),         /* Bad message.                                     */
  ERRNO(EBUSY),           /* Device or resource busy.                         */
  ERRNO(ECANCELED),       /* Operation canceled.                              */
  ERRNO(ECHILD),          /* No child processes.                              */
  ERRNO(ECONNABORTED),    /* Connection aborted.                              */
  ERRNO(ECONNREFUSED),    /* Connection refused.                              */
  ERRNO(ECONNRESET),      /* Connection reset.                                */
  ERRNO(EDEADLK),         /* Resource deadlock would occur.                   */
  ERRNO(EDESTADDRREQ),    /* Destination address required.                    */
  ERRNO(EDOM),            /* Mathematics argument out of domain of function.  */
  ERRNO(EDQUOT),          /* Reserved.                                        */
  ERRNO(EEXIST),          /* File exists.                                     */
  ERRNO(EFAULT),          /* Bad address.                                     */
  ERRNO(EFBIG),           /* File too large.                                  */
  ERRNO(EHOSTUNREACH),    /* Host is unreachable.                             */
  ERRNO(EIDRM),           /* Identifier removed.                              */
  ERRNO(EILSEQ),          /* Illegal byte sequence.                           */
  ERRNO(EINPROGRESS),     /* Operation in progress.                           */
  ERRNO(EINTR),           /* Interrupted function.                            */
  ERRNO(EINVAL),          /* Invalid argument.                                */
  ERRNO(EIO),             /* I/O error.                                       */
  ERRNO(EISCONN),         /* Socket is connected.                             */
  ERRNO(EISDIR),          /* Is a directory.                                  */
  ERRNO(ELOOP),           /* Too many levels of symbolic links.               */
  ERRNO(EMFILE),          /* File descriptor value too large.                 */
  ERRNO(EMLINK),          /* Too many links.                                  */
  ERRNO(EMSGSIZE),        /* Message too large.                               */
  ERRNO(EMULTIHOP),       /* Reserved.                                        */
  ERRNO(ENAMETOOLONG),    /* Filename too long.                               */
  ERRNO(ENETDOWN),        /* Network is down.                                 */
  ERRNO(ENETRESET),       /* Connection aborted by network.                   */
  ERRNO(ENETUNREACH),     /* Network unreachable.                             */
  ERRNO(ENFILE),          /* Too many files open in system.                   */
  ERRNO(ENOBUFS),         /* No buffer space available.                       */
#ifdef ENODATA
  ERRNO(ENODATA),         /* No message is available on the STREAM head read
                                                                       queue. */
#endif
  ERRNO(ENODEV),          /* No such device.                                  */
  ERRNO(ENOENT),          /* No such file or directory.                       */
  ERRNO(ENOEXEC),         /* Executable file format error.                    */
  ERRNO(ENOLCK),          /* No locks available.                              */
  ERRNO(ENOLINK),         /* Reserved.                                        */
  ERRNO(ENOMEM),          /* Not enough space.                                */
  ERRNO(ENOMSG),          /* No message of the desired type.                  */
  ERRNO(ENOPROTOOPT),     /* Protocol not available.                          */
  ERRNO(ENOSPC),          /* No space left on device.                         */
#ifdef ENOSR
  ERRNO(ENOSR),           /* No STREAM resources.                             */
#endif
#ifdef ENOSTR
  ERRNO(ENOSTR),          /* Not a STREAM.                                    */
#endif
  ERRNO(ENOSYS),          /* Function not supported.                          */
  ERRNO(ENOTCONN),        /* The socket is not connected.                     */
  ERRNO(ENOTDIR),         /* Not a directory.                                 */
  ERRNO(ENOTEMPTY),       /* Directory not empty.                             */
#ifdef ENOTRECOVERABLE
  ERRNO(ENOTRECOVERABLE), /* State not recoverable.                           */
#endif
  ERRNO(ENOTSOCK),        /* Not a socket.                                    */
  ERRNO(ENOTSUP),         /* Not supported
                                     (may be the same value as [EOPNOTSUPP]). */
  ERRNO(ENOTTY),          /* Inappropriate I/O control operation.             */
  ERRNO(ENXIO),           /* No such device or address.                       */
#if EOPNOTSUPP != ENOTSUP
  ERRNO(EOPNOTSUPP),      /* Operation not supported on socket
                                        (may be the same value as [ENOTSUP]). */
#endif
  ERRNO(EOVERFLOW),       /* Value too large to be stored in data type.       */
#ifdef EOWNERDEAD
  ERRNO(EOWNERDEAD),      /* Previous owner died.                             */
#endif
  ERRNO(EPERM),           /* Operation not permitted.                         */
  ERRNO(EPIPE),           /* Broken pipe.                                     */
  ERRNO(EPROTO),          /* Protocol error.                                  */
  ERRNO(EPROTONOSUPPORT), /* Protocol not supported.                          */
  ERRNO(EPROTOTYPE),      /* Protocol wrong type for socket.                  */
  ERRNO(ERANGE),          /* Result too large.                                */
  ERRNO(EROFS),           /* Read-only file system.                           */
  ERRNO(ESPIPE),          /* Invalid seek.                                    */
  ERRNO(ESRCH),           /* No such process.                                 */
  ERRNO(ESTALE),          /* Reserved.                                        */
#ifdef ETIME
  ERRNO(ETIME),           /* Stream ioctl() timeout.                          */
#endif
  ERRNO(ETIMEDOUT),       /* Connection timed out.                            */
  ERRNO(ETXTBSY),         /* Text file busy.                                  */
  ERRNO(EWOULDBLOCK),     /* Operation would block
                                         (may be the same value as [EAGAIN]). */
  ERRNO(EXDEV),           /* Cross-device link.                               */

/* Linux Error Numbers -- for 2.6.30, taken 8-Apr-2010.
 *
 *     (123456789012345), /-- no name is more than 15 characters
 */
#ifdef EADV
  ERRNO(EADV),            /* Advertise error                                  */
#endif
#ifdef EBADE
  ERRNO(EBADE),           /* Invalid exchange                                 */
#endif
#ifdef EBADFD
  ERRNO(EBADFD),          /* File descriptor in bad state                     */
#endif
#ifdef EBADR
  ERRNO(EBADR),           /* Invalid request descriptor                       */
#endif
#ifdef EBADRQC
  ERRNO(EBADRQC),         /* Invalid request code                             */
#endif
#ifdef EBADSLT
  ERRNO(EBADSLT),         /* Invalid slot                                     */
#endif
#ifdef EBFONT
  ERRNO(EBFONT),          /* Bad font file format                             */
#endif
#ifdef ECHRNG
  ERRNO(ECHRNG),          /* Channel number out of range                      */
#endif
#ifdef ECOMM
  ERRNO(ECOMM),           /* Communication error on send                      */
#endif
#ifdef EDEADLOCK
  ERRNO(EDEADLOCK),       /* same as EDEADLK                                  */
#endif
#ifdef EDOTDOT
  ERRNO(EDOTDOT),         /* RFS specific error                               */
#endif
#ifdef EHOSTDOWN
  ERRNO(EHOSTDOWN),       /* Host is down                                     */
#endif
#ifdef EISNAM
  ERRNO(EISNAM),          /* Is a named type file                             */
#endif
#ifdef EKEYEXPIRED
  ERRNO(EKEYEXPIRED),     /* Key has expired                                  */
#endif
#ifdef EKEYREJECTED
  ERRNO(EKEYREJECTED),    /* Key was rejected by service                      */
#endif
#ifdef EKEYREVOKED
  ERRNO(EKEYREVOKED),     /* Key has been revoked                             */
#endif
#ifdef EL2HLT
  ERRNO(EL2HLT),          /* Level 2 halted                                   */
#endif
#ifdef EL2NSYNC
  ERRNO(EL2NSYNC),        /* Level 2 not synchronized                         */
#endif
#ifdef EL3HLT
  ERRNO(EL3HLT),          /* Level 3 halted                                   */
#endif
#ifdef EL3RST
  ERRNO(EL3RST),          /* Level 3 reset                                    */
#endif
#ifdef ELIBACC
  ERRNO(ELIBACC),         /* Can not access a needed shared library           */
#endif
#ifdef ELIBBAD
  ERRNO(ELIBBAD),         /* Accessing a corrupted shared library             */
#endif
#ifdef ELIBEXEC
  ERRNO(ELIBEXEC),        /* Cannot exec a shared library directly            */
#endif
#ifdef ELIBMAX
  ERRNO(ELIBMAX),         /* Attempting to link in too many shared libraries  */
#endif
#ifdef ELIBSCN
  ERRNO(ELIBSCN),         /* .lib section in a.out corrupted                  */
#endif
#ifdef ELNRNG
  ERRNO(ELNRNG),          /* Link number out of range                         */
#endif
#ifdef EMEDIUMTYPE
  ERRNO(EMEDIUMTYPE),     /* Wrong medium type                                */
#endif
#ifdef ENAVAIL
  ERRNO(ENAVAIL),         /* No XENIX semaphores available                    */
#endif
#ifdef ENOANO
  ERRNO(ENOANO),          /* No anode                                         */
#endif
#ifdef ENOCSI
  ERRNO(ENOCSI),          /* No CSI structure available                       */
#endif
#ifdef ENOKEY
  ERRNO(ENOKEY),          /* Required key not available                       */
#endif
#ifdef ENOMEDIUM
  ERRNO(ENOMEDIUM),       /* No medium found                                  */
#endif
#ifdef ENONET
  ERRNO(ENONET),          /* Machine is not on the network                    */
#endif
#ifdef ENOPKG
  ERRNO(ENOPKG),          /* Package not installed                            */
#endif
#ifdef ENOTBLK
  ERRNO(ENOTBLK),         /* Block device required                            */
#endif
#ifdef ENOTNAM
  ERRNO(ENOTNAM),         /* Not a XENIX named type file                      */
#endif
#ifdef ENOTUNIQ
  ERRNO(ENOTUNIQ),        /* Name not unique on network                       */
#endif
#ifdef EPFNOSUPPORT
  ERRNO(EPFNOSUPPORT),    /* Protocol family not supported                    */
#endif
#ifdef EREMCHG
  ERRNO(EREMCHG),         /* Remote address changed                           */
#endif
#ifdef EREMOTE
  ERRNO(EREMOTE),         /* Object is remote                                 */
#endif
#ifdef EREMOTEIO
  ERRNO(EREMOTEIO),       /* Remote I/O error                                 */
#endif
#ifdef ERESTART
  ERRNO(ERESTART),        /* Interrupted system call should be restarted      */
#endif
#ifdef ESHUTDOWN
  ERRNO(ESHUTDOWN),       /* Cannot send after transport endpoint shutdown    */
#endif
#ifdef ESOCKTNOSUPPORT
  ERRNO(ESOCKTNOSUPPORT), /* Socket type not supported                        */
#endif
#ifdef ESRMNT
  ERRNO(ESRMNT),          /* Srmount error                                    */
#endif
#ifdef ESTRPIPE
  ERRNO(ESTRPIPE),        /* Streams pipe error                               */
#endif
#ifdef ETOOMANYREFS
  ERRNO(ETOOMANYREFS),    /* Too many references: cannot splice               */
#endif
#ifdef EUCLEAN
  ERRNO(EUCLEAN),         /* Structure needs cleaning                         */
#endif
#ifdef EUNATCH
  ERRNO(EUNATCH),         /* Protocol driver not attached                     */
#endif
#ifdef EUSERS
  ERRNO(EUSERS),          /* Too many users                                   */
#endif
#ifdef EXFULL
  ERRNO(EXFULL),          /* Exchange full                                    */
#endif
} ;

enum { errno_last = (sizeof(errno_name_table) / sizeof(char*)) - 1 } ;

/*------------------------------------------------------------------------------
 * Lookup the name for given error number.
 *
 * Returns: address of string, or NULL if not known
 *
 * NB: for 0 returns "EOK".
 *
 * NB: async-signal-safe and thread-safe !
 */
extern const char*
errno_name_lookup(int err)
{
  if ((err < 0) || (err > errno_last))
    return NULL ;
 return errno_name_table[err] ;
} ;

/*==============================================================================
 * Table to map EAI error number to its name -- the errors generated by
 * getaddrinfo() and getnameinfo().
 *
 * At least one system uses -ve numbers for these... so the following will
 * support either +ve or -ve values, provided that all have the same sign.
 */
#if EAI_AGAIN < 0
enum { eai_sgn = -1 } ;
#else
enum { eai_sgn = +1 } ;
#endif

#define EAINO(eai) [eai * eai_sgn] = #eai

static const char* eaino_name_table[] =
{
  /* Error number for no error
   *
   *   (123456789012345), /-- no name is more than 15 characters
   */
  EAINO(EAI_OK),          /* No error                                   */

  /* POSIX Error Numbers -- taken Open Group Base Specifications Issue 7
   *                        IEEE Std 1003.1-2008
   */
  EAINO(EAI_AGAIN),       /* Temporary failure in name resolution.      */
  EAINO(EAI_BADFLAGS),    /* Invalid value for 'ai_flags' field.        */
  EAINO(EAI_FAIL),        /* Non-recoverable failure in name res.       */
  EAINO(EAI_FAMILY),      /* 'ai_family' not supported.                 */
  EAINO(EAI_MEMORY),      /* Memory allocation failure.                 */
  EAINO(EAI_NONAME),      /* NAME or SERVICE is unknown.                */
  EAINO(EAI_OVERFLOW),    /* Argument buffer overflow.                  */
  EAINO(EAI_SERVICE),     /* SERVICE not supported for 'ai_socktype'.   */
  EAINO(EAI_SOCKTYPE),    /* 'ai_socktype' not supported.               */
  EAINO(EAI_SYSTEM),      /* System error returned in 'errno'.          */
} ;

enum { eaino_last = (sizeof(eaino_name_table) / sizeof(char*)) - 1 } ;

/*------------------------------------------------------------------------------
 * Lookup the name for given error number.
 *
 * Returns: address of string, or NULL if not known
 *
 * NB: for 0 returns "EOK".
 *
 * NB: async-signal-safe and thread-safe !
 */
extern const char*
eaino_name_lookup(int eai)
{
  eai *= eai_sgn ;
  if ((eai < 0) || (eai > eaino_last))
    return NULL ;
 return eaino_name_table[eai] ;
} ;