tail: fix -c +N. Closes 4111
authorDenys Vlasenko <vda.linux@googlemail.com>
Fri, 16 Sep 2011 22:12:24 +0000 (00:12 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Fri, 16 Sep 2011 22:12:24 +0000 (00:12 +0200)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
coreutils/tail.c
testsuite/tail.tests

index 454c2593625d640bbff061d1b51f8fe34a598481..43cecbd97ffd7c08dc7dd54fd137025e6b59350b 100644 (file)
@@ -203,7 +203,7 @@ int tail_main(int argc, char **argv)
                int fd = fds[i];
 
                if (ENABLE_FEATURE_FANCY_TAIL && fd < 0)
-                       continue; /* may happen with -E */
+                       continue; /* may happen with -F */
 
                if (nfiles > header_threshhold) {
                        tail_xprint_header(fmt, argv[i]);
@@ -252,14 +252,14 @@ int tail_main(int argc, char **argv)
                 * Used only by +N code ("start from Nth", 1-based): */
                seen = 1;
                newlines_seen = 0;
-               while ((nread = tail_read(fd, buf, tailbufsize-taillen)) > 0) {
+               while ((nread = tail_read(fd, buf, tailbufsize - taillen)) > 0) {
                        if (G.from_top) {
                                int nwrite = nread;
                                if (seen < count) {
                                        /* We need to skip a few more bytes/lines */
                                        if (COUNT_BYTES) {
                                                nwrite -= (count - seen);
-                                               seen = count;
+                                               seen += nread;
                                        } else {
                                                char *s = buf;
                                                do {
index 7140da262b6e2590f56bb61fe57effb2ae3f68b6..305a83b15ec243e73321f0d3e224edfb97b40f07 100755 (executable)
@@ -14,4 +14,12 @@ testing "tail: +N with N > file length" \
        "0\n" \
        "" "qw"
 
+testing "tail: -c +N with largish N" \
+       "
+       dd if=/dev/zero bs=16k count=1 2>/dev/null | tail -c +8200 | wc -c;
+       dd if=/dev/zero bs=16k count=1 2>/dev/null | tail -c +8208 | wc -c;
+       " \
+       "8185\n8177\n" \
+       "" ""
+
 exit $FAILCOUNT