Include unlocked-io.h.
[gnulib.git] / lib / fatal.c
1 #ifdef HAVE_CONFIG_H
2 # include <config.h>
3 #endif
4
5 /* FIXME: define EXIT_FAILURE */
6
7 #include <stdio.h>
8
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
21
22 #if STDC_HEADERS || _LIBC
23 # include <stdlib.h>
24 # include <string.h>
25 #else
26 void exit ();
27 #endif
28
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
36
37 #include "fatal.h"
38 #include "unlocked-io.h"
39
40 /* Like error, but always exit with EXIT_FAILURE.  */
41
42 void
43 #if defined VA_START && __STDC__
44 fatal (int errnum, const char *message, ...)
45 #else
46 fatal (errnum, message, va_alist)
47      int errnum;
48      char *message;
49      va_dcl
50 #endif
51 {
52 #ifdef VA_START
53   va_list args;
54 #endif
55
56   if (error_print_progname)
57     (*error_print_progname) ();
58   else
59     {
60       fflush (stdout);
61       fprintf (stderr, "%s: ", program_name);
62     }
63
64 #ifdef VA_START
65   VA_START (args, message);
66   error (EXIT_FAILURE, errnum, message, args);
67   va_end (args);
68 #else
69   error (EXIT_FAILURE, errnum, message, a1, a2, a3, a4, a5, a6, a7, a8);
70 #endif
71 }