home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / libg++-2.7.1-base.tgz / libg++-2.7.1-src.tar / fsf / libg++ / libiberty / xstrerror.c < prev   
C/C++ Source or Header  |  1995-08-22  |  2KB  |  55 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 "libiberty.h"
  6. #include "config.h"
  7.  
  8. #ifdef VMS
  9. #include <errno.h>
  10. #if !defined (__STRICT_ANSI__) && !defined (__HIDE_FORBIDDEN_NAMES)
  11. extern char *strerror PARAMS ((int,...));
  12. #define DONT_DECLARE_STRERROR
  13. #endif
  14. #endif    /* VMS */
  15.  
  16. #ifndef DONT_DECLARE_STRERROR
  17. extern char *strerror PARAMS ((int));
  18. #endif
  19.  
  20. /* If strerror returns NULL, we'll format the number into a static buffer.  */
  21.  
  22. #define ERRSTR_FMT "undocumented error #%d"
  23. static char xstrerror_buf[sizeof ERRSTR_FMT + 20];
  24.  
  25. /* Like strerror, but result is never a null pointer.  */
  26.  
  27. char *
  28. xstrerror (errnum)
  29.      int errnum;
  30. {
  31.   char *errstr;
  32. #ifdef VMS
  33.   char *(*vmslib_strerror) PARAMS ((int,...));
  34.  
  35.   /* Override any possibly-conflicting declaration from system header.  */
  36.   vmslib_strerror = (char *(*) PARAMS ((int,...))) strerror;
  37.   /* Second argument matters iff first is EVMSERR, but it's simpler to
  38.      pass it unconditionally.  `vaxc$errno' is declared in <errno.h>
  39.      and maintained by the run-time library in parallel to `errno'.
  40.      We assume that `errnum' corresponds to the last value assigned to
  41.      errno by the run-time library, hence vaxc$errno will be relevant.  */
  42.   errstr = (*vmslib_strerror) (errnum, vaxc$errno);
  43. #else
  44.   errstr = strerror (errnum);
  45. #endif
  46.  
  47.   /* If `errnum' is out of range, result might be NULL.  We'll fix that.  */
  48.   if (!errstr)
  49.     {
  50.       sprintf (xstrerror_buf, ERRSTR_FMT, errnum);
  51.       errstr = xstrerror_buf;
  52.     }
  53.   return errstr;
  54. }
  55.