home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 1.ddi / CLIB1.ZIP / PERROR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-07  |  3.1 KB  |  104 lines

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