Fix missing va_end call in uip/mhmisc.c
[mmh] / sbr / error.c
1 /*
2 ** error.c -- main error handling routines
3 **
4 ** This code is Copyright (c) 2002, by the authors of nmh.  See the
5 ** COPYRIGHT file in the root directory of the nmh distribution for
6 ** complete copyright information.
7 */
8
9 #include <h/mh.h>
10 #include <errno.h>
11 #include <stdarg.h>
12
13
14 /*
15 ** print out error message
16 */
17 void
18 advise(char *what, char *fmt, ...)
19 {
20         va_list ap;
21
22         va_start(ap, fmt);
23         advertise(what, NULL, fmt, ap);
24         va_end(ap);
25 }
26
27
28 /*
29 ** print out error message and exit
30 */
31 void
32 adios(int status, char *what, char *fmt, ...)
33 {
34         va_list ap;
35
36         va_start(ap, fmt);
37         advertise(what, NULL, fmt, ap);
38         va_end(ap);
39         exit(status);
40 }
41
42
43 /*
44 ** admonish the user
45 */
46 void
47 admonish(char *what, char *fmt, ...)
48 {
49         va_list ap;
50
51         va_start(ap, fmt);
52         advertise(what, "continuing...", fmt, ap);
53         va_end(ap);
54 }
55
56
57 /*
58 ** main routine for printing error messages.
59 **
60 ** Until 2011-11-01, this routine used writev(). In order to remove
61 ** ``sexy'' syscalls, in favor for mainstream programming, I removed
62 ** it. But I want to preserve the following comment:
63 **
64 **     Use writev() if available, for slightly better performance.
65 **     Why?  Well, there are a couple of reasons.  Primarily, it
66 **     gives a smoother output...  More importantly though, it's a
67 **     sexy syscall()...
68 **
69 ** advertise() does *not* use writev() anymore, and that's good so.
70 ** -- meillo@marmaro.de
71 */
72 void
73 advertise(char *what, char *tail, char *fmt, va_list ap)
74 {
75         int  eindex = errno;
76
77         fflush(stdout);
78         if (invo_name && *invo_name)
79                 fprintf(stderr, "%s: ", invo_name);
80         vfprintf(stderr, fmt, ap);
81
82         if (what) {
83                 char *s;
84
85                 if (*what)
86                         fprintf(stderr, " %s: ", what);
87                 if ((s = strerror(eindex)))
88                         fprintf(stderr, "%s", s);
89                 else
90                         fprintf(stderr, "Error %d", eindex);
91         }
92         if (tail)
93                 fprintf(stderr, ", %s", tail);
94         fputc('\n', stderr);
95 }