From: Sami Kerola <kerolasa@iki.fi>
To: util-linux@vger.kernel.org
Cc: kerolasa@iki.fi
Subject: [PATCH 05/14] pg: use libc error printing facilities
Date: Mon, 8 Oct 2012 08:08:11 +0100 [thread overview]
Message-ID: <1349680100-18120-6-git-send-email-kerolasa@iki.fi> (raw)
In-Reply-To: <1349680100-18120-1-git-send-email-kerolasa@iki.fi>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
text-utils/pg.c | 39 ++++++++++++---------------------------
1 file changed, 12 insertions(+), 27 deletions(-)
diff --git a/text-utils/pg.c b/text-utils/pg.c
index f9b6ac8..9f95eac 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(©right,
_("%s %s Copyright (c) 2000-2001 Gunnar Ritter. All rights reserved.\n"),
program_invocation_short_name, PACKAGE_VERSION);
--
1.7.12.2
next prev parent reply other threads:[~2012-10-08 7:08 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-08 7:08 [PATCH 00/14] various: clean ups and fixes Sami Kerola
2012-10-08 7:08 ` [PATCH 01/14] ddate: remove from util-linux Sami Kerola
2012-10-08 9:06 ` Petr Uzel
2012-10-08 7:08 ` [PATCH 02/14] column: add --output-separator option Sami Kerola
2012-10-08 7:08 ` [PATCH 03/14] docs: fix column.1 groff syntax error Sami Kerola
2012-10-08 7:08 ` [PATCH 04/14] pg: refactor argument handing Sami Kerola
2012-10-08 7:08 ` Sami Kerola [this message]
2012-10-08 7:08 ` [PATCH 06/14] pg: add const qualifiers where suitable Sami Kerola
2012-10-08 7:08 ` [PATCH 07/14] pg: add noreturn function attributes Sami Kerola
2012-10-08 7:08 ` [PATCH 08/14] pg: use unistd.h STDOUT_FILENO Sami Kerola
2012-10-08 7:08 ` [PATCH 09/14] pg: do not turn off warnigns artificially Sami Kerola
2012-10-08 7:08 ` [PATCH 10/14] pg: fix coding style Sami Kerola
2012-10-08 7:08 ` [PATCH 11/14] more: " Sami Kerola
2012-10-08 7:08 ` [PATCH 12/14] more: align void in functions with prototypes, and remove void casts Sami Kerola
2012-10-08 7:08 ` [PATCH 13/14] more: remove few memory leaks Sami Kerola
2012-10-08 7:08 ` [PATCH 14/14] swapon: remove loop declaration [smatch scan] Sami Kerola
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1349680100-18120-6-git-send-email-kerolasa@iki.fi \
--to=kerolasa@iki.fi \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).