.
[coreutils.git] / lib / fatal.c
blobb5c8b57fa4b919acd397c12642ff705eb5d43520
1 #ifdef HAVE_CONFIG_H
2 # include <config.h>
3 #endif
5 /* FIXME: define EXIT_FAILURE */
7 #include <stdio.h>
9 #if HAVE_VPRINTF || HAVE_DOPRNT || _LIBC
10 # if __STDC__
11 # include <stdarg.h>
12 # define VA_START(args, lastarg) va_start(args, lastarg)
13 # else
14 # include <varargs.h>
15 # define VA_START(args, lastarg) va_start(args)
16 # endif
17 #else
18 # define va_alist a1, a2, a3, a4, a5, a6, a7, a8
19 # define va_dcl char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8;
20 #endif
22 #if STDC_HEADERS || _LIBC
23 # include <stdlib.h>
24 # include <string.h>
25 #else
26 void exit ();
27 #endif
29 #ifdef _LIBC
30 # define program_name program_invocation_name
31 #else /* not _LIBC */
32 /* The calling program should define program_name and set it to the
33 name of the executing program. */
34 extern char *program_name;
35 #endif
37 #include "fatal.h"
39 /* Like error, but always exit with EXIT_FAILURE. */
41 void
42 #if defined VA_START && __STDC__
43 fatal (int errnum, const char *message, ...)
44 #else
45 fatal (errnum, message, va_alist)
46 int errnum;
47 char *message;
48 va_dcl
49 #endif
51 #ifdef VA_START
52 va_list args;
53 #endif
55 if (error_print_progname)
56 (*error_print_progname) ();
57 else
59 fflush (stdout);
60 fprintf (stderr, "%s: ", program_name);
63 #ifdef VA_START
64 VA_START (args, message);
65 error (EXIT_FAILURE, errnum, message, args);
66 va_end (args);
67 #else
68 error (EXIT_FAILURE, errnum, message, a1, a2, a3, a4, a5, a6, a7, a8);
69 #endif