]>
diplodocus.org Git - nmh/blob - sbr/error.c
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>
19 * print out error message
22 advise (char *what
, char *fmt
, ...)
27 advertise (what
, NULL
, fmt
, ap
);
33 * print out error message and exit
36 adios (char *what
, char *fmt
, ...)
41 advertise (what
, NULL
, fmt
, ap
);
51 admonish (char *what
, char *fmt
, ...)
56 advertise (what
, "continuing...", fmt
, ap
);
62 * main routine for printing error messages.
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
70 advertise (char *what
, char *tail
, char *fmt
, va_list ap
)
75 char buffer
[BUFSIZ
], err
[BUFSIZ
];
76 struct iovec iob
[20], *iov
;
85 if (invo_name
&& *invo_name
) {
86 iov
->iov_len
= strlen (iov
->iov_base
= invo_name
);
88 iov
->iov_len
= strlen (iov
->iov_base
= ": ");
92 vsnprintf (buffer
, sizeof(buffer
), fmt
, ap
);
93 iov
->iov_len
= strlen (iov
->iov_base
= buffer
);
97 iov
->iov_len
= strlen (iov
->iov_base
= " ");
99 iov
->iov_len
= strlen (iov
->iov_base
= what
);
101 iov
->iov_len
= strlen (iov
->iov_base
= ": ");
104 if (!(iov
->iov_base
= strerror (eindex
))) {
105 /* this shouldn't happen, but we'll test for it just in case */
106 snprintf (err
, sizeof(err
), "Error %d", eindex
);
109 iov
->iov_len
= strlen (iov
->iov_base
);
113 iov
->iov_len
= strlen (iov
->iov_base
= ", ");
115 iov
->iov_len
= strlen (iov
->iov_base
= tail
);
118 iov
->iov_len
= strlen (iov
->iov_base
= "\n");
120 writev (fileno (stderr
), iob
, iov
- iob
);
122 if (invo_name
&& *invo_name
)
123 fprintf (stderr
, "%s: ", invo_name
);
124 vfprintf (stderr
, fmt
, ap
);
130 fprintf (stderr
, " %s: ", what
);
131 if ((s
= strerror(eindex
)))
132 fprintf (stderr
, "%s", s
);
134 fprintf (stderr
, "Error %d", eindex
);
137 fprintf (stderr
, ", %s", tail
);
138 fputc ('\n', stderr
);