commit 4092196fdcdf8c39c66e5fc8a23151f70ba16662
parent 7d36a3564957826db7a7a4aad9614780905237d2
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Sat, 7 Mar 2015 13:29:12 +0100
uniq: fix argv check
uniq inputfile failed with "extra argument"
Diffstat:
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/uniq.c b/uniq.c
@@ -52,6 +52,9 @@ main(int argc, char *argv[])
usage();
} ARGEND;
+ if (argc > 2)
+ usage();
+
if (argc == 0) {
uniq(stdin, stdout);
} else if (argc >= 1) {
@@ -61,8 +64,7 @@ main(int argc, char *argv[])
if (strcmp(argv[1], "-") &&
!(ofp = fopen(argv[1], "w")))
eprintf("fopen %s:", argv[1]);
- } else
- eprintf("extra argument: %s\n", argv[2]);
+ }
uniq(fp, ofp);
if (fp != stdin)
fclose(fp);