1 /* error.c -- error handler for noninteractive utilities
2 Copyright (C) 1990, 91, 92, 93, 94 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 <djm@gnu.ai.mit.edu>. */
26 #if HAVE_VPRINTF || HAVE_DOPRNT
29 # define VA_START(args, lastarg) va_start(args, lastarg)
32 # define VA_START(args, lastarg) va_start(args)
35 # define va_alist a1, a2, a3, a4, a5, a6, a7, a8
36 # define va_dcl char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8;
46 /* If NULL, error will flush stdout, then print on stderr the program
47 name, a colon and a space. Otherwise, error will call this
48 function without parameters instead. */
49 void (*error_print_progname) () = NULL;
51 /* The calling program should define program_name and set it to the
52 name of the executing program. */
53 extern char *program_name;
56 # ifndef strerror /* On some systems, sterror is a macro */
61 private_strerror (errnum)
64 extern char *sys_errlist[];
67 if (errnum > 0 && errnum <= sys_nerr)
68 return sys_errlist[errnum];
69 return "Unknown system error";
71 #define strerror private_strerror
74 /* Print the program name and error message MESSAGE, which is a printf-style
75 format string with optional args.
76 If ERRNUM is nonzero, print its corresponding system error message.
77 Exit with status STATUS if it is nonzero. */
81 #if defined(VA_START) && __STDC__
82 error (int status, int errnum, const char *message, ...)
84 error (status, errnum, message, va_alist)
95 if (error_print_progname)
96 (*error_print_progname) ();
100 fprintf (stderr, "%s: ", program_name);
104 VA_START (args, message);
106 vfprintf (stderr, message, args);
108 _doprnt (message, args, stderr);
112 fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
116 fprintf (stderr, ": %s", strerror (errnum));