3 * error.c -- main error handling routines
7 * This code is Copyright (c) 2002, by the authors of nmh. See the
8 * COPYRIGHT file in the root directory of the nmh distribution for
9 * complete copyright information.
15 # include <sys/types.h>
23 * print out error message
26 advise (char *what, char *fmt, ...)
31 advertise (what, NULL, fmt, ap);
37 * print out error message and exit
40 adios (char *what, char *fmt, ...)
45 advertise (what, NULL, fmt, ap);
55 admonish (char *what, char *fmt, ...)
60 advertise (what, "continuing...", fmt, ap);
66 * main routine for printing error messages.
68 * Use writev() if available, for slightly better performance.
69 * Why? Well, there are a couple of reasons. Primarily, it
70 * gives a smoother output... More importantly though, it's a
74 advertise (char *what, char *tail, char *fmt, va_list ap)
79 char buffer[BUFSIZ], err[BUFSIZ];
80 struct iovec iob[20], *iov;
89 if (invo_name && *invo_name) {
90 iov->iov_len = strlen (iov->iov_base = invo_name);
92 iov->iov_len = strlen (iov->iov_base = ": ");
96 vsnprintf (buffer, sizeof(buffer), fmt, ap);
97 iov->iov_len = strlen (iov->iov_base = buffer);
101 iov->iov_len = strlen (iov->iov_base = " ");
103 iov->iov_len = strlen (iov->iov_base = what);
105 iov->iov_len = strlen (iov->iov_base = ": ");
108 if (!(iov->iov_base = strerror (eindex))) {
109 /* this shouldn't happen, but we'll test for it just in case */
110 snprintf (err, sizeof(err), "Error %d", eindex);
113 iov->iov_len = strlen (iov->iov_base);
117 iov->iov_len = strlen (iov->iov_base = ", ");
119 iov->iov_len = strlen (iov->iov_base = tail);
122 iov->iov_len = strlen (iov->iov_base = "\n");
124 writev (fileno (stderr), iob, iov - iob);
126 if (invo_name && *invo_name)
127 fprintf (stderr, "%s: ", invo_name);
128 vfprintf (stderr, fmt, ap);
134 fprintf (stderr, " %s: ", what);
135 if ((s = strerror(eindex)))
136 fprintf (stderr, "%s", s);
138 fprintf (stderr, "Error %d", eindex);
141 fprintf (stderr, ", %s", tail);
142 fputc ('\n', stderr);