X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/1691e80890e5d8ba258c51c214a3e91880e1db2b..09a5aa6a090a1c2b2b5d9518fbfd4b014cadc7ea:/sbr/error.c?ds=sidebyside diff --git a/sbr/error.c b/sbr/error.c index 0e02f2ab..beb4ba6d 100644 --- a/sbr/error.c +++ b/sbr/error.c @@ -2,24 +2,22 @@ /* * error.c -- main error handling routines * - * $Id$ + * This code is Copyright (c) 2002, by the authors of nmh. See the + * COPYRIGHT file in the root directory of the nmh distribution for + * complete copyright information. */ #include -#ifdef HAVE_WRITEV -# include -# include -#endif - -extern int errno; +#include +#include /* * print out error message */ void -advise (char *what, char *fmt, ...) +advise (const char *what, const char *fmt, ...) { va_list ap; @@ -33,7 +31,7 @@ advise (char *what, char *fmt, ...) * print out error message and exit */ void -adios (char *what, char *fmt, ...) +adios (const char *what, const char *fmt, ...) { va_list ap; @@ -60,25 +58,16 @@ admonish (char *what, char *fmt, ...) /* * main routine for printing error messages. - * - * Use writev() if available, for slightly better performance. - * Why? Well, there are a couple of reasons. Primarily, it - * gives a smoother output... More importantly though, it's a - * sexy syscall()... */ void -advertise (char *what, char *tail, char *fmt, va_list ap) +advertise (const char *what, char *tail, const char *fmt, va_list ap) { int eindex = errno; - -#ifdef HAVE_WRITEV char buffer[BUFSIZ], err[BUFSIZ]; struct iovec iob[20], *iov; -#endif fflush (stdout); -#ifdef HAVE_WRITEV fflush (stderr); iov = iob; @@ -96,7 +85,7 @@ advertise (char *what, char *tail, char *fmt, va_list ap) if (*what) { iov->iov_len = strlen (iov->iov_base = " "); iov++; - iov->iov_len = strlen (iov->iov_base = what); + iov->iov_len = strlen (iov->iov_base = (void*)what); iov++; iov->iov_len = strlen (iov->iov_base = ": "); iov++; @@ -117,24 +106,11 @@ advertise (char *what, char *tail, char *fmt, va_list ap) } iov->iov_len = strlen (iov->iov_base = "\n"); iov++; - writev (fileno (stderr), iob, iov - iob); -#else - if (invo_name && *invo_name) - fprintf (stderr, "%s: ", invo_name); - vfprintf (stderr, fmt, ap); - - if (what) { - char *s; - - if (*what) - fprintf (stderr, " %s: ", what); - if ((s = strerror(eindex))) - fprintf (stderr, "%s", s); - else - fprintf (stderr, "Error %d", eindex); + if (writev (fileno (stderr), iob, iov - iob) < 0) { + snprintf(buffer, sizeof buffer, "%s: write stderr failed: %d\n", + invo_name && *invo_name ? invo_name : "nmh", errno); + if (write(2, buffer, strlen(buffer)) == -1) { + /* Ignore. if-statement needed to shut up compiler. */ + } } - if (tail) - fprintf (stderr, ", %s", tail); - fputc ('\n', stderr); -#endif }