[hackers] [sbase] Make both arguments to cmp(1) mandatory and handle "-" properly || sin
commit 6449db8691e66ad53c276d41fb15179990d62aff
Author: sin <sin_AT_2f30.org>
Date: Thu Nov 13 15:23:28 2014 +0000
Make both arguments to cmp(1) mandatory and handle "-" properly
diff --git a/cmp.c b/cmp.c
index 8a51a66..c3f9405 100644
--- a/cmp.c
+++ b/cmp.c
_AT_@ -10,7 +10,7 @@ enum { Same = 0, Diff = 1, Error = 2 };
static void
usage(void)
{
- enprintf(Error, "usage: %s [-ls] file1 [file2]\n", argv0);
+ enprintf(Error, "usage: %s [-ls] file1 file2\n", argv0);
}
int
_AT_@ -34,23 +34,25 @@ main(int argc, char *argv[])
usage();
} ARGEND;
- if (argc < 1 || argc > 2)
+ if (argc != 2)
usage();
+ if (argv[0][0] == '-')
+ argv[0] = "/dev/fd/0";
fp[0] = fopen(argv[0], "r");
if (!fp[0]) {
if(!sflag)
weprintf("fopen %s:", argv[0]);
exit(Error);
}
- fp[1] = stdin;
- if (argc == 2) {
- if(!(fp[1] = fopen(argv[1], "r"))) {
- if(!sflag)
- weprintf("fopen %s:", argv[1]);
- exit(Error);
- }
+ if (argv[1][0] == '-')
+ argv[1] = "/dev/fd/0";
+ fp[1] = fopen(argv[1], "r");
+ if (!fp[1]) {
+ if(!sflag)
+ weprintf("fopen %s:", argv[1]);
+ exit(Error);
}
for(n = 1; ; n++) {
Received on Thu Nov 13 2014 - 17:01:16 CET
This archive was generated by hypermail 2.3.0
: Thu Nov 13 2014 - 17:12:09 CET