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