home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / f / ftp-102.zip / ftape-1.02 / qic / error.c < prev    next >
C/C++ Source or Header  |  1992-10-12  |  3KB  |  119 lines

  1. /* error.c -- error handler for noninteractive utilities
  2.    Copyright (C) 1990-1991 Free Software Foundation, Inc.
  3.  
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 2, or (at your option)
  7.    any later version.
  8.  
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. /* David MacKenzie */
  19.  
  20. /*
  21.  * error.c,v 1.3 1992/10/12 05:14:26 dbrown Exp
  22.  *
  23.  * error.c,v
  24.  * Revision 1.3  1992/10/12  05:14:26  dbrown
  25.  * Make errors cause a core dump instead of exiting.
  26.  *
  27.  * Revision 1.2  1992/03/21  13:07:19  dbrown
  28.  * Added call to close_down to cleanly close the tape device.
  29.  *
  30.  */
  31.  
  32. #include <stdio.h>
  33.  
  34. #ifndef VPRINTF_MISSING
  35.  
  36. #ifdef __STDC__
  37. #include <stdarg.h>
  38. #define VA_START(args, lastarg) va_start(args, lastarg)
  39. #else
  40. #include <varargs.h>
  41. #define VA_START(args, lastarg) va_start(args)
  42. #endif
  43.  
  44. #else
  45.  
  46. #ifndef DOPRNT_MISSING
  47. #define va_alist args
  48. #define va_dcl int args;
  49. #else
  50. #define va_alist a1, a2, a3, a4, a5, a6, a7, a8
  51. #define va_dcl char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8;
  52. #endif
  53.  
  54. #endif
  55.  
  56. #ifdef STDC_HEADERS
  57. #include <stdlib.h>
  58. #include <string.h>
  59. #else
  60. void exit ();
  61.  
  62. static char *
  63. strerror (errnum)
  64.      int errnum;
  65. {
  66.   extern char *sys_errlist[];
  67.   extern int sys_nerr;
  68.  
  69.   if (errnum > 0 && errnum < sys_nerr)
  70.     return sys_errlist[errnum];
  71.   return "Unknown system error";
  72. }
  73. #endif
  74.  
  75. /* Print the program name and error message MESSAGE, which is a printf-style
  76.    format string with optional args.
  77.    If ERRNUM is nonzero, print its corresponding system error message.
  78.    Exit with status STATUS if it is nonzero. */
  79. /* VARARGS */
  80. void
  81. #if !defined (VPRINTF_MISSING) && defined (__STDC__)
  82. error (int status, int errnum, char *message, ...)
  83. #else
  84. error (status, errnum, message, va_alist)
  85.      int status;
  86.      int errnum;
  87.      char *message;
  88.      va_dcl
  89. #endif
  90. {
  91.   extern char *program_name;
  92. #ifndef VPRINTF_MISSING
  93.   va_list args;
  94. #endif
  95.  
  96.   fprintf (stderr, "%s: ", program_name);
  97. #ifndef VPRINTF_MISSING
  98.   VA_START (args, message);
  99.   vfprintf (stderr, message, args);
  100.   va_end (args);
  101. #else
  102. #ifndef DOPRNT_MISSING
  103.   _doprnt (message, &args, stderr);
  104. #else
  105.   fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
  106. #endif
  107. #endif
  108.   if (errnum)
  109.     fprintf (stderr, ": %s", strerror (errnum));
  110.   putc ('\n', stderr);
  111.   fflush (stderr);
  112.   if (status)
  113.     {
  114.       close_down ();        /* Shut down the tape drive. */
  115.       abort ();
  116.       exit (status);
  117.     }
  118. }
  119.