From 28e9041cc224267271fbcd8db22bea115912365b Mon Sep 17 00:00:00 2001 From: jason Date: Thu, 21 Aug 1997 22:57:35 +0000 Subject: Initial revision git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@14877 138bc75d-0d04-0410-961f-82ee72b054a4 --- libiberty/xstrerror.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 libiberty/xstrerror.c (limited to 'libiberty/xstrerror.c') diff --git a/libiberty/xstrerror.c b/libiberty/xstrerror.c new file mode 100644 index 00000000000..770b653ba80 --- /dev/null +++ b/libiberty/xstrerror.c @@ -0,0 +1,56 @@ +/* xstrerror.c -- jacket routine for more robust strerror() usage. + Fri Jun 16 18:30:00 1995 Pat Rankin + This code is in the public domain. */ + +#include + +#include "libiberty.h" +#include "config.h" + +#ifdef VMS +#include +#if !defined (__STRICT_ANSI__) && !defined (__HIDE_FORBIDDEN_NAMES) +extern char *strerror PARAMS ((int,...)); +#define DONT_DECLARE_STRERROR +#endif +#endif /* VMS */ + +#ifndef DONT_DECLARE_STRERROR +extern char *strerror PARAMS ((int)); +#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 (errnum) + int errnum; +{ + char *errstr; +#ifdef VMS + char *(*vmslib_strerror) PARAMS ((int,...)); + + /* Override any possibly-conflicting declaration from system header. */ + vmslib_strerror = (char *(*) PARAMS ((int,...))) strerror; + /* Second argument matters iff first is EVMSERR, but it's simpler to + pass it unconditionally. `vaxc$errno' is declared in + 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; +} -- cgit v1.2.1