File: xstrerror.c

package info (click to toggle)
gdb 8.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 223,696 kB
  • sloc: ansic: 1,936,156; asm: 341,757; exp: 146,606; makefile: 56,749; sh: 23,776; cpp: 20,830; yacc: 12,914; perl: 5,331; ada: 4,977; python: 4,617; xml: 4,176; pascal: 3,134; lisp: 1,527; cs: 879; lex: 620; f90: 479; sed: 228; awk: 140; objc: 134; fortran: 43
file content (79 lines) | stat: -rw-r--r-- 2,038 bytes parent folder | download | duplicates (86)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* xstrerror.c -- jacket routine for more robust strerror() usage.
   Fri Jun 16 18:30:00 1995  Pat Rankin  <rankin@eql.caltech.edu>
   This code is in the public domain.  */

/*

@deftypefn Replacement char* xstrerror (int @var{errnum})

Behaves exactly like the standard @code{strerror} function, but
will never return a @code{NULL} pointer.

@end deftypefn

*/

#include <stdio.h>

#include "config.h"
#include "libiberty.h"

#ifdef VMS
#  include <errno.h>
#  if !defined (__STRICT_ANSI__) && !defined (__HIDE_FORBIDDEN_NAMES)
#    ifdef __cplusplus
extern "C" {
#    endif /* __cplusplus */
extern char *strerror (int,...);
#    define DONT_DECLARE_STRERROR
#    ifdef __cplusplus
}
#    endif /* __cplusplus */
#  endif
#endif  /* VMS */


#ifndef DONT_DECLARE_STRERROR
#  ifdef __cplusplus
extern "C" {
#  endif /* __cplusplus */
extern char *strerror (int);
#  ifdef __cplusplus
}
#  endif /* __cplusplus */
#endif

/* If strerror returns NULL, we'll format the number into a static buffer.  */

#define ERRSTR_FMT "undocumented error #%d"
static char xstrerror_buf[sizeof ERRSTR_FMT + 20];

/* Like strerror, but result is never a null pointer.  */

char *
xstrerror (int errnum)
{
  char *errstr;
#ifdef VMS
  char *(*vmslib_strerror) (int,...);

  /* Override any possibly-conflicting declaration from system header.  */
  vmslib_strerror = (char *(*) (int,...)) strerror;
  /* Second argument matters iff first is EVMSERR, but it's simpler to
     pass it unconditionally.  `vaxc$errno' is declared in <errno.h>
     and maintained by the run-time library in parallel to `errno'.
     We assume that `errnum' corresponds to the last value assigned to
     errno by the run-time library, hence vaxc$errno will be relevant.  */
  errstr = (*vmslib_strerror) (errnum, vaxc$errno);
#else
  errstr = strerror (errnum);
#endif

  /* If `errnum' is out of range, result might be NULL.  We'll fix that.  */
  if (!errstr)
    {
      sprintf (xstrerror_buf, ERRSTR_FMT, errnum);
      errstr = xstrerror_buf;
    }
  return errstr;
}