uniq: fix argv check

uniq inputfile failed with "extra argument"
This commit is contained in:
Hiltjo Posthuma 2015-03-07 13:29:12 +01:00
parent 7d36a35649
commit 4092196fdc

6
uniq.c
View File

@ -52,6 +52,9 @@ main(int argc, char *argv[])
usage(); usage();
} ARGEND; } ARGEND;
if (argc > 2)
usage();
if (argc == 0) { if (argc == 0) {
uniq(stdin, stdout); uniq(stdin, stdout);
} else if (argc >= 1) { } else if (argc >= 1) {
@ -61,8 +64,7 @@ main(int argc, char *argv[])
if (strcmp(argv[1], "-") && if (strcmp(argv[1], "-") &&
!(ofp = fopen(argv[1], "w"))) !(ofp = fopen(argv[1], "w")))
eprintf("fopen %s:", argv[1]); eprintf("fopen %s:", argv[1]);
} else }
eprintf("extra argument: %s\n", argv[2]);
uniq(fp, ofp); uniq(fp, ofp);
if (fp != stdin) if (fp != stdin)
fclose(fp); fclose(fp);