| 1 | /* Extended support for using errno values.
|
|---|
| 2 | Written by Fred Fish. [email protected]
|
|---|
| 3 | This file is in the public domain. --Per Bothner. */
|
|---|
| 4 |
|
|---|
| 5 | #include "ansidecl.h"
|
|---|
| 6 | #include "libiberty.h"
|
|---|
| 7 |
|
|---|
| 8 | #include "config.h"
|
|---|
| 9 |
|
|---|
| 10 | #ifdef HAVE_SYS_ERRLIST
|
|---|
| 11 | /* Note that errno.h (not sure what OS) or stdio.h (BSD 4.4, at least)
|
|---|
| 12 | might declare sys_errlist in a way that the compiler might consider
|
|---|
| 13 | incompatible with our later declaration, perhaps by using const
|
|---|
| 14 | attributes. So we hide the declaration in errno.h (if any) using a
|
|---|
| 15 | macro. */
|
|---|
| 16 | #define sys_nerr sys_nerr__
|
|---|
| 17 | #define sys_errlist sys_errlist__
|
|---|
| 18 | #endif
|
|---|
| 19 |
|
|---|
| 20 | #include <stdio.h>
|
|---|
| 21 | #include <errno.h>
|
|---|
| 22 |
|
|---|
| 23 | #ifdef HAVE_SYS_ERRLIST
|
|---|
| 24 | #undef sys_nerr
|
|---|
| 25 | #undef sys_errlist
|
|---|
| 26 | #endif
|
|---|
| 27 |
|
|---|
| 28 | /* Routines imported from standard C runtime libraries. */
|
|---|
| 29 |
|
|---|
| 30 | #ifdef HAVE_STDLIB_H
|
|---|
| 31 | #include <stdlib.h>
|
|---|
| 32 | #else
|
|---|
| 33 | extern PTR malloc ();
|
|---|
| 34 | #endif
|
|---|
| 35 |
|
|---|
| 36 | #ifdef HAVE_STRING_H
|
|---|
| 37 | #include <string.h>
|
|---|
| 38 | #else
|
|---|
| 39 | extern PTR memset ();
|
|---|
| 40 | #endif
|
|---|
| 41 |
|
|---|
| 42 | #ifndef MAX
|
|---|
| 43 | # define MAX(a,b) ((a) > (b) ? (a) : (b))
|
|---|
| 44 | #endif
|
|---|
| 45 |
|
|---|
| 46 | static void init_error_tables PARAMS ((void));
|
|---|
| 47 |
|
|---|
| 48 | /* Translation table for errno values. See intro(2) in most UNIX systems
|
|---|
| 49 | Programmers Reference Manuals.
|
|---|
| 50 |
|
|---|
| 51 | Note that this table is generally only accessed when it is used at runtime
|
|---|
| 52 | to initialize errno name and message tables that are indexed by errno
|
|---|
| 53 | value.
|
|---|
| 54 |
|
|---|
| 55 | Not all of these errnos will exist on all systems. This table is the only
|
|---|
| 56 | thing that should have to be updated as new error numbers are introduced.
|
|---|
| 57 | It's sort of ugly, but at least its portable. */
|
|---|
| 58 |
|
|---|
| 59 | struct error_info
|
|---|
| 60 | {
|
|---|
| 61 | const int value; /* The numeric value from <errno.h> */
|
|---|
| 62 | const char *const name; /* The equivalent symbolic value */
|
|---|
| 63 | #ifndef HAVE_SYS_ERRLIST
|
|---|
| 64 | const char *const msg; /* Short message about this value */
|
|---|
| 65 | #endif
|
|---|
| 66 | };
|
|---|
| 67 |
|
|---|
| 68 | #ifndef HAVE_SYS_ERRLIST
|
|---|
| 69 | # define ENTRY(value, name, msg) {value, name, msg}
|
|---|
| 70 | #else
|
|---|
| 71 | # define ENTRY(value, name, msg) {value, name}
|
|---|
| 72 | #endif
|
|---|
| 73 |
|
|---|
| 74 | static const struct error_info error_table[] =
|
|---|
| 75 | {
|
|---|
| 76 | #if defined (EPERM)
|
|---|
| 77 | ENTRY(EPERM, "EPERM", "Not owner"),
|
|---|
| 78 | #endif
|
|---|
| 79 | #if defined (ENOENT)
|
|---|
| 80 | ENTRY(ENOENT, "ENOENT", "No such file or directory"),
|
|---|
| 81 | #endif
|
|---|
| 82 | #if defined (ESRCH)
|
|---|
| 83 | ENTRY(ESRCH, "ESRCH", "No such process"),
|
|---|
| 84 | #endif
|
|---|
| 85 | #if defined (EINTR)
|
|---|
| 86 | ENTRY(EINTR, "EINTR", "Interrupted system call"),
|
|---|
| 87 | #endif
|
|---|
| 88 | #if defined (EIO)
|
|---|
| 89 | ENTRY(EIO, "EIO", "I/O error"),
|
|---|
| 90 | #endif
|
|---|
| 91 | #if defined (ENXIO)
|
|---|
| 92 | ENTRY(ENXIO, "ENXIO", "No such device or address"),
|
|---|
| 93 | #endif
|
|---|
| 94 | #if defined (E2BIG)
|
|---|
| 95 | ENTRY(E2BIG, "E2BIG", "Arg list too long"),
|
|---|
| 96 | #endif
|
|---|
| 97 | #if defined (ENOEXEC)
|
|---|
| 98 | ENTRY(ENOEXEC, "ENOEXEC", "Exec format error"),
|
|---|
| 99 | #endif
|
|---|
| 100 | #if defined (EBADF)
|
|---|
| 101 | ENTRY(EBADF, "EBADF", "Bad file number"),
|
|---|
| 102 | #endif
|
|---|
| 103 | #if defined (ECHILD)
|
|---|
| 104 | ENTRY(ECHILD, "ECHILD", "No child processes"),
|
|---|
| 105 | #endif
|
|---|
| 106 | #if defined (EWOULDBLOCK) /* Put before EAGAIN, sometimes aliased */
|
|---|
| 107 | ENTRY(EWOULDBLOCK, "EWOULDBLOCK", "Operation would block"),
|
|---|
| 108 | #endif
|
|---|
| 109 | #if defined (EAGAIN)
|
|---|
| 110 | ENTRY(EAGAIN, "EAGAIN", "No more processes"),
|
|---|
| 111 | #endif
|
|---|
| 112 | #if defined (ENOMEM)
|
|---|
| 113 | ENTRY(ENOMEM, "ENOMEM", "Not enough space"),
|
|---|
| 114 | #endif
|
|---|
| 115 | #if defined (EACCES)
|
|---|
| 116 | ENTRY(EACCES, "EACCES", "Permission denied"),
|
|---|
| 117 | #endif
|
|---|
| 118 | #if defined (EFAULT)
|
|---|
| 119 | ENTRY(EFAULT, "EFAULT", "Bad address"),
|
|---|
| 120 | #endif
|
|---|
| 121 | #if defined (ENOTBLK)
|
|---|
| 122 | ENTRY(ENOTBLK, "ENOTBLK", "Block device required"),
|
|---|
| 123 | #endif
|
|---|
| 124 | #if defined (EBUSY)
|
|---|
| 125 | ENTRY(EBUSY, "EBUSY", "Device busy"),
|
|---|
| 126 | #endif
|
|---|
| 127 | #if defined (EEXIST)
|
|---|
| 128 | ENTRY(EEXIST, "EEXIST", "File exists"),
|
|---|
| 129 | #endif
|
|---|
| 130 | #if defined (EXDEV)
|
|---|
| 131 | ENTRY(EXDEV, "EXDEV", "Cross-device link"),
|
|---|
| 132 | #endif
|
|---|
| 133 | #if defined (ENODEV)
|
|---|
| 134 | ENTRY(ENODEV, "ENODEV", "No such device"),
|
|---|
| 135 | #endif
|
|---|
| 136 | #if defined (ENOTDIR)
|
|---|
| 137 | ENTRY(ENOTDIR, "ENOTDIR", "Not a directory"),
|
|---|
| 138 | #endif
|
|---|
| 139 | #if defined (EISDIR)
|
|---|
| 140 | ENTRY(EISDIR, "EISDIR", "Is a directory"),
|
|---|
| 141 | #endif
|
|---|
| 142 | #if defined (EINVAL)
|
|---|
| 143 | ENTRY(EINVAL, "EINVAL", "Invalid argument"),
|
|---|
| 144 | #endif
|
|---|
| 145 | #if defined (ENFILE)
|
|---|
| 146 | ENTRY(ENFILE, "ENFILE", "File table overflow"),
|
|---|
| 147 | #endif
|
|---|
| 148 | #if defined (EMFILE)
|
|---|
| 149 | ENTRY(EMFILE, "EMFILE", "Too many open files"),
|
|---|
| 150 | #endif
|
|---|
| 151 | #if defined (ENOTTY)
|
|---|
| 152 | ENTRY(ENOTTY, "ENOTTY", "Not a typewriter"),
|
|---|
| 153 | #endif
|
|---|
| 154 | #if defined (ETXTBSY)
|
|---|
| 155 | ENTRY(ETXTBSY, "ETXTBSY", "Text file busy"),
|
|---|
| 156 | #endif
|
|---|
| 157 | #if defined (EFBIG)
|
|---|
| 158 | ENTRY(EFBIG, "EFBIG", "File too large"),
|
|---|
| 159 | #endif
|
|---|
| 160 | #if defined (ENOSPC)
|
|---|
| 161 | ENTRY(ENOSPC, "ENOSPC", "No space left on device"),
|
|---|
| 162 | #endif
|
|---|
| 163 | #if defined (ESPIPE)
|
|---|
| 164 | ENTRY(ESPIPE, "ESPIPE", "Illegal seek"),
|
|---|
| 165 | #endif
|
|---|
| 166 | #if defined (EROFS)
|
|---|
| 167 | ENTRY(EROFS, "EROFS", "Read-only file system"),
|
|---|
| 168 | #endif
|
|---|
| 169 | #if defined (EMLINK)
|
|---|
| 170 | ENTRY(EMLINK, "EMLINK", "Too many links"),
|
|---|
|
|---|