From fffe39059d5a04811412388ec25d8aaa32d7844f Mon Sep 17 00:00:00 2001 From: Li Zefan Date: Mon, 10 Sep 2007 14:45:37 +0800 Subject: [PATCH] rev: use warn() in errs.h The function warn() in rev.c is actually duplicate code, so here we remove it. Signed-off-by: Li Zefan Signed-off-by: Karel Zak --- text-utils/rev.c | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/text-utils/rev.c b/text-utils/rev.c index e3ac017a..3ae38cfd 100644 --- a/text-utils/rev.c +++ b/text-utils/rev.c @@ -51,12 +51,12 @@ #include #include #include -#include "nls.h" +#include +#include "nls.h" #include "widechar.h" void usage(void); -void warn(const char *, ...); int main(int argc, char *argv[]) @@ -89,7 +89,7 @@ main(int argc, char *argv[]) do { if (*argv) { if ((fp = fopen(*argv, "r")) == NULL) { - warn("%s: %s", *argv, strerror(errno)); + warn("cannot open %s", *argv ); rval = 1; ++argv; continue; @@ -109,19 +109,17 @@ main(int argc, char *argv[]) buflen *= 2; p = realloc(p, buflen*sizeof(wchar_t)); - if (p == NULL) { - fprintf(stderr,_("Unable to allocate bufferspace\n")); - exit(1); - } + if (p == NULL) + err(1, _("unable to allocate bufferspace")); /* And fill the rest of the buffer */ if (fgetws(&p[len], buflen/2, fp) == NULL) break; len = wcslen(p); - + /* That was a lot of work for nothing. Gimme perl! */ } - + t = p + len - 1 - (*(p+len-1)=='\r' || *(p+len-1)=='\n'); for ( ; t >= p; --t) if (*t != 0) @@ -130,7 +128,7 @@ main(int argc, char *argv[]) } fflush(fp); if (ferror(fp)) { - warn("%s: %s", filename, strerror(errno)); + warn("%s", filename); rval = 1; } if (fclose(fp)) @@ -139,17 +137,6 @@ main(int argc, char *argv[]) exit(rval); } -void -warn(const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - (void)fprintf(stderr, "rev: "); - (void)vfprintf(stderr, fmt, ap); - va_end(ap); - (void)fprintf(stderr, "\n"); -} - void usage(void) { -- 2.39.5