diff options
author | Baptiste Daroussin <bapt@FreeBSD.org> | 2020-06-01 09:09:36 +0000 |
---|---|---|
committer | Baptiste Daroussin <bapt@FreeBSD.org> | 2020-06-01 09:09:36 +0000 |
commit | 2816b9998c649dce97c132b8365ca697040b4c41 (patch) | |
tree | 31f7afbaab01cc5c615ef7bfc62977a153957cf3 /usr.bin/diff/diff.c | |
parent | f096ed981fe534c36ed8662ef307042123e443f3 (diff) |
Notes
Diffstat (limited to 'usr.bin/diff/diff.c')
-rw-r--r-- | usr.bin/diff/diff.c | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/usr.bin/diff/diff.c b/usr.bin/diff/diff.c index 82e60c953a67..27d5bb5cb336 100644 --- a/usr.bin/diff/diff.c +++ b/usr.bin/diff/diff.c @@ -27,6 +27,7 @@ __FBSDID("$FreeBSD$"); #include <ctype.h> #include <err.h> +#include <errno.h> #include <getopt.h> #include <stdlib.h> #include <stdio.h> @@ -351,13 +352,33 @@ main(int argc, char **argv) if (strcmp(argv[0], "-") == 0) { fstat(STDIN_FILENO, &stb1); gotstdin = 1; - } else if (stat(argv[0], &stb1) != 0) - err(2, "%s", argv[0]); + } else if (stat(argv[0], &stb1) != 0) { + if (!Nflag || errno != ENOENT) + err(2, "%s", argv[0]); + dflags |= D_EMPTY1; + memset(&stb1, 0, sizeof(struct stat)); + } + if (strcmp(argv[1], "-") == 0) { fstat(STDIN_FILENO, &stb2); gotstdin = 1; - } else if (stat(argv[1], &stb2) != 0) - err(2, "%s", argv[1]); + } else if (stat(argv[1], &stb2) != 0) { + if (!Nflag || errno != ENOENT) + err(2, "%s", argv[1]); + dflags |= D_EMPTY2; + memset(&stb2, 0, sizeof(stb2)); + stb2.st_mode = stb1.st_mode; + } + + if (dflags & D_EMPTY1 && dflags & D_EMPTY2){ + warn("%s", argv[0]); + warn("%s", argv[1]); + exit(2); + } + + if (stb1.st_mode == 0) + stb1.st_mode = stb2.st_mode; + if (gotstdin && (S_ISDIR(stb1.st_mode) || S_ISDIR(stb2.st_mode))) errx(2, "can't compare - to a directory"); set_argstr(oargv, argv); |