home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / binutils-2.7-src.tgz / tar.out / fsf / binutils / libiberty / xstrerror.c < prev   
C/C++ Source or Header  |  1996-09-28  |  2KB  |  57 lines

  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.  
  5. #include <stdio.h>
  6.  
  7. #include "libiberty.h"
  8. #include "config.h"
  9.  
  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 */
  17.  
  18. #ifndef DONT_DECLARE_STRERROR
  19. extern char *strerror PARAMS ((int));
  20. #endif
  21.  
  22. /* If strerror returns NULL, we'll format the number into a static buffer.  */
  23.  
  24. #define ERRSTR_FMT "undocumented error #%d"
  25. static char xstrerror_buf[sizeof ERRSTR_FMT + 20];
  26.  
  27. /* Like strerror, but result is never a null pointer.  */
  28.  
  29. char *
  30. xstrerror (errnum)
  31.      int errnum;
  32. {
  33.   char *errstr;
  34. #ifdef VMS
  35.   char *(*vmslib_strerror) PARAMS ((int,...));
  36.  
  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
  48.  
  49.   /* If `errnum' is out of range, result might be NULL.  We'll fix that.  */
  50.   if (!errstr)
  51.     {
  52.       sprintf (xstrerror_buf, ERRSTR_FMT, errnum);
  53.       errstr = xstrerror_buf;
  54.     }
  55.   return errstr;
  56. }
  57.