diff: fix a bug in diffing against stdin. Closes 7784
authorDenys Vlasenko <vda.linux@googlemail.com>
Sun, 11 Jan 2015 15:41:54 +0000 (16:41 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Sun, 11 Jan 2015 15:41:54 +0000 (16:41 +0100)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
editors/diff.c
testsuite/diff.tests

index a78a0ee283732b359d4e001c09c519e9f264d909..c3ad31bf30cc8fd7b85a542ab6f8cb127638ba1b 100644 (file)
@@ -740,9 +740,10 @@ static int diffreg(char *file[2])
                        unlink(name);
                        if (bb_copyfd_eof(fd, fd_tmp) < 0)
                                xfunc_die();
-                       if (fd) /* Prevents closing of stdin */
+                       if (fd != STDIN_FILENO)
                                close(fd);
                        fd = fd_tmp;
+                       xlseek(fd, 0, SEEK_SET);
                }
                fp[i] = fdopen(fd, "r");
        }
index 6de46483bb809d33aebc08031c46a96d10e14fa0..84d853852002541881ae4f8bc0006a06550d975e 100755 (executable)
@@ -44,6 +44,17 @@ testing "diff of stdin, twice" \
        "" \
        "stdin"
 
+testing "diff of empty file against stdin" \
+       "diff -u - input | $TRIM_TAB" \
+"\
+--- -
++++ input
+@@ -1 +0,0 @@
+-a
+" \
+       "" \
+       "a\n"
+
 testing "diff of empty file against nonempty one" \
        "diff -u - input | $TRIM_TAB" \
 "\