1 /* error.c -- error handler for noninteractive utilities
2 Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
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)
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.
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. */
18 /* Written by David MacKenzie. */
21 #if defined (CONFIG_BROKETS)
22 /* We use <config.h> instead of "config.h" so that a compilation
23 using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
24 (which it would do because it found this file in $srcdir). */
37 #define VA_START(args, lastarg) va_start(args, lastarg)
40 #define VA_START(args, lastarg) va_start(args)
41 #endif /* !__STDC__ */
43 #else /* !HAVE_VPRINTF */
47 #define va_dcl int args;
48 #else /* !HAVE_DOPRNT */
49 #define va_alist a1, a2, a3, a4, a5, a6, a7, a8
50 #define va_dcl char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8;
51 #endif /* !HAVE_DOPRNT */
53 #endif /* !HAVE_VPRINTF */
58 #else /* !STDC_HEADERS */
60 #endif /* !STDC_HEADERS */
62 extern char *program_name;
66 private_strerror (errnum)
69 extern char *sys_errlist[];
72 if (errnum > 0 && errnum <= sys_nerr)
73 return sys_errlist[errnum];
74 return "Unknown system error";
76 #define strerror private_strerror
77 #endif /* !HAVE_STRERROR */
79 /* Print the program name and error message MESSAGE, which is a printf-style
80 format string with optional args.
81 If ERRNUM is nonzero, print its corresponding system error message.
82 Exit with status STATUS if it is nonzero. */
85 #if defined (HAVE_VPRINTF) && __STDC__
86 error (int status, int errnum, char *message, ...)
87 #else /* !HAVE_VPRINTF or !__STDC__ */
88 error (status, errnum, message, va_alist)
93 #endif /* !HAVE_VPRINTF or !__STDC__ */
97 #endif /* HAVE_VPRINTF */
99 fprintf (stderr, "%s: ", program_name);
101 VA_START (args, message);
102 vfprintf (stderr, message, args);
104 #else /* !HAVE_VPRINTF */
106 _doprnt (message, &args, stderr);
107 #else /* !HAVE_DOPRNT */
108 fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
109 #endif /* !HAVE_DOPRNT */
110 #endif /* !HAVE_VPRINTF */
112 fprintf (stderr, ": %s", strerror (errnum));