2 * error.c -- main error handling routines
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.
12 # include <sys/types.h>
20 * print out error message
23 advise (char *what, char *fmt, ...)
28 advertise (what, NULL, fmt, ap);
34 * print out error message and exit
37 adios (char *what, char *fmt, ...)
42 advertise (what, NULL, fmt, ap);
52 admonish (char *what, char *fmt, ...)
57 advertise (what, "continuing...", fmt, ap);
63 * main routine for printing error messages.
65 * Use writev() if available, for slightly better performance.
66 * Why? Well, there are a couple of reasons. Primarily, it
67 * gives a smoother output... More importantly though, it's a
71 advertise (char *what, char *tail, char *fmt, va_list ap)
76 char buffer[BUFSIZ], err[BUFSIZ];
77 struct iovec iob[20], *iov;
86 if (invo_name && *invo_name) {
87 iov->iov_len = strlen (iov->iov_base = invo_name);
89 iov->iov_len = strlen (iov->iov_base = ": ");
93 vsnprintf (buffer, sizeof(buffer), fmt, ap);
94 iov->iov_len = strlen (iov->iov_base = buffer);
98 iov->iov_len = strlen (iov->iov_base = " ");
100 iov->iov_len = strlen (iov->iov_base = what);
102 iov->iov_len = strlen (iov->iov_base = ": ");
105 if (!(iov->iov_base = strerror (eindex))) {
106 /* this shouldn't happen, but we'll test for it just in case */
107 snprintf (err, sizeof(err), "Error %d", eindex);
110 iov->iov_len = strlen (iov->iov_base);
114 iov->iov_len = strlen (iov->iov_base = ", ");
116 iov->iov_len = strlen (iov->iov_base = tail);
119 iov->iov_len = strlen (iov->iov_base = "\n");
121 writev (fileno (stderr), iob, iov - iob);
123 if (invo_name && *invo_name)
124 fprintf (stderr, "%s: ", invo_name);
125 vfprintf (stderr, fmt, ap);
131 fprintf (stderr, " %s: ", what);
132 if ((s = strerror(eindex)))
133 fprintf (stderr, "%s", s);
135 fprintf (stderr, "Error %d", eindex);
138 fprintf (stderr, ", %s", tail);
139 fputc ('\n', stderr);