]> git.ipfire.org Git - thirdparty/gcc.git/blame - libiberty/xstrerror.c
c++: drop in-charge for dtors without vbases
[thirdparty/gcc.git] / libiberty / xstrerror.c
CommitLineData
6599da04
JM
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. */
4
aaa5f039
DD
5/*
6
7@deftypefn Replacement char* xstrerror (int @var{errnum})
8
9Behaves exactly like the standard @code{strerror} function, but
7f8fa05d 10will never return a @code{NULL} pointer.
aaa5f039
DD
11
12@end deftypefn
13
14*/
15
6599da04
JM
16#include <stdio.h>
17
6599da04 18#include "config.h"
2d59754f 19#include "libiberty.h"
6599da04
JM
20
21#ifdef VMS
d7cf8390
GDR
22# include <errno.h>
23# if !defined (__STRICT_ANSI__) && !defined (__HIDE_FORBIDDEN_NAMES)
24# ifdef __cplusplus
25extern "C" {
26# endif /* __cplusplus */
7a17ef5e 27extern char *strerror (int,...);
d7cf8390
GDR
28# define DONT_DECLARE_STRERROR
29# ifdef __cplusplus
30}
31# endif /* __cplusplus */
32# endif
33#endif /* VMS */
34
6599da04
JM
35
36#ifndef DONT_DECLARE_STRERROR
d7cf8390
GDR
37# ifdef __cplusplus
38extern "C" {
39# endif /* __cplusplus */
7a17ef5e 40extern char *strerror (int);
d7cf8390
GDR
41# ifdef __cplusplus
42}
43# endif /* __cplusplus */
6599da04
JM
44#endif
45
46/* If strerror returns NULL, we'll format the number into a static buffer. */
47
48#define ERRSTR_FMT "undocumented error #%d"
49static char xstrerror_buf[sizeof ERRSTR_FMT + 20];
50
51/* Like strerror, but result is never a null pointer. */
52
53char *
7a17ef5e 54xstrerror (int errnum)
6599da04
JM
55{
56 char *errstr;
57#ifdef VMS
7a17ef5e 58 char *(*vmslib_strerror) (int,...);
6599da04
JM
59
60 /* Override any possibly-conflicting declaration from system header. */
7a17ef5e 61 vmslib_strerror = (char *(*) (int,...)) strerror;
6599da04
JM
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);
68#else
69 errstr = strerror (errnum);
70#endif
71
72 /* If `errnum' is out of range, result might be NULL. We'll fix that. */
73 if (!errstr)
74 {
75 sprintf (xstrerror_buf, ERRSTR_FMT, errnum);
76 errstr = xstrerror_buf;
77 }
78 return errstr;
79}