summaryrefslogtreecommitdiffstats
path: root/text-utils/pg.c
diff options
context:
space:
mode:
authorSami Kerola2012-10-08 09:08:11 +0200
committerKarel Zak2012-10-15 16:19:35 +0200
commit5ad961719df99fc17c08c3ac5428a7f8c979b468 (patch)
tree647e9910c89b499de1d3d8175247989730899acd /text-utils/pg.c
parentpg: refactor argument handing (diff)
downloadkernel-qcow2-util-linux-5ad961719df99fc17c08c3ac5428a7f8c979b468.tar.gz
kernel-qcow2-util-linux-5ad961719df99fc17c08c3ac5428a7f8c979b468.tar.xz
kernel-qcow2-util-linux-5ad961719df99fc17c08c3ac5428a7f8c979b468.zip
pg: use libc error printing facilities
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'text-utils/pg.c')
-rw-r--r--text-utils/pg.c39
1 files changed, 12 insertions, 27 deletions
diff --git a/text-utils/pg.c b/text-utils/pg.c
index 70f61dc24..b94b988aa 100644
--- a/text-utils/pg.c
+++ b/text-utils/pg.c
@@ -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,30 +930,18 @@ 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);