]>
Commit | Line | Data |
---|---|---|
252b5132 RH |
1 | /* xstrerror.c -- jacket routine for more robust strerror() usage. |
2 | Fri Jun 16 18:30:00 1995 Pat Rankin <[email protected]> | |
3 | This code is in the public domain. */ | |
4 | ||
39423523 DD |
5 | /* |
6 | ||
7 | @deftypefn Replacement char* xstrerror (int @var{errnum}) | |
8 | ||
9 | Behaves exactly like the standard @code{strerror} function, but | |
99b58139 | 10 | will never return a @code{NULL} pointer. |
39423523 DD |
11 | |
12 | @end deftypefn | |
13 | ||
14 | */ | |
15 | ||
252b5132 RH |
16 | #include <stdio.h> |
17 | ||
252b5132 | 18 | #include "config.h" |
3e0f1404 | 19 | #include "libiberty.h" |
252b5132 RH |
20 | |
21 | #ifdef VMS | |
22 | #include <errno.h> | |
23 | #if !defined (__STRICT_ANSI__) && !defined (__HIDE_FORBIDDEN_NAMES) | |
49b1fae4 | 24 | extern char *strerror (int,...); |
252b5132 RH |
25 | #define DONT_DECLARE_STRERROR |
26 | #endif | |
27 | #endif /* VMS */ | |
28 | ||
29 | #ifndef DONT_DECLARE_STRERROR | |
49b1fae4 | 30 | extern char *strerror (int); |
252b5132 RH |
31 | #endif |
32 | ||
33 | /* If strerror returns NULL, we'll format the number into a static buffer. */ | |
34 | ||
35 | #define ERRSTR_FMT "undocumented error #%d" | |
36 | static char xstrerror_buf[sizeof ERRSTR_FMT + 20]; | |
37 | ||
38 | /* Like strerror, but result is never a null pointer. */ | |
39 | ||
40 | char * | |
49b1fae4 | 41 | xstrerror (int errnum) |
252b5132 RH |
42 | { |
43 | char *errstr; | |
44 | #ifdef VMS | |
49b1fae4 | 45 | char *(*vmslib_strerror) (int,...); |
252b5132 RH |
46 | |
47 | /* Override any possibly-conflicting declaration from system header. */ | |
49b1fae4 | 48 | vmslib_strerror = (char *(*) (int,...)) strerror; |
252b5132 RH |
49 | /* Second argument matters iff first is EVMSERR, but it's simpler to |
50 | pass it unconditionally. `vaxc$errno' is declared in <errno.h> | |
51 | and maintained by the run-time library in parallel to `errno'. | |
52 | We assume that `errnum' corresponds to the last value assigned to | |
53 | errno by the run-time library, hence vaxc$errno will be relevant. */ | |
54 | errstr = (*vmslib_strerror) (errnum, vaxc$errno); | |
55 | #else | |
56 | errstr = strerror (errnum); | |
57 | #endif | |
58 | ||
59 | /* If `errnum' is out of range, result might be NULL. We'll fix that. */ | |
60 | if (!errstr) | |
61 | { | |
62 | sprintf (xstrerror_buf, ERRSTR_FMT, errnum); | |
63 | errstr = xstrerror_buf; | |
64 | } | |
65 | return errstr; | |
66 | } |