3 * error.c -- main error handling routines
5 * This code is Copyright (c) 2002, by the authors of nmh. See the
6 * COPYRIGHT file in the root directory of the nmh distribution for
7 * complete copyright information.
13 # include <sys/types.h>
21 * print out error message
24 advise (char *what, char *fmt, ...)
29 advertise (what, NULL, fmt, ap);
35 * print out error message and exit
38 adios (char *what, char *fmt, ...)
43 advertise (what, NULL, fmt, ap);
53 admonish (char *what, char *fmt, ...)
58 advertise (what, "continuing...", fmt, ap);
64 * main routine for printing error messages.
66 * Use writev() if available, for slightly better performance.
67 * Why? Well, there are a couple of reasons. Primarily, it
68 * gives a smoother output... More importantly though, it's a
72 advertise (char *what, char *tail, char *fmt, va_list ap)
77 char buffer[BUFSIZ], err[BUFSIZ];
78 struct iovec iob[20], *iov;
87 if (invo_name && *invo_name) {
88 iov->iov_len = strlen (iov->iov_base = invo_name);
90 iov->iov_len = strlen (iov->iov_base = ": ");
94 vsnprintf (buffer, sizeof(buffer), fmt, ap);
95 iov->iov_len = strlen (iov->iov_base = buffer);
99 iov->iov_len = strlen (iov->iov_base = " ");
101 iov->iov_len = strlen (iov->iov_base = what);
103 iov->iov_len = strlen (iov->iov_base = ": ");
106 if (!(iov->iov_base = strerror (eindex))) {
107 /* this shouldn't happen, but we'll test for it just in case */
108 snprintf (err, sizeof(err), "Error %d", eindex);
111 iov->iov_len = strlen (iov->iov_base);
115 iov->iov_len = strlen (iov->iov_base = ", ");
117 iov->iov_len = strlen (iov->iov_base = tail);
120 iov->iov_len = strlen (iov->iov_base = "\n");
122 writev (fileno (stderr), iob, iov - iob);
124 if (invo_name && *invo_name)
125 fprintf (stderr, "%s: ", invo_name);
126 vfprintf (stderr, fmt, ap);
132 fprintf (stderr, " %s: ", what);
133 if ((s = strerror(eindex)))
134 fprintf (stderr, "%s", s);
136 fprintf (stderr, "Error %d", eindex);
139 fprintf (stderr, ", %s", tail);
140 fputc ('\n', stderr);