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

  1. /*-------------------------------------------------------------------------*
  2.  * filename - perror.c
  3.  *
  4.  * function(s)
  5.  *        perror - system error messages
  6.  *--------------------------------------------------------------------------*/
  7.  
  8. /*
  9.  *      C/C++ Run Time Library - Version 5.0
  10.  *
  11.  *      Copyright (c) 1987, 1992 by Borland International
  12.  *      All Rights Reserved.
  13.  *
  14.  */
  15.  
  16.  
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <errno.h>
  20.  
  21. #undef sys_errlist
  22. #undef sys_nerr
  23.  
  24. char    *sys_errlist[] = {
  25. /*  0 */    "Error 0",
  26. /*  1 */    "Invalid function number",
  27. /*  2 */    "No such file or directory",
  28. /*  3 */    "Path not found",
  29. /*  4 */    "Too many open files",
  30. /*  5 */    "Permission denied",
  31. /*  6 */    "Bad file number",
  32. /*  7 */    "Memory arena trashed",
  33. /*  8 */    "Not enough memory",
  34. /*  9 */    "Invalid memory block address",
  35. /* 10 */    "Invalid environment",
  36. /* 11 */    "Invalid format",
  37. /* 12 */    "Invalid access code",
  38. /* 13 */    "Invalid data",
  39. /* 14 */    "", // "Bad address",
  40. /* 15 */    "No such device",
  41. /* 16 */    "Attempted to remove current directory",
  42. /* 17 */    "Not same device",
  43. /* 18 */    "No more files",
  44. /* 19 */    "Invalid argument",
  45. /* 20 */    "Arg list too big",
  46. /* 21 */    "Exec format error",
  47. /* 22 */    "Cross-device link",
  48. /* 23 */    "", // "Too many open files",
  49. /* 24 */    "", // "No child processes",
  50. /* 25 */    "", // "Inappropriate I/O control operation",
  51. /* 26 */    "", // "Executable file in use",
  52. /* 27 */    "", // "File too large",
  53. /* 28 */    "", // "No space left on device",
  54. /* 29 */    "", // "Illegal seek",
  55. /* 30 */    "", // "Read-only file system",
  56. /* 31 */    "", // "Too many links",
  57. /* 32 */    "", // "Broken pipe",
  58. /* 33 */    "Math argument",
  59. /* 34 */    "Result too large",
  60. /* 35 */    "File already exists",
  61. /* 36 */    "Possible deadlock",
  62. /* 37 */    "", // "Operation not permitted",
  63. /* 38 */    "", // "No such process",
  64. /* 39 */    "", // "Interrupted function call",
  65. /* 40 */    "", // "Input/output error",
  66. /* 41 */    "", // "No such device or address",
  67. /* 42 */    "", // "Resource temporarily unavailable",
  68. /* 43 */    "", // "Block device required",
  69. /* 44 */    "", // "Resource busy",
  70. /* 45 */    "", // "Not a directory",
  71. /* 46 */    "", // "Is a directory",
  72. /* 47 */    ""
  73. };
  74.  
  75. int     sys_nerr = sizeof(sys_errlist) / sizeof(sys_errlist[0]);
  76.  
  77. /*---------------------------------------------------------------------*
  78.  
  79. Name            perror - system error messages
  80.  
  81. Usage           void perror(const char *string);
  82.  
  83. Prototype in    stdio.h
  84.  
  85. Description     perror prints an error message to stderr, describing
  86.                 the most recent error encountered in a system call from the
  87.                 current program.
  88.  
  89.                 First the argument string is printed, then a colon, then the
  90.                 message corresponding to the current value of errno, and finally
  91.                 a newline. The convention is to pass the name of the program as
  92.                 the argument string.
  93.  
  94.                 To provide more control over message formatting, the array of
  95.                 message strings is provided in sys_errlist. errno can be used as
  96.                 an index into the array to find the string corresponding to the
  97.                 error number. The string does not include any newline character.
  98.  
  99.                 sys_nerr contains the number of entries in the array.
  100.  
  101.                 Refer to errno, sys_errlist, and sys_nerr in the "Variables"
  102.                 section of this chapter for more information.
  103.  
  104. Return value    None
  105.  
  106. *---------------------------------------------------------------------*/
  107. void _FARFUNC perror(const char _FAR *s)
  108. {
  109.     char    *cp;
  110.  
  111.     if (errno < sys_nerr && errno >= 0)
  112.         cp = sys_errlist[errno];
  113.     else
  114.         cp = "Unknown error";
  115.  
  116.     fprintf(stderr, "%s: %s\n", s, cp);
  117. }
  118.