File: strerror.c

package info (click to toggle)
cssc 1.0.1-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,612 kB
  • ctags: 1,424
  • sloc: cpp: 13,502; sh: 4,759; ansic: 2,971; perl: 342; makefile: 339; awk: 11
file content (64 lines) | stat: -rw-r--r-- 1,101 bytes parent folder | download | duplicates (3)
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