Tweak comments.
[gnulib.git] / lib / fatal.c
1 /* Fatal exits for noninteractive utilities
2
3    Copyright (C) 2001, 2003 Free Software Foundation, Inc.
4
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 2, or (at your option)
8    any later version.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14
15    You should have received a copy of the GNU General Public License along
16    with this program; if not, write to the Free Software Foundation,
17    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
18
19 #ifdef HAVE_CONFIG_H
20 # include <config.h>
21 #endif
22
23 /* FIXME: define EXIT_FAILURE */
24
25 #include <stdio.h>
26
27 #if HAVE_VPRINTF || HAVE_DOPRNT || _LIBC
28 # include <stdarg.h>
29 # define VA_START(args, lastarg) va_start(args, lastarg)
30 #else
31 # define va_alist a1, a2, a3, a4, a5, a6, a7, a8
32 # define va_dcl char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8;
33 #endif
34
35 #if STDC_HEADERS || _LIBC
36 # include <stdlib.h>
37 # include <string.h>
38 #else
39 void exit ();
40 #endif
41
42 #ifdef _LIBC
43 # define program_name program_invocation_name
44 #else /* not _LIBC */
45 /* The calling program should define program_name and set it to the
46    name of the executing program.  */
47 extern char *program_name;
48 #endif
49
50 #include "fatal.h"
51 #include "unlocked-io.h"
52
53 /* Like error, but always exit with EXIT_FAILURE.  */
54
55 void
56 #if defined VA_START && __STDC__
57 fatal (int errnum, const char *message, ...)
58 #else
59 fatal (errnum, message, va_alist)
60      int errnum;
61      char *message;
62      va_dcl
63 #endif
64 {
65 #ifdef VA_START
66   va_list args;
67 #endif
68
69   if (error_print_progname)
70     (*error_print_progname) ();
71   else
72     {
73       fflush (stdout);
74       fprintf (stderr, "%s: ", program_name);
75     }
76
77 #ifdef VA_START
78   VA_START (args, message);
79   error (EXIT_FAILURE, errnum, message, args);
80   va_end (args);
81 #else
82   error (EXIT_FAILURE, errnum, message, a1, a2, a3, a4, a5, a6, a7, a8);
83 #endif
84 }