diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-03-23 03:28:40 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-03-23 03:28:40 +0000 |
commit | 69ca5a70fd4ae30f8a3beabec4d705f7dd32e3f3 (patch) | |
tree | 1939c21e008bb456049b186d8e3f61f41842b9e8 | |
parent | c8bac033f321d6077be35a6ce127b2587d096583 (diff) | |
download | busybox-w32-69ca5a70fd4ae30f8a3beabec4d705f7dd32e3f3.tar.gz busybox-w32-69ca5a70fd4ae30f8a3beabec4d705f7dd32e3f3.tar.bz2 busybox-w32-69ca5a70fd4ae30f8a3beabec4d705f7dd32e3f3.zip |
tail: fix fallout from tail -c optimization
-rw-r--r-- | coreutils/tail.c | 22 | ||||
-rw-r--r-- | testsuite/tail/tail-n-works | 8 | ||||
-rw-r--r-- | testsuite/tail/tail-works | 8 |
3 files changed, 17 insertions, 21 deletions
diff --git a/coreutils/tail.c b/coreutils/tail.c index 35b25a416..2f997a9f6 100644 --- a/coreutils/tail.c +++ b/coreutils/tail.c | |||
@@ -163,8 +163,6 @@ int tail_main(int argc, char **argv) | |||
163 | fmt = header_fmt + 1; /* Skip header leading newline on first output. */ | 163 | fmt = header_fmt + 1; /* Skip header leading newline on first output. */ |
164 | i = 0; | 164 | i = 0; |
165 | do { | 165 | do { |
166 | off_t current; | ||
167 | |||
168 | if (nfiles > header_threshhold) { | 166 | if (nfiles > header_threshhold) { |
169 | tail_xprint_header(fmt, argv[i]); | 167 | tail_xprint_header(fmt, argv[i]); |
170 | fmt = header_fmt; | 168 | fmt = header_fmt; |
@@ -173,19 +171,17 @@ int tail_main(int argc, char **argv) | |||
173 | /* Optimizing count-bytes case if the file is seekable. | 171 | /* Optimizing count-bytes case if the file is seekable. |
174 | * Beware of backing up too far. | 172 | * Beware of backing up too far. |
175 | * Also we exclude files with size 0 (because of /proc/xxx) */ | 173 | * Also we exclude files with size 0 (because of /proc/xxx) */ |
176 | current = lseek(fds[i], 0, SEEK_END); | 174 | if (COUNT_BYTES && !from_top) { |
177 | if (current > 0) { | 175 | off_t current = lseek(fds[i], 0, SEEK_END); |
178 | if (!from_top) { | 176 | if (current > 0) { |
179 | if (count == 0) | 177 | if (count == 0) |
180 | continue; /* showing zero lines is easy :) */ | 178 | continue; /* showing zero lines is easy :) */ |
181 | if (COUNT_BYTES) { | 179 | current -= count; |
182 | current -= count; | 180 | if (current < 0) |
183 | if (current < 0) | 181 | current = 0; |
184 | current = 0; | 182 | xlseek(fds[i], current, SEEK_SET); |
185 | xlseek(fds[i], current, SEEK_SET); | 183 | bb_copyfd_size(fds[i], STDOUT_FILENO, count); |
186 | bb_copyfd_size(fds[i], STDOUT_FILENO, count); | 184 | continue; |
187 | continue; | ||
188 | } | ||
189 | } | 185 | } |
190 | } | 186 | } |
191 | 187 | ||
diff --git a/testsuite/tail/tail-n-works b/testsuite/tail/tail-n-works index 27a905f88..e5b260caf 100644 --- a/testsuite/tail/tail-n-works +++ b/testsuite/tail/tail-n-works | |||
@@ -1,4 +1,4 @@ | |||
1 | [ -n "$d" ] || d=.. | 1 | echo -ne "abc\ndef\n123\n" >input |
2 | tail -n 2 "$d/README" > logfile.gnu | 2 | echo -ne "def\n123\n" >logfile.ok |
3 | busybox tail -n 2 "$d/README" > logfile.bb | 3 | busybox tail -n 2 input > logfile.bb |
4 | cmp logfile.gnu logfile.bb | 4 | cmp logfile.ok logfile.bb |
diff --git a/testsuite/tail/tail-works b/testsuite/tail/tail-works index 27a905f88..64e6d88ab 100644 --- a/testsuite/tail/tail-works +++ b/testsuite/tail/tail-works | |||
@@ -1,4 +1,4 @@ | |||
1 | [ -n "$d" ] || d=.. | 1 | echo -ne "abc\ndef\n123\n" >input |
2 | tail -n 2 "$d/README" > logfile.gnu | 2 | echo -ne "def\n123\n" >logfile.ok |
3 | busybox tail -n 2 "$d/README" > logfile.bb | 3 | busybox tail -2 input > logfile.bb |
4 | cmp logfile.gnu logfile.bb | 4 | cmp logfile.ok logfile.bb |