Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/error use warn/err.



details:   https://anonhg.NetBSD.org/src/rev/974bc34a50d0
branches:  trunk
changeset: 765188:974bc34a50d0
user:      christos <christos%NetBSD.org@localhost>
date:      Sat May 21 00:43:52 2011 +0000

description:
use warn/err.

diffstat:

 usr.bin/error/touch.c |  33 +++++++++++++--------------------
 1 files changed, 13 insertions(+), 20 deletions(-)

diffs (101 lines):

diff -r 7399c2b19aaa -r 974bc34a50d0 usr.bin/error/touch.c
--- a/usr.bin/error/touch.c     Sat May 21 00:43:42 2011 +0000
+++ b/usr.bin/error/touch.c     Sat May 21 00:43:52 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: touch.c,v 1.24 2011/05/20 02:00:45 christos Exp $      */
+/*     $NetBSD: touch.c,v 1.25 2011/05/21 00:43:52 christos Exp $      */
 
 /*
  * Copyright (c) 1980, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)touch.c    8.1 (Berkeley) 6/6/93";
 #endif
-__RCSID("$NetBSD: touch.c,v 1.24 2011/05/20 02:00:45 christos Exp $");
+__RCSID("$NetBSD: touch.c,v 1.25 2011/05/21 00:43:52 christos Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -47,6 +47,7 @@
 #include <unistd.h>
 #include <util.h>
 #include <stdarg.h>
+#include <err.h>
 #include "error.h"
 #include "pathnames.h"
 
@@ -574,8 +575,7 @@
 
        o_name = name;
        if ((o_touchedfile = fopen(name, "r")) == NULL) {
-               fprintf(stderr, "%s: Can't open file \"%s\" to touch (read).\n",
-                       processname, name);
+               warn("Can't open file `%s' to touch (read)", name);
                return true;
        }
        if ((tmpdir = getenv("TMPDIR")) == NULL)
@@ -584,10 +584,9 @@
        fd = -1;
        if ((fd = mkstemp(n_name)) == -1 ||
            (n_touchedfile = fdopen(fd, "w")) == NULL) {
+               warn("Can't open file `%s' to touch (write)", name);
                if (fd != -1)
                        close(fd);
-               fprintf(stderr,"%s: Can't open file \"%s\" to touch (write).\n",
-                       processname, name);
                return true;
        }
        tempfileopen = true;
@@ -647,9 +646,8 @@
                         * Catastrophe in temporary area: file system full?
                         */
                        botch = 1;
-                       fprintf(stderr,
-                           "%s: write failure: No errors inserted in \"%s\"\n",
-                           processname, o_name);
+                       warn("write failure: No errors inserted in `%s'",
+                           o_name);
                }
        }
        fclose(n_touchedfile);
@@ -664,14 +662,11 @@
                localfile = NULL;
                temp = NULL;
                if ((localfile = fopen(o_name, "w")) == NULL) {
-                       fprintf(stderr,
-                               "%s: Can't open file \"%s\" to overwrite.\n",
-                               processname, o_name);
+                       warn("Can't open file `%s' to overwrite", o_name);
                        botch++;
                }
                if ((temp = fopen(n_name, "r")) == NULL) {
-                       fprintf(stderr, "%s: Can't open file \"%s\" to read.\n",
-                               processname, n_name);
+                       warn("Can't open file `%s' to read", n_name);
                        botch++;
                }
                if (!botch)
@@ -681,11 +676,9 @@
                if (temp != NULL)
                        fclose(temp);
        }
-       if (oktorm == 0) {
-               fprintf(stderr, "%s: Catastrophe: A copy of \"%s\": was saved in \"%s\"\n",
-                       processname, o_name, n_name);
-               exit(1);
-       }
+       if (oktorm == 0)
+               errx(1, "Catastrophe: A copy of `%s': was saved in `%s'",
+                   o_name, n_name);
        /*
         * Kiss the temp file good bye
         */
@@ -722,7 +715,7 @@
        nwrote = fwrite(base, 1, n, preciousfile);
        if (nwrote == n)
                return (1);
-       perror(processname);
+       warn("write failed");
        switch (inquire(terse
            ? "Botch overwriting: retry? "
            : "Botch overwriting the source file: retry? ")) {



Home | Main Index | Thread Index | Old Index