Make both arguments to cmp(1) mandatory and handle "-" properly
This commit is contained in:
parent
dfd0e6e77d
commit
6449db8691
20
cmp.c
20
cmp.c
|
@ -10,7 +10,7 @@ enum { Same = 0, Diff = 1, Error = 2 };
|
||||||
static void
|
static void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
enprintf(Error, "usage: %s [-ls] file1 [file2]\n", argv0);
|
enprintf(Error, "usage: %s [-ls] file1 file2\n", argv0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -34,23 +34,25 @@ main(int argc, char *argv[])
|
||||||
usage();
|
usage();
|
||||||
} ARGEND;
|
} ARGEND;
|
||||||
|
|
||||||
if (argc < 1 || argc > 2)
|
if (argc != 2)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
|
if (argv[0][0] == '-')
|
||||||
|
argv[0] = "/dev/fd/0";
|
||||||
fp[0] = fopen(argv[0], "r");
|
fp[0] = fopen(argv[0], "r");
|
||||||
if (!fp[0]) {
|
if (!fp[0]) {
|
||||||
if(!sflag)
|
if(!sflag)
|
||||||
weprintf("fopen %s:", argv[0]);
|
weprintf("fopen %s:", argv[0]);
|
||||||
exit(Error);
|
exit(Error);
|
||||||
}
|
}
|
||||||
fp[1] = stdin;
|
|
||||||
|
|
||||||
if (argc == 2) {
|
if (argv[1][0] == '-')
|
||||||
if(!(fp[1] = fopen(argv[1], "r"))) {
|
argv[1] = "/dev/fd/0";
|
||||||
if(!sflag)
|
fp[1] = fopen(argv[1], "r");
|
||||||
weprintf("fopen %s:", argv[1]);
|
if (!fp[1]) {
|
||||||
exit(Error);
|
if(!sflag)
|
||||||
}
|
weprintf("fopen %s:", argv[1]);
|
||||||
|
exit(Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(n = 1; ; n++) {
|
for(n = 1; ; n++) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user