summaryrefslogtreecommitdiffstats
path: root/text-utils/rev.c
diff options
context:
space:
mode:
authorLi Zefan2007-09-10 08:45:37 +0200
committerKarel Zak2007-10-25 21:50:59 +0200
commitfffe39059d5a04811412388ec25d8aaa32d7844f (patch)
treee4149952482e71aa6f91cd5bdb8dabd0e307e50f /text-utils/rev.c
parentswapon: cleanup usage() (diff)
downloadkernel-qcow2-util-linux-fffe39059d5a04811412388ec25d8aaa32d7844f.tar.gz
kernel-qcow2-util-linux-fffe39059d5a04811412388ec25d8aaa32d7844f.tar.xz
kernel-qcow2-util-linux-fffe39059d5a04811412388ec25d8aaa32d7844f.zip
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 <lizf@cn.fujitsu.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'text-utils/rev.c')
-rw-r--r--text-utils/rev.c29
1 files changed, 8 insertions, 21 deletions
diff --git a/text-utils/rev.c b/text-utils/rev.c
index e3ac017a0..3ae38cfd6 100644
--- a/text-utils/rev.c
+++ b/text-utils/rev.c
@@ -51,12 +51,12 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include "nls.h"
+#include <err.h>
+#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))
@@ -140,17 +138,6 @@ main(int argc, char *argv[])
}
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)
{
(void)fprintf(stderr, _("usage: rev [file ...]\n"));