Home | History | Annotate | Line # | Download | only in libiberty
strerror.c revision 1.1.1.1.4.2
      1  1.1.1.1.4.2  yamt /* Extended support for using errno values.
      2  1.1.1.1.4.2  yamt    Written by Fred Fish.  fnf (at) cygnus.com
      3  1.1.1.1.4.2  yamt    This file is in the public domain.  --Per Bothner.  */
      4  1.1.1.1.4.2  yamt 
      5  1.1.1.1.4.2  yamt #include "config.h"
      6  1.1.1.1.4.2  yamt 
      7  1.1.1.1.4.2  yamt #ifdef HAVE_SYS_ERRLIST
      8  1.1.1.1.4.2  yamt /* Note that errno.h (not sure what OS) or stdio.h (BSD 4.4, at least)
      9  1.1.1.1.4.2  yamt    might declare sys_errlist in a way that the compiler might consider
     10  1.1.1.1.4.2  yamt    incompatible with our later declaration, perhaps by using const
     11  1.1.1.1.4.2  yamt    attributes.  So we hide the declaration in errno.h (if any) using a
     12  1.1.1.1.4.2  yamt    macro. */
     13  1.1.1.1.4.2  yamt #define sys_nerr sys_nerr__
     14  1.1.1.1.4.2  yamt #define sys_errlist sys_errlist__
     15  1.1.1.1.4.2  yamt #endif
     16  1.1.1.1.4.2  yamt 
     17  1.1.1.1.4.2  yamt #include "ansidecl.h"
     18  1.1.1.1.4.2  yamt #include "libiberty.h"
     19  1.1.1.1.4.2  yamt 
     20  1.1.1.1.4.2  yamt #include <stdio.h>
     21  1.1.1.1.4.2  yamt #include <errno.h>
     22  1.1.1.1.4.2  yamt 
     23  1.1.1.1.4.2  yamt #ifdef HAVE_SYS_ERRLIST
     24  1.1.1.1.4.2  yamt #undef sys_nerr
     25  1.1.1.1.4.2  yamt #undef sys_errlist
     26  1.1.1.1.4.2  yamt #endif
     27  1.1.1.1.4.2  yamt 
     28  1.1.1.1.4.2  yamt /*  Routines imported from standard C runtime libraries. */
     29  1.1.1.1.4.2  yamt 
     30  1.1.1.1.4.2  yamt #ifdef HAVE_STDLIB_H
     31  1.1.1.1.4.2  yamt #include <stdlib.h>
     32  1.1.1.1.4.2  yamt #else
     33  1.1.1.1.4.2  yamt extern PTR malloc ();
     34  1.1.1.1.4.2  yamt #endif
     35  1.1.1.1.4.2  yamt 
     36  1.1.1.1.4.2  yamt #ifdef HAVE_STRING_H
     37  1.1.1.1.4.2  yamt #include <string.h>
     38  1.1.1.1.4.2  yamt #else
     39  1.1.1.1.4.2  yamt extern PTR memset ();
     40  1.1.1.1.4.2  yamt #endif
     41  1.1.1.1.4.2  yamt 
     42  1.1.1.1.4.2  yamt #ifndef MAX
     43  1.1.1.1.4.2  yamt #  define MAX(a,b) ((a) > (b) ? (a) : (b))
     44  1.1.1.1.4.2  yamt #endif
     45  1.1.1.1.4.2  yamt 
     46  1.1.1.1.4.2  yamt static void init_error_tables (void);
     47  1.1.1.1.4.2  yamt 
     48  1.1.1.1.4.2  yamt /* Translation table for errno values.  See intro(2) in most UNIX systems
     49  1.1.1.1.4.2  yamt    Programmers Reference Manuals.
     50  1.1.1.1.4.2  yamt 
     51  1.1.1.1.4.2  yamt    Note that this table is generally only accessed when it is used at runtime
     52  1.1.1.1.4.2  yamt    to initialize errno name and message tables that are indexed by errno
     53  1.1.1.1.4.2  yamt    value.
     54  1.1.1.1.4.2  yamt 
     55  1.1.1.1.4.2  yamt    Not all of these errnos will exist on all systems.  This table is the only
     56  1.1.1.1.4.2  yamt    thing that should have to be updated as new error numbers are introduced.
     57  1.1.1.1.4.2  yamt    It's sort of ugly, but at least its portable. */
     58  1.1.1.1.4.2  yamt 
     59  1.1.1.1.4.2  yamt struct error_info
     60  1.1.1.1.4.2  yamt {
     61  1.1.1.1.4.2  yamt   const int value;		/* The numeric value from <errno.h> */
     62  1.1.1.1.4.2  yamt   const char *const name;	/* The equivalent symbolic value */
     63  1.1.1.1.4.2  yamt #ifndef HAVE_SYS_ERRLIST
     64  1.1.1.1.4.2  yamt   const char *const msg;	/* Short message about this value */
     65  1.1.1.1.4.2  yamt #endif
     66  1.1.1.1.4.2  yamt };
     67  1.1.1.1.4.2  yamt 
     68  1.1.1.1.4.2  yamt #ifndef HAVE_SYS_ERRLIST
     69  1.1.1.1.4.2  yamt #   define ENTRY(value, name, msg)	{value, name, msg}
     70  1.1.1.1.4.2  yamt #else
     71  1.1.1.1.4.2  yamt #   define ENTRY(value, name, msg)	{value, name}
     72  1.1.1.1.4.2  yamt #endif
     73  1.1.1.1.4.2  yamt 
     74  1.1.1.1.4.2  yamt static const struct error_info error_table[] =
     75  1.1.1.1.4.2  yamt {
     76  1.1.1.1.4.2  yamt #if defined (EPERM)
     77  1.1.1.1.4.2  yamt   ENTRY(EPERM, "EPERM", "Not owner"),
     78  1.1.1.1.4.2  yamt #endif
     79  1.1.1.1.4.2  yamt #if defined (ENOENT)
     80  1.1.1.1.4.2  yamt   ENTRY(ENOENT, "ENOENT", "No such file or directory"),
     81  1.1.1.1.4.2  yamt #endif
     82  1.1.1.1.4.2  yamt #if defined (ESRCH)
     83  1.1.1.1.4.2  yamt   ENTRY(ESRCH, "ESRCH", "No such process"),
     84  1.1.1.1.4.2  yamt #endif
     85  1.1.1.1.4.2  yamt #if defined (EINTR)
     86  1.1.1.1.4.2  yamt   ENTRY(EINTR, "EINTR", "Interrupted system call"),
     87  1.1.1.1.4.2  yamt #endif
     88  1.1.1.1.4.2  yamt #if defined (EIO)
     89  1.1.1.1.4.2  yamt   ENTRY(EIO, "EIO", "I/O error"),
     90  1.1.1.1.4.2  yamt #endif
     91  1.1.1.1.4.2  yamt #if defined (ENXIO)
     92  1.1.1.1.4.2  yamt   ENTRY(ENXIO, "ENXIO", "No such device or address"),
     93  1.1.1.1.4.2  yamt #endif
     94  1.1.1.1.4.2  yamt #if defined (E2BIG)
     95  1.1.1.1.4.2  yamt   ENTRY(E2BIG, "E2BIG", "Arg list too long"),
     96  1.1.1.1.4.2  yamt #endif
     97  1.1.1.1.4.2  yamt #if defined (ENOEXEC)
     98  1.1.1.1.4.2  yamt   ENTRY(ENOEXEC, "ENOEXEC", "Exec format error"),
     99  1.1.1.1.4.2  yamt #endif
    100  1.1.1.1.4.2  yamt #if defined (EBADF)
    101  1.1.1.1.4.2  yamt   ENTRY(EBADF, "EBADF", "Bad file number"),
    102  1.1.1.1.4.2  yamt #endif
    103  1.1.1.1.4.2  yamt #if defined (ECHILD)
    104  1.1.1.1.4.2  yamt   ENTRY(ECHILD, "ECHILD", "No child processes"),
    105  1.1.1.1.4.2  yamt #endif
    106  1.1.1.1.4.2  yamt #if defined (EWOULDBLOCK)	/* Put before EAGAIN, sometimes aliased */
    107  1.1.1.1.4.2  yamt   ENTRY(EWOULDBLOCK, "EWOULDBLOCK", "Operation would block"),
    108  1.1.1.1.4.2  yamt #endif
    109  1.1.1.1.4.2  yamt #if defined (EAGAIN)
    110  1.1.1.1.4.2  yamt   ENTRY(EAGAIN, "EAGAIN", "No more processes"),
    111  1.1.1.1.4.2  yamt #endif
    112  1.1.1.1.4.2  yamt #if defined (ENOMEM)
    113  1.1.1.1.4.2  yamt   ENTRY(ENOMEM, "ENOMEM", "Not enough space"),
    114  1.1.1.1.4.2  yamt #endif
    115  1.1.1.1.4.2  yamt #if defined (EACCES)
    116  1.1.1.1.4.2  yamt   ENTRY(EACCES, "EACCES", "Permission denied"),
    117  1.1.1.1.4.2  yamt #endif
    118  1.1.1.1.4.2  yamt #if defined (EFAULT)
    119  1.1.1.1.4.2  yamt   ENTRY(EFAULT, "EFAULT", "Bad address"),
    120  1.1.1.1.4.2  yamt #endif
    121  1.1.1.1.4.2  yamt #if defined (ENOTBLK)
    122  1.1.1.1.4.2  yamt   ENTRY(ENOTBLK, "ENOTBLK", "Block device required"),
    123  1.1.1.1.4.2  yamt #endif
    124  1.1.1.1.4.2  yamt #if defined (EBUSY)
    125  1.1.1.1.4.2  yamt   ENTRY(EBUSY, "EBUSY", "Device busy"),
    126  1.1.1.1.4.2  yamt #endif
    127  1.1.1.1.4.2  yamt #if defined (EEXIST)
    128  1.1.1.1.4.2  yamt   ENTRY(EEXIST, "EEXIST", "File exists"),
    129  1.1.1.1.4.2  yamt #endif
    130  1.1.1.1.4.2  yamt #if defined (EXDEV)
    131  1.1.1.1.4.2  yamt   ENTRY(EXDEV, "EXDEV", "Cross-device link"),
    132  1.1.1.1.4.2  yamt #endif
    133  1.1.1.1.4.2  yamt #if defined (ENODEV)
    134  1.1.1.1.4.2  yamt   ENTRY(ENODEV, "ENODEV", "No such device"),
    135  1.1.1.1.4.2  yamt #endif
    136  1.1.1.1.4.2  yamt #if defined (ENOTDIR)
    137  1.1.1.1.4.2  yamt   ENTRY(ENOTDIR, "ENOTDIR", "Not a directory"),
    138  1.1.1.1.4.2  yamt #endif
    139  1.1.1.1.4.2  yamt #if defined (EISDIR)
    140  1.1.1.1.4.2  yamt   ENTRY(EISDIR, "EISDIR", "Is a directory"),
    141  1.1.1.1.4.2  yamt #endif
    142  1.1.1.1.4.2  yamt #if defined (EINVAL)
    143  1.1.1.1.4.2  yamt   ENTRY(EINVAL, "EINVAL", "Invalid argument"),
    144  1.1.1.1.4.2  yamt #endif
    145  1.1.1.1.4.2  yamt #if defined (ENFILE)
    146  1.1.1.1.4.2  yamt   ENTRY(ENFILE, "ENFILE", "File table overflow"),
    147  1.1.1.1.4.2  yamt #endif
    148  1.1.1.1.4.2  yamt #if defined (EMFILE)
    149  1.1.1.1.4.2  yamt   ENTRY(EMFILE, "EMFILE", "Too many open files"),
    150  1.1.1.1.4.2  yamt #endif
    151  1.1.1.1.4.2  yamt #if defined (ENOTTY)
    152  1.1.1.1.4.2  yamt   ENTRY(ENOTTY, "ENOTTY", "Not a typewriter"),
    153  1.1.1.1.4.2  yamt #endif
    154  1.1.1.1.4.2  yamt #if defined (ETXTBSY)
    155  1.1.1.1.4.2  yamt   ENTRY(ETXTBSY, "ETXTBSY", "Text file busy"),
    156  1.1.1.1.4.2  yamt #endif
    157  1.1.1.1.4.2  yamt #if defined (EFBIG)
    158  1.1.1.1.4.2  yamt   ENTRY(EFBIG, "EFBIG", "File too large"),
    159  1.1.1.1.4.2  yamt #endif
    160  1.1.1.1.4.2  yamt #if defined (ENOSPC)
    161  1.1.1.1.4.2  yamt   ENTRY(ENOSPC, "ENOSPC", "No space left on device"),
    162  1.1.1.1.4.2  yamt #endif
    163  1.1.1.1.4.2  yamt #if defined (ESPIPE)
    164  1.1.1.1.4.2  yamt   ENTRY(ESPIPE, "ESPIPE", "Illegal seek"),
    165  1.1.1.1.4.2  yamt #endif
    166  1.1.1.1.4.2  yamt #if defined (EROFS)
    167  1.1.1.1.4.2  yamt   ENTRY(EROFS, "EROFS", "Read-only file system"),
    168  1.1.1.1.4.2  yamt #endif
    169  1.1.1.1.4.2  yamt #if defined (EMLINK)
    170  1.1.1.1.4.2  yamt   ENTRY(EMLINK, "EMLINK", "Too many links"),
    171  1.1.1.1.4.2  yamt #endif
    172  1.1.1.1.4.2  yamt #if defined (EPIPE)
    173  1.1.1.1.4.2  yamt   ENTRY(EPIPE, "EPIPE", "Broken pipe"),
    174  1.1.1.1.4.2  yamt #endif
    175  1.1.1.1.4.2  yamt #if defined (EDOM)
    176  1.1.1.1.4.2  yamt   ENTRY(EDOM, "EDOM", "Math argument out of domain of func"),
    177  1.1.1.1.4.2  yamt #endif
    178  1.1.1.1.4.2  yamt #if defined (ERANGE)
    179  1.1.1.1.4.2  yamt   ENTRY(ERANGE, "ERANGE", "Math result not representable"),
    180  1.1.1.1.4.2  yamt #endif
    181  1.1.1.1.4.2  yamt #if defined (ENOMSG)
    182  1.1.1.1.4.2  yamt   ENTRY(ENOMSG, "ENOMSG", "No message of desired type"),
    183  1.1.1.1.4.2  yamt #endif
    184  1.1.1.1.4.2  yamt #if defined (EIDRM)
    185  1.1.1.1.4.2  yamt   ENTRY(EIDRM, "EIDRM", "Identifier removed"),
    186  1.1.1.1.4.2  yamt #endif
    187  1.1.1.1.4.2  yamt #if defined (ECHRNG)
    188  1.1.1.1.4.2  yamt   ENTRY(ECHRNG, "ECHRNG", "Channel number out of range"),
    189  1.1.1.1.4.2  yamt #endif
    190  1.1.1.1.4.2  yamt #if defined (EL2NSYNC)
    191  1.1.1.1.4.2  yamt   ENTRY(EL2NSYNC, "EL2NSYNC", "Level 2 not synchronized"),
    192  1.1.1.1.4.2  yamt #endif
    193  1.1.1.1.4.2  yamt #if defined (EL3HLT)
    194  1.1.1.1.4.2  yamt   ENTRY(EL3HLT, "EL3HLT", "Level 3 halted"),
    195  1.1.1.1.4.2  yamt #endif
    196  1.1.1.1.4.2  yamt #if defined (EL3RST)
    197  1.1.1.1.4.2  yamt   ENTRY(EL3RST, "EL3RST", "Level 3 reset"),
    198  1.1.1.1.4.2  yamt #endif
    199  1.1.1.1.4.2  yamt #if defined (ELNRNG)
    200  1.1.1.1.4.2  yamt   ENTRY(ELNRNG, "ELNRNG", "Link number out of range"),
    201  1.1.1.1.4.2  yamt #endif
    202  1.1.1.1.4.2  yamt #if defined (EUNATCH)
    203  1.1.1.1.4.2  yamt   ENTRY(EUNATCH, "EUNATCH", "Protocol driver not attached"),
    204  1.1.1.1.4.2  yamt #endif
    205  1.1.1.1.4.2  yamt #if defined (ENOCSI)
    206  1.1.1.1.4.2  yamt   ENTRY(ENOCSI, "ENOCSI", "No CSI structure available"),
    207  1.1.1.1.4.2  yamt #endif
    208  1.1.1.1.4.2  yamt #if defined (EL2HLT)
    209  1.1.1.1.4.2  yamt   ENTRY(EL2HLT, "EL2HLT", "Level 2 halted"),
    210  1.1.1.1.4.2  yamt #endif
    211  1.1.1.1.4.2  yamt #if defined (EDEADLK)
    212  1.1.1.1.4.2  yamt   ENTRY(EDEADLK, "EDEADLK", "Deadlock condition"),
    213  1.1.1.1.4.2  yamt #endif
    214  1.1.1.1.4.2  yamt #if defined (ENOLCK)
    215  1.1.1.1.4.2  yamt   ENTRY(ENOLCK, "ENOLCK", "No record locks available"),
    216  1.1.1.1.4.2  yamt #endif
    217  1.1.1.1.4.2  yamt #if defined (EBADE)
    218  1.1.1.1.4.2  yamt   ENTRY(EBADE, "EBADE", "Invalid exchange"),
    219  1.1.1.1.4.2  yamt #endif
    220  1.1.1.1.4.2  yamt #if defined (EBADR)
    221  1.1.1.1.4.2  yamt   ENTRY(EBADR, "EBADR", "Invalid request descriptor"),
    222  1.1.1.1.4.2  yamt #endif
    223  1.1.1.1.4.2  yamt #if defined (EXFULL)
    224  1.1.1.1.4.2  yamt   ENTRY(EXFULL, "EXFULL", "Exchange full"),
    225  1.1.1.1.4.2  yamt #endif
    226  1.1.1.1.4.2  yamt #if defined (ENOANO)
    227  1.1.1.1.4.2  yamt   ENTRY(ENOANO, "ENOANO", "No anode"),
    228  1.1.1.1.4.2  yamt #endif
    229  1.1.1.1.4.2  yamt #if defined (EBADRQC)
    230  1.1.1.1.4.2  yamt   ENTRY(EBADRQC, "EBADRQC", "Invalid request code"),
    231  1.1.1.1.4.2  yamt #endif
    232  1.1.1.1.4.2  yamt #if defined (EBADSLT)
    233  1.1.1.1.4.2  yamt   ENTRY(EBADSLT, "EBADSLT", "Invalid slot"),
    234  1.1.1.1.4.2  yamt #endif
    235  1.1.1.1.4.2  yamt #if defined (EDEADLOCK)
    236  1.1.1.1.4.2  yamt   ENTRY(EDEADLOCK, "EDEADLOCK", "File locking deadlock error"),
    237  1.1.1.1.4.2  yamt #endif
    238  1.1.1.1.4.2  yamt #if defined (EBFONT)
    239  1.1.1.1.4.2  yamt   ENTRY(EBFONT, "EBFONT", "Bad font file format"),
    240  1.1.1.1.4.2  yamt #endif
    241  1.1.1.1.4.2  yamt #if defined (ENOSTR)
    242  1.1.1.1.4.2  yamt   ENTRY(ENOSTR, "ENOSTR", "Device not a stream"),
    243  1.1.1.1.4.2  yamt #endif
    244  1.1.1.1.4.2  yamt #if defined (ENODATA)
    245  1.1.1.1.4.2  yamt   ENTRY(ENODATA, "ENODATA", "No data available"),
    246  1.1.1.1.4.2  yamt #endif
    247  1.1.1.1.4.2  yamt #if defined (ETIME)
    248  1.1.1.1.4.2  yamt   ENTRY(ETIME, "ETIME", "Timer expired"),
    249  1.1.1.1.4.2  yamt #endif
    250  1.1.1.1.4.2  yamt #if defined (ENOSR)
    251  1.1.1.1.4.2  yamt   ENTRY(ENOSR, "ENOSR", "Out of streams resources"),
    252  1.1.1.1.4.2  yamt #endif
    253  1.1.1.1.4.2  yamt #if defined (ENONET)
    254  1.1.1.1.4.2  yamt   ENTRY(ENONET, "ENONET", "Machine is not on the network"),
    255  1.1.1.1.4.2  yamt #endif
    256  1.1.1.1.4.2  yamt #if defined (ENOPKG)
    257  1.1.1.1.4.2  yamt   ENTRY(ENOPKG, "ENOPKG", "Package not installed"),
    258  1.1.1.1.4.2  yamt #endif
    259  1.1.1.1.4.2  yamt #if defined (EREMOTE)
    260  1.1.1.1.4.2  yamt   ENTRY(EREMOTE, "EREMOTE", "Object is remote"),
    261  1.1.1.1.4.2  yamt #endif
    262  1.1.1.1.4.2  yamt #if defined (ENOLINK)
    263  1.1.1.1.4.2  yamt   ENTRY(ENOLINK, "ENOLINK", "Link has been severed"),
    264  1.1.1.1.4.2  yamt #endif
    265  1.1.1.1.4.2  yamt #if defined (EADV)
    266  1.1.1.1.4.2  yamt   ENTRY(EADV, "EADV", "Advertise error"),
    267  1.1.1.1.4.2  yamt #endif
    268  1.1.1.1.4.2  yamt #if defined (ESRMNT)
    269  1.1.1.1.4.2  yamt   ENTRY(ESRMNT, "ESRMNT", "Srmount error"),
    270  1.1.1.1.4.2  yamt #endif
    271  1.1.1.1.4.2  yamt #if defined (ECOMM)
    272  1.1.1.1.4.2  yamt   ENTRY(ECOMM, "ECOMM", "Communication error on send"),
    273  1.1.1.1.4.2  yamt #endif
    274  1.1.1.1.4.2  yamt #if defined (EPROTO)
    275  1.1.1.1.4.2  yamt   ENTRY(EPROTO, "EPROTO", "Protocol error"),
    276  1.1.1.1.4.2  yamt #endif
    277  1.1.1.1.4.2  yamt #if defined (EMULTIHOP)
    278  1.1.1.1.4.2  yamt   ENTRY(EMULTIHOP, "EMULTIHOP", "Multihop attempted"),
    279  1.1.1.1.4.2  yamt #endif
    280  1.1.1.1.4.2  yamt #if defined (EDOTDOT)
    281  1.1.1.1.4.2  yamt   ENTRY(EDOTDOT, "EDOTDOT", "RFS specific error"),
    282  1.1.1.1.4.2  yamt #endif
    283  1.1.1.1.4.2  yamt #if defined (EBADMSG)
    284  1.1.1.1.4.2  yamt   ENTRY(EBADMSG, "EBADMSG", "Not a data message"),
    285  1.1.1.1.4.2  yamt #endif
    286  1.1.1.1.4.2  yamt #if defined (ENAMETOOLONG)
    287  1.1.1.1.4.2  yamt   ENTRY(ENAMETOOLONG, "ENAMETOOLONG", "File name too long"),
    288  1.1.1.1.4.2  yamt #endif
    289  1.1.1.1.4.2  yamt #if defined (EOVERFLOW)
    290  1.1.1.1.4.2  yamt   ENTRY(EOVERFLOW, "EOVERFLOW", "Value too large for defined data type"),
    291  1.1.1.1.4.2  yamt #endif
    292  1.1.1.1.4.2  yamt #if defined (ENOTUNIQ)
    293  1.1.1.1.4.2  yamt   ENTRY(ENOTUNIQ, "ENOTUNIQ", "Name not unique on network"),
    294  1.1.1.1.4.2  yamt #endif
    295  1.1.1.1.4.2  yamt #if defined (EBADFD)
    296  1.1.1.1.4.2  yamt   ENTRY(EBADFD, "EBADFD", "File descriptor in bad state"),
    297  1.1.1.1.4.2  yamt #endif
    298  1.1.1.1.4.2  yamt #if defined (EREMCHG)
    299  1.1.1.1.4.2  yamt   ENTRY(EREMCHG, "EREMCHG", "Remote address changed"),
    300  1.1.1.1.4.2  yamt #endif
    301  1.1.1.1.4.2  yamt #if defined (ELIBACC)
    302  1.1.1.1.4.2  yamt   ENTRY(ELIBACC, "ELIBACC", "Can not access a needed shared library"),
    303  1.1.1.1.4.2  yamt #endif
    304  1.1.1.1.4.2  yamt #if defined (ELIBBAD)
    305  1.1.1.1.4.2  yamt   ENTRY(ELIBBAD, "ELIBBAD", "Accessing a corrupted shared library"),
    306  1.1.1.1.4.2  yamt #endif
    307  1.1.1.1.4.2  yamt #if defined (ELIBSCN)
    308  1.1.1.1.4.2  yamt   ENTRY(ELIBSCN, "ELIBSCN", ".lib section in a.out corrupted"),
    309  1.1.1.1.4.2  yamt #endif
    310  1.1.1.1.4.2  yamt #if defined (ELIBMAX)
    311  1.1.1.1.4.2  yamt   ENTRY(ELIBMAX, "ELIBMAX", "Attempting to link in too many shared libraries"),
    312  1.1.1.1.4.2  yamt #endif
    313  1.1.1.1.4.2  yamt #if defined (ELIBEXEC)
    314  1.1.1.1.4.2  yamt   ENTRY(ELIBEXEC, "ELIBEXEC", "Cannot exec a shared library directly"),
    315  1.1.1.1.4.2  yamt #endif
    316  1.1.1.1.4.2  yamt #if defined (EILSEQ)
    317  1.1.1.1.4.2  yamt   ENTRY(EILSEQ, "EILSEQ", "Illegal byte sequence"),
    318  1.1.1.1.4.2  yamt #endif
    319  1.1.1.1.4.2  yamt #if defined (ENOSYS)
    320  1.1.1.1.4.2  yamt   ENTRY(ENOSYS, "ENOSYS", "Operation not applicable"),
    321  1.1.1.1.4.2  yamt #endif
    322  1.1.1.1.4.2  yamt #if defined (ELOOP)
    323  1.1.1.1.4.2  yamt   ENTRY(ELOOP, "ELOOP", "Too many symbolic links encountered"),
    324  1.1.1.1.4.2  yamt #endif
    325  1.1.1.1.4.2  yamt #if defined (ERESTART)
    326  1.1.1.1.4.2  yamt   ENTRY(ERESTART, "ERESTART", "Interrupted system call should be restarted"),
    327  1.1.1.1.4.2  yamt #endif
    328  1.1.1.1.4.2  yamt #if defined (ESTRPIPE)
    329  1.1.1.1.4.2  yamt   ENTRY(ESTRPIPE, "ESTRPIPE", "Streams pipe error"),
    330  1.1.1.1.4.2  yamt #endif
    331  1.1.1.1.4.2  yamt #if defined (ENOTEMPTY)
    332  1.1.1.1.4.2  yamt   ENTRY(ENOTEMPTY, "ENOTEMPTY", "Directory not empty"),
    333  1.1.1.1.4.2  yamt #endif
    334  1.1.1.1.4.2  yamt #if defined (EUSERS)
    335  1.1.1.1.4.2  yamt   ENTRY(EUSERS, "EUSERS", "Too many users"),
    336  1.1.1.1.4.2  yamt #endif
    337  1.1.1.1.4.2  yamt #if defined (ENOTSOCK)
    338  1.1.1.1.4.2  yamt   ENTRY(ENOTSOCK, "ENOTSOCK", "Socket operation on non-socket"),
    339  1.1.1.1.4.2  yamt #endif
    340  1.1.1.1.4.2  yamt #if defined (EDESTADDRREQ)
    341  1.1.1.1.4.2  yamt   ENTRY(EDESTADDRREQ, "EDESTADDRREQ", "Destination address required"),
    342  1.1.1.1.4.2  yamt #endif
    343  1.1.1.1.4.2  yamt #if defined (EMSGSIZE)
    344  1.1.1.1.4.2  yamt   ENTRY(EMSGSIZE, "EMSGSIZE", "Message too long"),
    345  1.1.1.1.4.2  yamt #endif
    346  1.1.1.1.4.2  yamt #if defined (EPROTOTYPE)
    347  1.1.1.1.4.2  yamt   ENTRY(EPROTOTYPE, "EPROTOTYPE", "Protocol wrong type for socket"),
    348  1.1.1.1.4.2  yamt #endif
    349  1.1.1.1.4.2  yamt #if defined (ENOPROTOOPT)
    350  1.1.1.1.4.2  yamt   ENTRY(ENOPROTOOPT, "ENOPROTOOPT", "Protocol option not available"),
    351  1.1.1.1.4.2  yamt #endif
    352  1.1.1.1.4.2  yamt #if defined (EPROTONOSUPPORT)
    353  1.1.1.1.4.2  yamt   ENTRY(EPROTONOSUPPORT, "EPROTONOSUPPORT", "Protocol not supported"),
    354  1.1.1.1.4.2  yamt #endif
    355  1.1.1.1.4.2  yamt #if defined (ESOCKTNOSUPPORT)
    356  1.1.1.1.4.2  yamt   ENTRY(ESOCKTNOSUPPORT, "ESOCKTNOSUPPORT", "Socket type not supported"),
    357  1.1.1.1.4.2  yamt #endif
    358  1.1.1.1.4.2  yamt #if defined (EOPNOTSUPP)
    359  1.1.1.1.4.2  yamt   ENTRY(EOPNOTSUPP, "EOPNOTSUPP", "Operation not supported on transport endpoint"),
    360  1.1.1.1.4.2  yamt #endif
    361  1.1.1.1.4.2  yamt #if defined (EPFNOSUPPORT)
    362  1.1.1.1.4.2  yamt   ENTRY(EPFNOSUPPORT, "EPFNOSUPPORT", "Protocol family not supported"),
    363  1.1.1.1.4.2  yamt #endif
    364  1.1.1.1.4.2  yamt #if defined (EAFNOSUPPORT)
    365  1.1.1.1.4.2  yamt   ENTRY(EAFNOSUPPORT, "EAFNOSUPPORT", "Address family not supported by protocol"),
    366  1.1.1.1.4.2  yamt #endif
    367  1.1.1.1.4.2  yamt #if defined (EADDRINUSE)
    368  1.1.1.1.4.2  yamt   ENTRY(EADDRINUSE, "EADDRINUSE", "Address already in use"),
    369  1.1.1.1.4.2  yamt #endif
    370  1.1.1.1.4.2  yamt #if defined (EADDRNOTAVAIL)
    371  1.1.1.1.4.2  yamt   ENTRY(EADDRNOTAVAIL, "EADDRNOTAVAIL","Cannot assign requested address"),
    372  1.1.1.1.4.2  yamt #endif
    373  1.1.1.1.4.2  yamt #if defined (ENETDOWN)
    374  1.1.1.1.4.2  yamt   ENTRY(ENETDOWN, "ENETDOWN", "Network is down"),
    375  1.1.1.1.4.2  yamt #endif
    376  1.1.1.1.4.2  yamt #if defined (ENETUNREACH)
    377  1.1.1.1.4.2  yamt   ENTRY(ENETUNREACH, "ENETUNREACH", "Network is unreachable"),
    378  1.1.1.1.4.2  yamt #endif
    379  1.1.1.1.4.2  yamt #if defined (ENETRESET)
    380  1.1.1.1.4.2  yamt   ENTRY(ENETRESET, "ENETRESET", "Network dropped connection because of reset"),
    381  1.1.1.1.4.2  yamt #endif
    382  1.1.1.1.4.2  yamt #if defined (ECONNABORTED)
    383  1.1.1.1.4.2  yamt   ENTRY(ECONNABORTED, "ECONNABORTED", "Software caused connection abort"),
    384  1.1.1.1.4.2  yamt #endif
    385  1.1.1.1.4.2  yamt #if defined (ECONNRESET)
    386  1.1.1.1.4.2  yamt   ENTRY(ECONNRESET, "ECONNRESET", "Connection reset by peer"),
    387  1.1.1.1.4.2  yamt #endif
    388  1.1.1.1.4.2  yamt #if defined (ENOBUFS)
    389  1.1.1.1.4.2  yamt   ENTRY(ENOBUFS, "ENOBUFS", "No buffer space available"),
    390  1.1.1.1.4.2  yamt #endif
    391  1.1.1.1.4.2  yamt #if defined (EISCONN)
    392  1.1.1.1.4.2  yamt   ENTRY(EISCONN, "EISCONN", "Transport endpoint is already connected"),
    393  1.1.1.1.4.2  yamt #endif
    394  1.1.1.1.4.2  yamt #if defined (ENOTCONN)
    395  1.1.1.1.4.2  yamt   ENTRY(ENOTCONN, "ENOTCONN", "Transport endpoint is not connected"),
    396  1.1.1.1.4.2  yamt #endif
    397  1.1.1.1.4.2  yamt #if defined (ESHUTDOWN)
    398  1.1.1.1.4.2  yamt   ENTRY(ESHUTDOWN, "ESHUTDOWN", "Cannot send after transport endpoint shutdown"),
    399  1.1.1.1.4.2  yamt #endif
    400  1.1.1.1.4.2  yamt #if defined (ETOOMANYREFS)
    401  1.1.1.1.4.2  yamt   ENTRY(ETOOMANYREFS, "ETOOMANYREFS", "Too many references: cannot splice"),
    402  1.1.1.1.4.2  yamt #endif
    403  1.1.1.1.4.2  yamt #if defined (ETIMEDOUT)
    404  1.1.1.1.4.2  yamt   ENTRY(ETIMEDOUT, "ETIMEDOUT", "Connection timed out"),
    405  1.1.1.1.4.2  yamt #endif
    406  1.1.1.1.4.2  yamt #if defined (ECONNREFUSED)
    407  1.1.1.1.4.2  yamt   ENTRY(ECONNREFUSED, "ECONNREFUSED", "Connection refused"),
    408  1.1.1.1.4.2  yamt #endif
    409  1.1.1.1.4.2  yamt #if defined (EHOSTDOWN)
    410  1.1.1.1.4.2  yamt   ENTRY(EHOSTDOWN, "EHOSTDOWN", "Host is down"),
    411  1.1.1.1.4.2  yamt #endif
    412  1.1.1.1.4.2  yamt #if defined (EHOSTUNREACH)
    413  1.1.1.1.4.2  yamt   ENTRY(EHOSTUNREACH, "EHOSTUNREACH", "No route to host"),
    414  1.1.1.1.4.2  yamt #endif
    415  1.1.1.1.4.2  yamt #if defined (EALREADY)
    416  1.1.1.1.4.2  yamt   ENTRY(EALREADY, "EALREADY", "Operation already in progress"),
    417  1.1.1.1.4.2  yamt #endif
    418  1.1.1.1.4.2  yamt #if defined (EINPROGRESS)
    419  1.1.1.1.4.2  yamt   ENTRY(EINPROGRESS, "EINPROGRESS", "Operation now in progress"),
    420  1.1.1.1.4.2  yamt #endif
    421  1.1.1.1.4.2  yamt #if defined (ESTALE)
    422  1.1.1.1.4.2  yamt   ENTRY(ESTALE, "ESTALE", "Stale NFS file handle"),
    423  1.1.1.1.4.2  yamt #endif
    424  1.1.1.1.4.2  yamt #if defined (EUCLEAN)
    425  1.1.1.1.4.2  yamt   ENTRY(EUCLEAN, "EUCLEAN", "Structure needs cleaning"),
    426  1.1.1.1.4.2  yamt #endif
    427  1.1.1.1.4.2  yamt #if defined (ENOTNAM)
    428  1.1.1.1.4.2  yamt   ENTRY(ENOTNAM, "ENOTNAM", "Not a XENIX named type file"),
    429  1.1.1.1.4.2  yamt #endif
    430  1.1.1.1.4.2  yamt #if defined (ENAVAIL)
    431  1.1.1.1.4.2  yamt   ENTRY(ENAVAIL, "ENAVAIL", "No XENIX semaphores available"),
    432  1.1.1.1.4.2  yamt #endif
    433  1.1.1.1.4.2  yamt #if defined (EISNAM)
    434  1.1.1.1.4.2  yamt   ENTRY(EISNAM, "EISNAM", "Is a named type file"),
    435  1.1.1.1.4.2  yamt #endif
    436  1.1.1.1.4.2  yamt #if defined (EREMOTEIO)
    437  1.1.1.1.4.2  yamt   ENTRY(EREMOTEIO, "EREMOTEIO", "Remote I/O error"),
    438  1.1.1.1.4.2  yamt #endif
    439  1.1.1.1.4.2  yamt   ENTRY(0, NULL, NULL)
    440  1.1.1.1.4.2  yamt };
    441  1.1.1.1.4.2  yamt 
    442  1.1.1.1.4.2  yamt #ifdef EVMSERR
    443  1.1.1.1.4.2  yamt /* This is not in the table, because the numeric value of EVMSERR (32767)
    444  1.1.1.1.4.2  yamt    lies outside the range of sys_errlist[].  */
    445  1.1.1.1.4.2  yamt static struct { int value; const char *name, *msg; }
    446  1.1.1.1.4.2  yamt   evmserr = { EVMSERR, "EVMSERR", "VMS-specific error" };
    447  1.1.1.1.4.2  yamt #endif
    448  1.1.1.1.4.2  yamt 
    449  1.1.1.1.4.2  yamt /* Translation table allocated and initialized at runtime.  Indexed by the
    450  1.1.1.1.4.2  yamt    errno value to find the equivalent symbolic value. */
    451  1.1.1.1.4.2  yamt 
    452  1.1.1.1.4.2  yamt static const char **error_names;
    453  1.1.1.1.4.2  yamt static int num_error_names = 0;
    454  1.1.1.1.4.2  yamt 
    455  1.1.1.1.4.2  yamt /* Translation table allocated and initialized at runtime, if it does not
    456  1.1.1.1.4.2  yamt    already exist in the host environment.  Indexed by the errno value to find
    457  1.1.1.1.4.2  yamt    the descriptive string.
    458  1.1.1.1.4.2  yamt 
    459  1.1.1.1.4.2  yamt    We don't export it for use in other modules because even though it has the
    460  1.1.1.1.4.2  yamt    same name, it differs from other implementations in that it is dynamically
    461  1.1.1.1.4.2  yamt    initialized rather than statically initialized. */
    462  1.1.1.1.4.2  yamt 
    463  1.1.1.1.4.2  yamt #ifndef HAVE_SYS_ERRLIST
    464  1.1.1.1.4.2  yamt 
    465  1.1.1.1.4.2  yamt #define sys_nerr sys_nerr__
    466  1.1.1.1.4.2  yamt #define sys_errlist sys_errlist__
    467  1.1.1.1.4.2  yamt static int sys_nerr;
    468  1.1.1.1.4.2  yamt static const char **sys_errlist;
    469  1.1.1.1.4.2  yamt 
    470  1.1.1.1.4.2  yamt #else
    471  1.1.1.1.4.2  yamt 
    472  1.1.1.1.4.2  yamt extern int sys_nerr;
    473  1.1.1.1.4.2  yamt extern char *sys_errlist[];
    474  1.1.1.1.4.2  yamt 
    475  1.1.1.1.4.2  yamt #endif
    476  1.1.1.1.4.2  yamt 
    477  1.1.1.1.4.2  yamt /*
    478  1.1.1.1.4.2  yamt 
    479  1.1.1.1.4.2  yamt NAME
    480  1.1.1.1.4.2  yamt 
    481  1.1.1.1.4.2  yamt 	init_error_tables -- initialize the name and message tables
    482  1.1.1.1.4.2  yamt 
    483  1.1.1.1.4.2  yamt SYNOPSIS
    484  1.1.1.1.4.2  yamt 
    485  1.1.1.1.4.2  yamt 	static void init_error_tables ();
    486  1.1.1.1.4.2  yamt 
    487  1.1.1.1.4.2  yamt DESCRIPTION
    488  1.1.1.1.4.2  yamt 
    489  1.1.1.1.4.2  yamt 	Using the error_table, which is initialized at compile time, generate
    490  1.1.1.1.4.2  yamt 	the error_names and the sys_errlist (if needed) tables, which are
    491  1.1.1.1.4.2  yamt 	indexed at runtime by a specific errno value.
    492  1.1.1.1.4.2  yamt 
    493  1.1.1.1.4.2  yamt BUGS
    494  1.1.1.1.4.2  yamt 
    495  1.1.1.1.4.2  yamt 	The initialization of the tables may fail under low memory conditions,
    496  1.1.1.1.4.2  yamt 	in which case we don't do anything particularly useful, but we don't
    497  1.1.1.1.4.2  yamt 	bomb either.  Who knows, it might succeed at a later point if we free
    498  1.1.1.1.4.2  yamt 	some memory in the meantime.  In any case, the other routines know
    499  1.1.1.1.4.2  yamt 	how to deal with lack of a table after trying to initialize it.  This
    500  1.1.1.1.4.2  yamt 	may or may not be considered to be a bug, that we don't specifically
    501  1.1.1.1.4.2  yamt 	warn about this particular failure mode.
    502  1.1.1.1.4.2  yamt 
    503  1.1.1.1.4.2  yamt */
    504  1.1.1.1.4.2  yamt 
    505  1.1.1.1.4.2  yamt static void
    506  1.1.1.1.4.2  yamt init_error_tables (void)
    507  1.1.1.1.4.2  yamt {
    508  1.1.1.1.4.2  yamt   const struct error_info *eip;
    509  1.1.1.1.4.2  yamt   int nbytes;
    510  1.1.1.1.4.2  yamt 
    511  1.1.1.1.4.2  yamt   /* If we haven't already scanned the error_table once to find the maximum
    512  1.1.1.1.4.2  yamt      errno value, then go find it now. */
    513  1.1.1.1.4.2  yamt 
    514  1.1.1.1.4.2  yamt   if (num_error_names == 0)
    515  1.1.1.1.4.2  yamt     {
    516  1.1.1.1.4.2  yamt       for (eip = error_table; eip -> name != NULL; eip++)
    517  1.1.1.1.4.2  yamt 	{
    518  1.1.1.1.4.2  yamt 	  if (eip -> value >= num_error_names)
    519  1.1.1.1.4.2  yamt 	    {
    520  1.1.1.1.4.2  yamt 	      num_error_names = eip -> value + 1;
    521  1.1.1.1.4.2  yamt 	    }
    522  1.1.1.1.4.2  yamt 	}
    523  1.1.1.1.4.2  yamt     }
    524  1.1.1.1.4.2  yamt 
    525  1.1.1.1.4.2  yamt   /* Now attempt to allocate the error_names table, zero it out, and then
    526  1.1.1.1.4.2  yamt      initialize it from the statically initialized error_table. */
    527  1.1.1.1.4.2  yamt 
    528  1.1.1.1.4.2  yamt   if (error_names == NULL)
    529  1.1.1.1.4.2  yamt     {
    530  1.1.1.1.4.2  yamt       nbytes = num_error_names * sizeof (char *);
    531  1.1.1.1.4.2  yamt       if ((error_names = (const char **) malloc (nbytes)) != NULL)
    532  1.1.1.1.4.2  yamt 	{
    533  1.1.1.1.4.2  yamt 	  memset (error_names, 0, nbytes);
    534  1.1.1.1.4.2  yamt 	  for (eip = error_table; eip -> name != NULL; eip++)
    535  1.1.1.1.4.2  yamt 	    {
    536  1.1.1.1.4.2  yamt 	      error_names[eip -> value] = eip -> name;
    537  1.1.1.1.4.2  yamt 	    }
    538  1.1.1.1.4.2  yamt 	}
    539  1.1.1.1.4.2  yamt     }
    540  1.1.1.1.4.2  yamt 
    541  1.1.1.1.4.2  yamt #ifndef HAVE_SYS_ERRLIST
    542  1.1.1.1.4.2  yamt 
    543  1.1.1.1.4.2  yamt   /* Now attempt to allocate the sys_errlist table, zero it out, and then
    544  1.1.1.1.4.2  yamt      initialize it from the statically initialized error_table. */
    545  1.1.1.1.4.2  yamt 
    546  1.1.1.1.4.2  yamt   if (sys_errlist == NULL)
    547  1.1.1.1.4.2  yamt     {
    548  1.1.1.1.4.2  yamt       nbytes = num_error_names * sizeof (char *);
    549  1.1.1.1.4.2  yamt       if ((sys_errlist = (const char **) malloc (nbytes)) != NULL)
    550  1.1.1.1.4.2  yamt 	{
    551  1.1.1.1.4.2  yamt 	  memset (sys_errlist, 0, nbytes);
    552  1.1.1.1.4.2  yamt 	  sys_nerr = num_error_names;
    553  1.1.1.1.4.2  yamt 	  for (eip = error_table; eip -> name != NULL; eip++)
    554  1.1.1.1.4.2  yamt 	    {
    555  1.1.1.1.4.2  yamt 	      sys_errlist[eip -> value] = eip -> msg;
    556  1.1.1.1.4.2  yamt 	    }
    557  1.1.1.1.4.2  yamt 	}
    558  1.1.1.1.4.2  yamt     }
    559  1.1.1.1.4.2  yamt 
    560  1.1.1.1.4.2  yamt #endif
    561  1.1.1.1.4.2  yamt 
    562  1.1.1.1.4.2  yamt }
    563  1.1.1.1.4.2  yamt 
    564  1.1.1.1.4.2  yamt /*
    565  1.1.1.1.4.2  yamt 
    566  1.1.1.1.4.2  yamt 
    567  1.1.1.1.4.2  yamt @deftypefn Extension int errno_max (void)
    568  1.1.1.1.4.2  yamt 
    569  1.1.1.1.4.2  yamt Returns the maximum @code{errno} value for which a corresponding
    570  1.1.1.1.4.2  yamt symbolic name or message is available.  Note that in the case where we
    571  1.1.1.1.4.2  yamt use the @code{sys_errlist} supplied by the system, it is possible for
    572  1.1.1.1.4.2  yamt there to be more symbolic names than messages, or vice versa.  In
    573  1.1.1.1.4.2  yamt fact, the manual page for @code{perror(3C)} explicitly warns that one
    574  1.1.1.1.4.2  yamt should check the size of the table (@code{sys_nerr}) before indexing
    575  1.1.1.1.4.2  yamt it, since new error codes may be added to the system before they are
    576  1.1.1.1.4.2  yamt added to the table.  Thus @code{sys_nerr} might be smaller than value
    577  1.1.1.1.4.2  yamt implied by the largest @code{errno} value defined in @code{<errno.h>}.
    578  1.1.1.1.4.2  yamt 
    579  1.1.1.1.4.2  yamt We return the maximum value that can be used to obtain a meaningful
    580  1.1.1.1.4.2  yamt symbolic name or message.
    581  1.1.1.1.4.2  yamt 
    582  1.1.1.1.4.2  yamt @end deftypefn
    583  1.1.1.1.4.2  yamt 
    584  1.1.1.1.4.2  yamt */
    585  1.1.1.1.4.2  yamt 
    586  1.1.1.1.4.2  yamt int
    587  1.1.1.1.4.2  yamt errno_max (void)
    588  1.1.1.1.4.2  yamt {
    589  1.1.1.1.4.2  yamt   int maxsize;
    590  1.1.1.1.4.2  yamt 
    591  1.1.1.1.4.2  yamt   if (error_names == NULL)
    592  1.1.1.1.4.2  yamt     {
    593  1.1.1.1.4.2  yamt       init_error_tables ();
    594  1.1.1.1.4.2  yamt     }
    595  1.1.1.1.4.2  yamt   maxsize = MAX (sys_nerr, num_error_names);
    596  1.1.1.1.4.2  yamt   return (maxsize - 1);
    597  1.1.1.1.4.2  yamt }
    598  1.1.1.1.4.2  yamt 
    599  1.1.1.1.4.2  yamt #ifndef HAVE_STRERROR
    600  1.1.1.1.4.2  yamt 
    601  1.1.1.1.4.2  yamt /*
    602  1.1.1.1.4.2  yamt 
    603  1.1.1.1.4.2  yamt @deftypefn Supplemental char* strerror (int @var{errnoval})
    604  1.1.1.1.4.2  yamt 
    605  1.1.1.1.4.2  yamt Maps an @code{errno} number to an error message string, the contents
    606  1.1.1.1.4.2  yamt of which are implementation defined.  On systems which have the
    607  1.1.1.1.4.2  yamt external variables @code{sys_nerr} and @code{sys_errlist}, these
    608  1.1.1.1.4.2  yamt strings will be the same as the ones used by @code{perror}.
    609  1.1.1.1.4.2  yamt 
    610  1.1.1.1.4.2  yamt If the supplied error number is within the valid range of indices for
    611  1.1.1.1.4.2  yamt the @code{sys_errlist}, but no message is available for the particular
    612  1.1.1.1.4.2  yamt error number, then returns the string @samp{Error @var{num}}, where
    613  1.1.1.1.4.2  yamt @var{num} is the error number.
    614  1.1.1.1.4.2  yamt 
    615  1.1.1.1.4.2  yamt If the supplied error number is not a valid index into
    616  1.1.1.1.4.2  yamt @code{sys_errlist}, returns @code{NULL}.
    617  1.1.1.1.4.2  yamt 
    618  1.1.1.1.4.2  yamt The returned string is only guaranteed to be valid only until the
    619  1.1.1.1.4.2  yamt next call to @code{strerror}.
    620  1.1.1.1.4.2  yamt 
    621  1.1.1.1.4.2  yamt @end deftypefn
    622  1.1.1.1.4.2  yamt 
    623  1.1.1.1.4.2  yamt */
    624  1.1.1.1.4.2  yamt 
    625  1.1.1.1.4.2  yamt char *
    626  1.1.1.1.4.2  yamt strerror (int errnoval)
    627  1.1.1.1.4.2  yamt {
    628  1.1.1.1.4.2  yamt   const char *msg;
    629  1.1.1.1.4.2  yamt   static char buf[32];
    630  1.1.1.1.4.2  yamt 
    631  1.1.1.1.4.2  yamt #ifndef HAVE_SYS_ERRLIST
    632  1.1.1.1.4.2  yamt 
    633  1.1.1.1.4.2  yamt   if (error_names == NULL)
    634  1.1.1.1.4.2  yamt     {
    635  1.1.1.1.4.2  yamt       init_error_tables ();
    636  1.1.1.1.4.2  yamt     }
    637  1.1.1.1.4.2  yamt 
    638  1.1.1.1.4.2  yamt #endif
    639  1.1.1.1.4.2  yamt 
    640  1.1.1.1.4.2  yamt   if ((errnoval < 0) || (errnoval >= sys_nerr))
    641  1.1.1.1.4.2  yamt     {
    642  1.1.1.1.4.2  yamt #ifdef EVMSERR
    643  1.1.1.1.4.2  yamt       if (errnoval == evmserr.value)
    644  1.1.1.1.4.2  yamt 	msg = evmserr.msg;
    645  1.1.1.1.4.2  yamt       else
    646  1.1.1.1.4.2  yamt #endif
    647  1.1.1.1.4.2  yamt       /* Out of range, just return NULL */
    648  1.1.1.1.4.2  yamt       msg = NULL;
    649  1.1.1.1.4.2  yamt     }
    650  1.1.1.1.4.2  yamt   else if ((sys_errlist == NULL) || (sys_errlist[errnoval] == NULL))
    651  1.1.1.1.4.2  yamt     {
    652  1.1.1.1.4.2  yamt       /* In range, but no sys_errlist or no entry at this index. */
    653  1.1.1.1.4.2  yamt       sprintf (buf, "Error %d", errnoval);
    654  1.1.1.1.4.2  yamt       msg = buf;
    655  1.1.1.1.4.2  yamt     }
    656  1.1.1.1.4.2  yamt   else
    657  1.1.1.1.4.2  yamt     {
    658  1.1.1.1.4.2  yamt       /* In range, and a valid message.  Just return the message. */
    659  1.1.1.1.4.2  yamt       msg = (char *) sys_errlist[errnoval];
    660  1.1.1.1.4.2  yamt     }
    661  1.1.1.1.4.2  yamt 
    662  1.1.1.1.4.2  yamt   return (msg);
    663  1.1.1.1.4.2  yamt }
    664  1.1.1.1.4.2  yamt 
    665  1.1.1.1.4.2  yamt #endif	/* ! HAVE_STRERROR */
    666  1.1.1.1.4.2  yamt 
    667  1.1.1.1.4.2  yamt 
    668  1.1.1.1.4.2  yamt /*
    669  1.1.1.1.4.2  yamt 
    670  1.1.1.1.4.2  yamt @deftypefn Replacement {const char*} strerrno (int @var{errnum})
    671  1.1.1.1.4.2  yamt 
    672  1.1.1.1.4.2  yamt Given an error number returned from a system call (typically returned
    673  1.1.1.1.4.2  yamt in @code{errno}), returns a pointer to a string containing the
    674  1.1.1.1.4.2  yamt symbolic name of that error number, as found in @code{<errno.h>}.
    675  1.1.1.1.4.2  yamt 
    676  1.1.1.1.4.2  yamt If the supplied error number is within the valid range of indices for
    677  1.1.1.1.4.2  yamt symbolic names, but no name is available for the particular error
    678  1.1.1.1.4.2  yamt number, then returns the string @samp{Error @var{num}}, where @var{num}
    679  1.1.1.1.4.2  yamt is the error number.
    680  1.1.1.1.4.2  yamt 
    681  1.1.1.1.4.2  yamt If the supplied error number is not within the range of valid
    682  1.1.1.1.4.2  yamt indices, then returns @code{NULL}.
    683  1.1.1.1.4.2  yamt 
    684  1.1.1.1.4.2  yamt The contents of the location pointed to are only guaranteed to be
    685  1.1.1.1.4.2  yamt valid until the next call to @code{strerrno}.
    686  1.1.1.1.4.2  yamt 
    687  1.1.1.1.4.2  yamt @end deftypefn
    688  1.1.1.1.4.2  yamt 
    689  1.1.1.1.4.2  yamt */
    690  1.1.1.1.4.2  yamt 
    691  1.1.1.1.4.2  yamt const char *
    692  1.1.1.1.4.2  yamt strerrno (int errnoval)
    693  1.1.1.1.4.2  yamt {
    694  1.1.1.1.4.2  yamt   const char *name;
    695  1.1.1.1.4.2  yamt   static char buf[32];
    696  1.1.1.1.4.2  yamt 
    697  1.1.1.1.4.2  yamt   if (error_names == NULL)
    698  1.1.1.1.4.2  yamt     {
    699  1.1.1.1.4.2  yamt       init_error_tables ();
    700  1.1.1.1.4.2  yamt     }
    701  1.1.1.1.4.2  yamt 
    702  1.1.1.1.4.2  yamt   if ((errnoval < 0) || (errnoval >= num_error_names))
    703  1.1.1.1.4.2  yamt     {
    704  1.1.1.1.4.2  yamt #ifdef EVMSERR
    705  1.1.1.1.4.2  yamt       if (errnoval == evmserr.value)
    706  1.1.1.1.4.2  yamt 	name = evmserr.name;
    707  1.1.1.1.4.2  yamt       else
    708  1.1.1.1.4.2  yamt #endif
    709  1.1.1.1.4.2  yamt       /* Out of range, just return NULL */
    710  1.1.1.1.4.2  yamt       name = NULL;
    711  1.1.1.1.4.2  yamt     }
    712  1.1.1.1.4.2  yamt   else if ((error_names == NULL) || (error_names[errnoval] == NULL))
    713  1.1.1.1.4.2  yamt     {
    714  1.1.1.1.4.2  yamt       /* In range, but no error_names or no entry at this index. */
    715  1.1.1.1.4.2  yamt       sprintf (buf, "Error %d", errnoval);
    716  1.1.1.1.4.2  yamt       name = (const char *) buf;
    717  1.1.1.1.4.2  yamt     }
    718  1.1.1.1.4.2  yamt   else
    719  1.1.1.1.4.2  yamt     {
    720  1.1.1.1.4.2  yamt       /* In range, and a valid name.  Just return the name. */
    721  1.1.1.1.4.2  yamt       name = error_names[errnoval];
    722  1.1.1.1.4.2  yamt     }
    723  1.1.1.1.4.2  yamt 
    724  1.1.1.1.4.2  yamt   return (name);
    725  1.1.1.1.4.2  yamt }
    726  1.1.1.1.4.2  yamt 
    727  1.1.1.1.4.2  yamt /*
    728  1.1.1.1.4.2  yamt 
    729  1.1.1.1.4.2  yamt @deftypefn Extension int strtoerrno (const char *@var{name})
    730  1.1.1.1.4.2  yamt 
    731  1.1.1.1.4.2  yamt Given the symbolic name of a error number (e.g., @code{EACCES}), map it
    732  1.1.1.1.4.2  yamt to an errno value.  If no translation is found, returns 0.
    733  1.1.1.1.4.2  yamt 
    734  1.1.1.1.4.2  yamt @end deftypefn
    735  1.1.1.1.4.2  yamt 
    736  1.1.1.1.4.2  yamt */
    737  1.1.1.1.4.2  yamt 
    738  1.1.1.1.4.2  yamt int
    739  1.1.1.1.4.2  yamt strtoerrno (const char *name)
    740  1.1.1.1.4.2  yamt {
    741  1.1.1.1.4.2  yamt   int errnoval = 0;
    742  1.1.1.1.4.2  yamt 
    743  1.1.1.1.4.2  yamt   if (name != NULL)
    744  1.1.1.1.4.2  yamt     {
    745  1.1.1.1.4.2  yamt       if (error_names == NULL)
    746  1.1.1.1.4.2  yamt 	{
    747  1.1.1.1.4.2  yamt 	  init_error_tables ();
    748  1.1.1.1.4.2  yamt 	}
    749  1.1.1.1.4.2  yamt       for (errnoval = 0; errnoval < num_error_names; errnoval++)
    750  1.1.1.1.4.2  yamt 	{
    751  1.1.1.1.4.2  yamt 	  if ((error_names[errnoval] != NULL) &&
    752  1.1.1.1.4.2  yamt 	      (strcmp (name, error_names[errnoval]) == 0))
    753  1.1.1.1.4.2  yamt 	    {
    754  1.1.1.1.4.2  yamt 	      break;
    755  1.1.1.1.4.2  yamt 	    }
    756  1.1.1.1.4.2  yamt 	}
    757  1.1.1.1.4.2  yamt       if (errnoval == num_error_names)
    758  1.1.1.1.4.2  yamt 	{
    759  1.1.1.1.4.2  yamt #ifdef EVMSERR
    760  1.1.1.1.4.2  yamt 	  if (strcmp (name, evmserr.name) == 0)
    761  1.1.1.1.4.2  yamt 	    errnoval = evmserr.value;
    762  1.1.1.1.4.2  yamt 	  else
    763  1.1.1.1.4.2  yamt #endif
    764  1.1.1.1.4.2  yamt 	  errnoval = 0;
    765  1.1.1.1.4.2  yamt 	}
    766  1.1.1.1.4.2  yamt     }
    767  1.1.1.1.4.2  yamt   return (errnoval);
    768  1.1.1.1.4.2  yamt }
    769  1.1.1.1.4.2  yamt 
    770  1.1.1.1.4.2  yamt 
    771  1.1.1.1.4.2  yamt /* A simple little main that does nothing but print all the errno translations
    772  1.1.1.1.4.2  yamt    if MAIN is defined and this file is compiled and linked. */
    773  1.1.1.1.4.2  yamt 
    774  1.1.1.1.4.2  yamt #ifdef MAIN
    775  1.1.1.1.4.2  yamt 
    776  1.1.1.1.4.2  yamt #include <stdio.h>
    777  1.1.1.1.4.2  yamt 
    778  1.1.1.1.4.2  yamt int
    779  1.1.1.1.4.2  yamt main (void)
    780  1.1.1.1.4.2  yamt {
    781  1.1.1.1.4.2  yamt   int errn;
    782  1.1.1.1.4.2  yamt   int errnmax;
    783  1.1.1.1.4.2  yamt   const char *name;
    784  1.1.1.1.4.2  yamt   const char *msg;
    785  1.1.1.1.4.2  yamt   char *strerror ();
    786  1.1.1.1.4.2  yamt 
    787  1.1.1.1.4.2  yamt   errnmax = errno_max ();
    788  1.1.1.1.4.2  yamt   printf ("%d entries in names table.\n", num_error_names);
    789  1.1.1.1.4.2  yamt   printf ("%d entries in messages table.\n", sys_nerr);
    790  1.1.1.1.4.2  yamt   printf ("%d is max useful index.\n", errnmax);
    791  1.1.1.1.4.2  yamt 
    792  1.1.1.1.4.2  yamt   /* Keep printing values until we get to the end of *both* tables, not
    793  1.1.1.1.4.2  yamt      *either* table.  Note that knowing the maximum useful index does *not*
    794  1.1.1.1.4.2  yamt      relieve us of the responsibility of testing the return pointer for
    795  1.1.1.1.4.2  yamt      NULL. */
    796  1.1.1.1.4.2  yamt 
    797  1.1.1.1.4.2  yamt   for (errn = 0; errn <= errnmax; errn++)
    798  1.1.1.1.4.2  yamt     {
    799  1.1.1.1.4.2  yamt       name = strerrno (errn);
    800  1.1.1.1.4.2  yamt       name = (name == NULL) ? "<NULL>" : name;
    801  1.1.1.1.4.2  yamt       msg = strerror (errn);
    802  1.1.1.1.4.2  yamt       msg = (msg == NULL) ? "<NULL>" : msg;
    803  1.1.1.1.4.2  yamt       printf ("%-4d%-18s%s\n", errn, name, msg);
    804  1.1.1.1.4.2  yamt     }
    805  1.1.1.1.4.2  yamt 
    806  1.1.1.1.4.2  yamt   return 0;
    807  1.1.1.1.4.2  yamt }
    808  1.1.1.1.4.2  yamt 
    809  1.1.1.1.4.2  yamt #endif
    810