]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
pg: use libc error printing facilities
authorSami Kerola <kerolasa@iki.fi>
Mon, 8 Oct 2012 07:08:11 +0000 (08:08 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 15 Oct 2012 14:19:35 +0000 (16:19 +0200)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
text-utils/pg.c

index 70f61dc24e7bd2e8b60bcb6a17705dab4edca12b..b94b988aafcb1b10ce4c2a309423adb03aeb0010 100644 (file)
@@ -119,7 +119,6 @@ void                (*oldint)(int);         /* old SIGINT handler */
 void           (*oldquit)(int);        /* old SIGQUIT handler */
 void           (*oldterm)(int);        /* old SIGTERM handler */
 char           *tty;                   /* result of ttyname(1) */
-char           *progname;              /* program name */
 unsigned       ontty;                  /* whether running on tty device */
 unsigned       exitstatus;             /* exit status */
 int            pagelen = 23;           /* lines on a single screen page */
@@ -244,15 +243,14 @@ static void usage(FILE * out)
 static void
 needarg(char *s)
 {
-       fprintf(stderr, _("%s: option requires an argument -- %s\n"),
-               progname, s);
+       warnx(_("option requires an argument -- %s"), s);
        usage(stderr);
 }
 
 static void
 invopt(char *s)
 {
-       fprintf(stderr, _("%s: illegal option -- %s\n"), progname, s);
+       warnx(_("illegal option -- %s"), s);
        usage(stderr);
 }
 
@@ -932,29 +930,17 @@ static void
 tmperr(FILE *f, char *ftype)
 {
        if (ferror(f))
-               fprintf(stderr, _("%s: Read error from %s file\n"),
-                       progname, ftype);
+               warn(_("Read error from %s file"), ftype);
        else if (feof(f))
                /*
                 * Most likely '\0' in input.
                 */
-               fprintf(stderr, _("%s: Unexpected EOF in %s file\n"),
-                       progname, ftype);
+               warnx(_("Unexpected EOF in %s file"), ftype);
        else
-               fprintf(stderr, _("%s: Unknown error in %s file\n"),
-                       progname, ftype);
+               warn(_("Unknown error in %s file"), ftype);
        quit(++exitstatus);
 }
 
-/*
- * perror()-like, but showing the program's name.
- */
-static void
-pgerror(int eno, char *string)
-{
-       fprintf(stderr, "%s: %s: %s\n", progname, string, strerror(eno));
-}
-
 /*
  * Read the file and respond to user input.
  * Beware: long and ugly.
@@ -1023,7 +1009,7 @@ pgfile(FILE *f, char *name)
                while ((sz = fread(b, sizeof *b, READBUF, f)) != 0)
                        write_all(1, b, sz);
                if (ferror(f)) {
-                       pgerror(errno, name);
+                       warn("%s", name);
                        exitstatus++;
                }
                return;
@@ -1036,7 +1022,7 @@ pgfile(FILE *f, char *name)
        }
        find = tmpfile();
        if (fbuf == NULL || find == NULL) {
-               fprintf(stderr, _("%s: Cannot create tempfile\n"), progname);
+               warn(_("Cannot create tempfile"));
                quit(++exitstatus);
        }
        if (searchfor) {
@@ -1088,12 +1074,12 @@ pgfile(FILE *f, char *name)
                                        p = fgets(b, READBUF, f);
                                        if (nobuf)
                                                if ((fpos = ftello(f)) == -1)
-                                                       pgerror(errno, name);
+                                                       warn("%s", name);
                                        canjump = 0;
                                }
                                if (p == NULL || *b == '\0') {
                                        if (ferror(f))
-                                               pgerror(errno, name);
+                                               warn("%s", name);
                                        eofline = fline;
                                        eof = 1;
                                        break;
@@ -1465,7 +1451,7 @@ found_bw:
                                 * Shell escape.
                                 */
                                if (rflag) {
-                                       mesg(progname);
+                                       mesg(program_invocation_short_name);
                                        mesg(_(": !command not allowed in "
                                               "rflag mode.\n"));
                                } else {
@@ -1494,7 +1480,7 @@ found_bw:
                                                my_sigset(SIGTERM, oldterm);
                                                execl(p, p, "-c",
                                                        cmd.cmdline + 1, NULL);
-                                               pgerror(errno, p);
+                                               warn("%s", p);
                                                _exit(0177);
                                                /*NOTREACHED*/
                                        case -1:
@@ -1641,7 +1627,7 @@ parse_arguments(int arg, int argc, char **argv)
                else {
                        input = fopen(argv[arg], "r");
                        if (input == NULL) {
-                               pgerror(errno, argv[arg]);
+                               warn("%s", argv[arg]);
                                exitstatus++;
                                continue;
                        }
@@ -1667,7 +1653,6 @@ main(int argc, char **argv)
        int arg, i;
        char *p;
 
-       progname = basename(argv[0]);
        xasprintf(&copyright,
                  _("%s %s Copyright (c) 2000-2001 Gunnar Ritter. All rights reserved.\n"),
                  program_invocation_short_name, PACKAGE_VERSION);