home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 5.ddi / CLIBSRC2.ZIP / STRERROR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  2.8 KB  |  93 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - strerror.c
  3.  *
  4.  * function(s)
  5.  *    strerror  - returns pointer to error message string
  6.  *    _maperror - internal function
  7.  *    _strerror - internal function
  8.  *-----------------------------------------------------------------------*/
  9.  
  10. /*
  11.  *      C/C++ Run Time Library - Version 5.0
  12.  *
  13.  *      Copyright (c) 1987, 1992 by Borland International
  14.  *      All Rights Reserved.
  15.  *
  16.  */
  17.  
  18.  
  19. #include <stdio.h>
  20. #include <errno.h>
  21. #include <stdlib.h>
  22. #include <RtlData.h>
  23.  
  24. /* The local buffer should be able to contain :     */
  25. /*  94 characters   Max User string         */
  26. /*   2      semicolon and space     */
  27. /*  64      Max sys_errlist string      */
  28. /*   2      \n and NULL terminator      */
  29.  
  30. #if !defined( _RTLDLL )
  31. static char strbuf[94 + 2 + 64 + 1];
  32. #endif
  33.  
  34. static char * near pascal _maperror(int errnum, const char *s)
  35. {
  36.     char    *cp;
  37.     _QRTLDataBlock;
  38.  
  39.     if (errnum < sys_nerr && errnum >= 0)
  40.         cp = sys_errlist[errnum];
  41.     else
  42.         cp = "Unknown error";
  43.     if (s && *s)
  44.         sprintf(_QRTLInstanceData(strbuf), "%s: %s\n", s, cp);
  45.     else
  46.         sprintf(_QRTLInstanceData(strbuf), "%s\n", cp);
  47.     return _QRTLInstanceData(strbuf);
  48. }
  49.  
  50.  
  51.  
  52. char * _FARFUNC _strerror(const char *s)
  53. {
  54.     return _maperror(errno, s);
  55. }
  56.  
  57. /*---------------------------------------------------------------------*
  58.  
  59. Name            strerror - returns pointer to error message string
  60.  
  61. Usage           char *strerror(char *str);
  62.  
  63. Prototype in    string.h
  64.  
  65. Description     strerror allows you to generate customized error
  66.                 messages; it returns a pointer to a null-terminated string
  67.                 containing an error message.
  68.  
  69.                 If str is NULL, the return value contains the most recently
  70.                 generated system error message; this string is null-terminated.
  71.  
  72.                 If str is not NULL, the return value contains str (your
  73.                 customized error message), a colon, a space, the most recently
  74.                 generated system error message, and a newline.
  75.  
  76.                 The length of str should be 94 characters or less.
  77.  
  78.                 strerror is different from perror in that it does not print
  79.                 error messages.
  80.  
  81.                 For accurate error handling, strerror should be called as soon
  82.                 as a library routine generates an error return.
  83.  
  84. Return value    strerror returns a pointer to a constructed error
  85.                 string. The error message string is constructed in a static
  86.                 buffer that is over-written with each call to perror.
  87.  
  88. *---------------------------------------------------------------------*/
  89. char * _FARFUNC strerror(int errnum)
  90. {
  91.     return  _maperror(errnum, NULL);
  92. }
  93.