diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2011-09-17 00:12:24 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-09-17 00:12:24 +0200 |
commit | 0851d125c33d65cc8a0655758f2928960077c20c (patch) | |
tree | 3279b26a562443357d72afd0036347921af123be | |
parent | 6d2d652cd33679625f5d211d739fcd34826b3a9b (diff) | |
download | busybox-w32-0851d125c33d65cc8a0655758f2928960077c20c.tar.gz busybox-w32-0851d125c33d65cc8a0655758f2928960077c20c.tar.bz2 busybox-w32-0851d125c33d65cc8a0655758f2928960077c20c.zip |
tail: fix -c +N. Closes 4111
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | coreutils/tail.c | 6 | ||||
-rwxr-xr-x | testsuite/tail.tests | 8 |
2 files changed, 11 insertions, 3 deletions
diff --git a/coreutils/tail.c b/coreutils/tail.c index 454c25936..43cecbd97 100644 --- a/coreutils/tail.c +++ b/coreutils/tail.c | |||
@@ -203,7 +203,7 @@ int tail_main(int argc, char **argv) | |||
203 | int fd = fds[i]; | 203 | int fd = fds[i]; |
204 | 204 | ||
205 | if (ENABLE_FEATURE_FANCY_TAIL && fd < 0) | 205 | if (ENABLE_FEATURE_FANCY_TAIL && fd < 0) |
206 | continue; /* may happen with -E */ | 206 | continue; /* may happen with -F */ |
207 | 207 | ||
208 | if (nfiles > header_threshhold) { | 208 | if (nfiles > header_threshhold) { |
209 | tail_xprint_header(fmt, argv[i]); | 209 | tail_xprint_header(fmt, argv[i]); |
@@ -252,14 +252,14 @@ int tail_main(int argc, char **argv) | |||
252 | * Used only by +N code ("start from Nth", 1-based): */ | 252 | * Used only by +N code ("start from Nth", 1-based): */ |
253 | seen = 1; | 253 | seen = 1; |
254 | newlines_seen = 0; | 254 | newlines_seen = 0; |
255 | while ((nread = tail_read(fd, buf, tailbufsize-taillen)) > 0) { | 255 | while ((nread = tail_read(fd, buf, tailbufsize - taillen)) > 0) { |
256 | if (G.from_top) { | 256 | if (G.from_top) { |
257 | int nwrite = nread; | 257 | int nwrite = nread; |
258 | if (seen < count) { | 258 | if (seen < count) { |
259 | /* We need to skip a few more bytes/lines */ | 259 | /* We need to skip a few more bytes/lines */ |
260 | if (COUNT_BYTES) { | 260 | if (COUNT_BYTES) { |
261 | nwrite -= (count - seen); | 261 | nwrite -= (count - seen); |
262 | seen = count; | 262 | seen += nread; |
263 | } else { | 263 | } else { |
264 | char *s = buf; | 264 | char *s = buf; |
265 | do { | 265 | do { |
diff --git a/testsuite/tail.tests b/testsuite/tail.tests index 7140da262..305a83b15 100755 --- a/testsuite/tail.tests +++ b/testsuite/tail.tests | |||
@@ -14,4 +14,12 @@ testing "tail: +N with N > file length" \ | |||
14 | "0\n" \ | 14 | "0\n" \ |
15 | "" "qw" | 15 | "" "qw" |
16 | 16 | ||
17 | testing "tail: -c +N with largish N" \ | ||
18 | " | ||
19 | dd if=/dev/zero bs=16k count=1 2>/dev/null | tail -c +8200 | wc -c; | ||
20 | dd if=/dev/zero bs=16k count=1 2>/dev/null | tail -c +8208 | wc -c; | ||
21 | " \ | ||
22 | "8185\n8177\n" \ | ||
23 | "" "" | ||
24 | |||
17 | exit $FAILCOUNT | 25 | exit $FAILCOUNT |