7a17ef5e63
include/ 2005-03-27 Gabriel Dos Reis <gdr@integreable-solutions.net> * ternary.h: Don't use PARAMS anymore. libiberty/ 2005-03-27 Gabriel Dos Reis <gdr@integrable-solutions.net> Convert libiberty to use ISO C prototype style 6/n. * strerror.c (init_error_tables, errno_max, strerror, strerrno, strtoerrno, main): Use ISO C prototype style. * strncasecmp.c (strncasecmp): Likewise. * strncmp.c (strncmp): Likewise. * strndup.c (strndup): Likewise. * strrchr.c (strrchr): Likewise. * strsignal.c (init_signal_tables, signo_max, strsignal, strsigno, strtosigno, psignal, main): Likewise. * strstr.c (strstr): Likewise. * strtod.c (strtod, atof): Likewise. * strtol.c (strtol): Likewise. * strtoul.c (strtoul): Likewise. * ternary.c (ternary_insert, ternary_cleanup, ternary_search, ternary_recursivesearch): Likewise. * tmpnam.c (tmpnam): Likewise. * unlink-if-ordinary.c (unlink_if_ordinary): Likewise. * vasprintf.c (int_vasprintf, vasprintf, checkit, main): Likewise. * vfork.c (vfork): Likewise. * vfprintf.c (vfprintf): Likewise. * vprintf.c (vprintf): Likewise. * vsnprintf.c (vsnprintf, checkit, main): Likewise. * vsprintf.c (vsprintf): Likewise. * waitpid.c (waitpid): Likewise. * xatexit.c (xatexit, xatexit_cleanup): Likewise. * xexit.c (xexit): Likewise. * xmalloc.c (xmalloc_set_program_name, xmalloc_failed, xmalloc, xcalloc, xrealloc): Likewise. * xmemdup.c (xmemdup): Likewise. * xstrdup.c (xstrdup): Likewise. * xstrerror.c (xstrerror): Likewise. * xstrndup.c (xstrndup): Likewise. From-SVN: r97122
67 lines
1.8 KiB
C
67 lines
1.8 KiB
C
/* xstrerror.c -- jacket routine for more robust strerror() usage.
|
|
Fri Jun 16 18:30:00 1995 Pat Rankin <rankin@eql.caltech.edu>
|
|
This code is in the public domain. */
|
|
|
|
/*
|
|
|
|
@deftypefn Replacement char* xstrerror (int @var{errnum})
|
|
|
|
Behaves exactly like the standard @code{strerror} function, but
|
|
will never return a @code{NULL} pointer.
|
|
|
|
@end deftypefn
|
|
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "config.h"
|
|
#include "libiberty.h"
|
|
|
|
#ifdef VMS
|
|
#include <errno.h>
|
|
#if !defined (__STRICT_ANSI__) && !defined (__HIDE_FORBIDDEN_NAMES)
|
|
extern char *strerror (int,...);
|
|
#define DONT_DECLARE_STRERROR
|
|
#endif
|
|
#endif /* VMS */
|
|
|
|
#ifndef DONT_DECLARE_STRERROR
|
|
extern char *strerror (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 (int errnum)
|
|
{
|
|
char *errstr;
|
|
#ifdef VMS
|
|
char *(*vmslib_strerror) (int,...);
|
|
|
|
/* Override any possibly-conflicting declaration from system header. */
|
|
vmslib_strerror = (char *(*) (int,...)) strerror;
|
|
/* Second argument matters iff first is EVMSERR, but it's simpler to
|
|
pass it unconditionally. `vaxc$errno' is declared in <errno.h>
|
|
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;
|
|
}
|