diff options
Diffstat (limited to 'editors/diff.c')
-rw-r--r-- | editors/diff.c | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/editors/diff.c b/editors/diff.c index f2eeb8257..975bc4603 100644 --- a/editors/diff.c +++ b/editors/diff.c | |||
@@ -295,17 +295,6 @@ static int search(const int *c, int k, int y, const struct cand *list) | |||
295 | } | 295 | } |
296 | } | 296 | } |
297 | 297 | ||
298 | static unsigned isqrt(unsigned n) | ||
299 | { | ||
300 | unsigned x = 1; | ||
301 | while (1) { | ||
302 | const unsigned y = x; | ||
303 | x = ((n / x) + x) >> 1; | ||
304 | if (x <= (y + 1) && x >= (y - 1)) | ||
305 | return x; | ||
306 | } | ||
307 | } | ||
308 | |||
309 | static void stone(const int *a, int n, const int *b, int *J, int pref) | 298 | static void stone(const int *a, int n, const int *b, int *J, int pref) |
310 | { | 299 | { |
311 | const unsigned isq = isqrt(n); | 300 | const unsigned isq = isqrt(n); |
@@ -730,9 +719,19 @@ static int diffreg(char *file[2]) | |||
730 | fp[0] = stdin; | 719 | fp[0] = stdin; |
731 | fp[1] = stdin; | 720 | fp[1] = stdin; |
732 | for (i = 0; i < 2; i++) { | 721 | for (i = 0; i < 2; i++) { |
733 | int fd = open_or_warn_stdin(file[i]); | 722 | int fd = STDIN_FILENO; |
734 | if (fd == -1) | 723 | if (!LONE_DASH(file[i])) { |
735 | goto out; | 724 | if (!(option_mask32 & FLAG(N))) { |
725 | fd = open_or_warn(file[i], O_RDONLY); | ||
726 | if (fd == -1) | ||
727 | goto out; | ||
728 | } else { | ||
729 | /* -N: if some file does not exist compare it like empty */ | ||
730 | fd = open(file[i], O_RDONLY); | ||
731 | if (fd == -1) | ||
732 | fd = xopen("/dev/null", O_RDONLY); | ||
733 | } | ||
734 | } | ||
736 | /* Our diff implementation is using seek. | 735 | /* Our diff implementation is using seek. |
737 | * When we meet non-seekable file, we must make a temp copy. | 736 | * When we meet non-seekable file, we must make a temp copy. |
738 | */ | 737 | */ |
@@ -1010,17 +1009,23 @@ int diff_main(int argc UNUSED_PARAM, char **argv) | |||
1010 | argv += optind; | 1009 | argv += optind; |
1011 | while (L_arg) | 1010 | while (L_arg) |
1012 | label[!!label[0]] = llist_pop(&L_arg); | 1011 | label[!!label[0]] = llist_pop(&L_arg); |
1012 | |||
1013 | /* Compat: "diff file name_which_doesnt_exist" exits with 2 */ | ||
1013 | xfunc_error_retval = 2; | 1014 | xfunc_error_retval = 2; |
1014 | for (i = 0; i < 2; i++) { | 1015 | for (i = 0; i < 2; i++) { |
1015 | file[i] = argv[i]; | 1016 | file[i] = argv[i]; |
1016 | /* Compat: "diff file name_which_doesnt_exist" exits with 2 */ | ||
1017 | if (LONE_DASH(file[i])) { | 1017 | if (LONE_DASH(file[i])) { |
1018 | fstat(STDIN_FILENO, &stb[i]); | 1018 | fstat(STDIN_FILENO, &stb[i]); |
1019 | gotstdin++; | 1019 | gotstdin++; |
1020 | } else | 1020 | } else if (option_mask32 & FLAG(N)) { |
1021 | if (stat(file[i], &stb[i])) | ||
1022 | xstat("/dev/null", &stb[i]); | ||
1023 | } else { | ||
1021 | xstat(file[i], &stb[i]); | 1024 | xstat(file[i], &stb[i]); |
1025 | } | ||
1022 | } | 1026 | } |
1023 | xfunc_error_retval = 1; | 1027 | xfunc_error_retval = 1; |
1028 | |||
1024 | if (gotstdin && (S_ISDIR(stb[0].st_mode) || S_ISDIR(stb[1].st_mode))) | 1029 | if (gotstdin && (S_ISDIR(stb[0].st_mode) || S_ISDIR(stb[1].st_mode))) |
1025 | bb_error_msg_and_die("can't compare stdin to a directory"); | 1030 | bb_error_msg_and_die("can't compare stdin to a directory"); |
1026 | 1031 | ||