1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
/* If we are to roll our own strerror(), we must have sys_errlist
* and sys_nerr.
*/
#include <config.h>
#undef DIRE
#ifndef HAVE_SYS_ERRLIST
#define DIRE
#endif
#ifndef HAVE_SYS_NERR
#define DIRE
#endif
#if ERRNO_H_DECLARES_SYS_ERRLIST
#include <errno.h>
#elif STDLIB_H_DECLARES_SYS_ERRLIST
#include <stdlib.h>
#elif STDIO_H_DECLARES_SYS_ERRLIST
#include <stdio.h>
#else
extern const char *sys_errlist[];
#endif
#if ERRNO_H_DECLARES_SYS_NERR
#include <errno.h>
#elif STDLIB_H_DECLARES_SYS_NERR
#include <stdlib.h>
#elif STDIO_H_DECLARES_SYS_NERR
#include <stdio.h>
#else
extern int sys_nerr;
#endif
#ifdef DIRE
/*
* No sys_nerr or no sys_errlist?
*
* Wow, that's really dire!
*/
static const char *dunno = "don't know how to decode errors -- see" __FILE__;
char *
strerror(int errnum)
{
errnum = errnum; /* use the parameter to eliminate warning. */
return (char*)dunno;
}
#else
static const char *unknown = "unknown error";
char *
strerror(int errnum)
{
if (errnum < 0 || errnum >= sys_nerr)
return (char*)unknown;
else
return (char*)sys_errlist[errnum];
}
#endif
|