]> diplodocus.org Git - nmh/blobdiff - sbr/error.c
Replace `if (p) free(p)' with `mh_xfree(p)'.
[nmh] / sbr / error.c
index 0e02f2abd084cc8baacb651541b7fd2df619475a..beb4ba6d2213e77937e9ac61c116a8ccdea47987 100644 (file)
@@ -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 <h/mh.h>
 
-#ifdef HAVE_WRITEV
-# include <sys/types.h>
-# include <sys/uio.h>
-#endif
-
-extern int errno;
+#include <sys/types.h>
+#include <sys/uio.h>
 
 
 /*
  * 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
 }