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