1 /* xstrerror.c -- jacket routine for more robust strerror() usage.
2 Fri Jun 16 18:30:00 1995 Pat Rankin <rankin@eql.caltech.edu>
3 This code is in the public domain. */
7 @deftypefn Replacement char* xstrerror (int @var{errnum})
9 Behaves exactly like the standard @code{strerror} function, but
10 will never return a @code{NULL} pointer.
19 #include "libiberty.h"
23 # if !defined (__STRICT_ANSI__) && !defined (__HIDE_FORBIDDEN_NAMES)
26 # endif /* __cplusplus */
27 extern char *strerror (int,...);
28 # define DONT_DECLARE_STRERROR
31 # endif /* __cplusplus */
36 #ifndef DONT_DECLARE_STRERROR
39 # endif /* __cplusplus */
40 extern char *strerror (int);
43 # endif /* __cplusplus */
46 /* If strerror returns NULL, we'll format the number into a static buffer. */
48 #define ERRSTR_FMT "undocumented error #%d"
49 static char xstrerror_buf
[sizeof ERRSTR_FMT
+ 20];
51 /* Like strerror, but result is never a null pointer. */
54 xstrerror (int errnum
)
58 char *(*vmslib_strerror
) (int,...);
60 /* Override any possibly-conflicting declaration from system header. */
61 vmslib_strerror
= (char *(*) (int,...)) strerror
;
62 /* Second argument matters iff first is EVMSERR, but it's simpler to
63 pass it unconditionally. `vaxc$errno' is declared in <errno.h>
64 and maintained by the run-time library in parallel to `errno'.
65 We assume that `errnum' corresponds to the last value assigned to
66 errno by the run-time library, hence vaxc$errno will be relevant. */
67 errstr
= (*vmslib_strerror
) (errnum
, vaxc$errno
);
69 errstr
= strerror (errnum
);
72 /* If `errnum' is out of range, result might be NULL. We'll fix that. */
75 sprintf (xstrerror_buf
, ERRSTR_FMT
, errnum
);
76 errstr
= xstrerror_buf
;