Handle stdin properly in cmp(1) and remove path comparison
Same paths are undefined behaviour, let's not endorse it.
This commit is contained in:
parent
d756dca999
commit
cb1b5d532b
25
cmp.c
25
cmp.c
|
@ -35,17 +35,17 @@ main(int argc, char *argv[])
|
||||||
if (argc != 2 || (lflag && sflag))
|
if (argc != 2 || (lflag && sflag))
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
if (!strcmp(argv[0], argv[1]))
|
|
||||||
return Same;
|
|
||||||
|
|
||||||
for (n = 0; n < 2; n++) {
|
for (n = 0; n < 2; n++) {
|
||||||
if (argv[n][0] == '-' && !argv[n][1])
|
if (argv[n][0] == '-' && !argv[n][1]) {
|
||||||
argv[n] = "/dev/fd/0";
|
argv[n] = "<stdin>";
|
||||||
fp[n] = fopen(argv[n], "r");
|
fp[n] = stdin;
|
||||||
if (!fp[n]) {
|
} else {
|
||||||
if (!sflag)
|
fp[n] = fopen(argv[n], "r");
|
||||||
weprintf("fopen %s:", argv[n]);
|
if (!fp[n]) {
|
||||||
exit(Error);
|
if (!sflag)
|
||||||
|
weprintf("fopen %s:", argv[n]);
|
||||||
|
exit(Error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,5 +76,10 @@ main(int argc, char *argv[])
|
||||||
same = 0;
|
same = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (n = 1; n < 2; n++)
|
||||||
|
if (fp[n] != stdin)
|
||||||
|
fclose(fp[n]);
|
||||||
|
|
||||||
return same ? Same : Diff;
|
return same ? Same : Diff;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user