1 /* error.c -- error handler for noninteractive utilities
2 Copyright (C) 1990, 1991, 1992 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. */
26 #define VA_START(args, lastarg) va_start(args, lastarg)
29 #define VA_START(args, lastarg) va_start(args)
30 #endif /* !__STDC__ */
32 #else /* !HAVE_VPRINTF */
36 #define va_dcl int args;
37 #else /* !HAVE_DOPRNT */
38 #define va_alist a1, a2, a3, a4, a5, a6, a7, a8
39 #define va_dcl char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8;
40 #endif /* !HAVE_DOPRNT */
42 #endif /* !HAVE_VPRINTF */
47 #else /* !STDC_HEADERS */
49 #endif /* !STDC_HEADERS */
53 private_strerror (errnum
)
56 extern char *sys_errlist
[];
59 if (errnum
> 0 && errnum
<= sys_nerr
)
60 return sys_errlist
[errnum
];
61 return "Unknown system error";
63 #define strerror private_strerror
64 #endif /* !HAVE_STRERROR */
66 /* Print the program name and error message MESSAGE, which is a printf-style
67 format string with optional args.
68 If ERRNUM is nonzero, print its corresponding system error message.
69 Exit with status STATUS if it is nonzero. */
72 #if defined (HAVE_VPRINTF) && __STDC__
73 error (int status
, int errnum
, char *message
, ...)
74 #else /* !HAVE_VPRINTF or !__STDC__ */
75 error (status
, errnum
, message
, va_alist
)
80 #endif /* !HAVE_VPRINTF or !__STDC__ */
82 extern char *program_name
;
85 #endif /* HAVE_VPRINTF */
87 fprintf (stderr
, "%s: ", program_name
);
89 VA_START (args
, message
);
90 vfprintf (stderr
, message
, args
);
92 #else /* !HAVE_VPRINTF */
94 _doprnt (message
, &args
, stderr
);
95 #else /* !HAVE_DOPRNT */
96 fprintf (stderr
, message
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
);
97 #endif /* !HAVE_DOPRNT */
98 #endif /* !HAVE_VPRINTF */
100 fprintf (stderr
, ": %s", strerror (errnum
));