* elfos.h (const_section): Output a tab before assembler directives.
[official-gcc.git] / libiberty / xstrerror.c
blob770b653ba8000f1668857df203f96407da3a2179
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. */
5 #include <stdio.h>
7 #include "libiberty.h"
8 #include "config.h"
10 #ifdef VMS
11 #include <errno.h>
12 #if !defined (__STRICT_ANSI__) && !defined (__HIDE_FORBIDDEN_NAMES)
13 extern char *strerror PARAMS ((int,...));
14 #define DONT_DECLARE_STRERROR
15 #endif
16 #endif /* VMS */
18 #ifndef DONT_DECLARE_STRERROR
19 extern char *strerror PARAMS ((int));
20 #endif
22 /* If strerror returns NULL, we'll format the number into a static buffer. */
24 #define ERRSTR_FMT "undocumented error #%d"
25 static char xstrerror_buf[sizeof ERRSTR_FMT + 20];
27 /* Like strerror, but result is never a null pointer. */
29 char *
30 xstrerror (errnum)
31 int errnum;
33 char *errstr;
34 #ifdef VMS
35 char *(*vmslib_strerror) PARAMS ((int,...));
37 /* Override any possibly-conflicting declaration from system header. */
38 vmslib_strerror = (char *(*) PARAMS ((int,...))) strerror;
39 /* Second argument matters iff first is EVMSERR, but it's simpler to
40 pass it unconditionally. `vaxc$errno' is declared in <errno.h>
41 and maintained by the run-time library in parallel to `errno'.
42 We assume that `errnum' corresponds to the last value assigned to
43 errno by the run-time library, hence vaxc$errno will be relevant. */
44 errstr = (*vmslib_strerror) (errnum, vaxc$errno);
45 #else
46 errstr = strerror (errnum);
47 #endif
49 /* If `errnum' is out of range, result might be NULL. We'll fix that. */
50 if (!errstr)
52 sprintf (xstrerror_buf, ERRSTR_FMT, errnum);
53 errstr = xstrerror_buf;
55 return errstr;