tail: fix fallout from tail -c optimization

This commit is contained in:
Denis Vlasenko 2008-03-23 03:28:40 +00:00
parent c8bac033f3
commit 69ca5a70fd
3 changed files with 17 additions and 21 deletions

View File

@ -163,8 +163,6 @@ int tail_main(int argc, char **argv)
fmt = header_fmt + 1; /* Skip header leading newline on first output. */
i = 0;
do {
off_t current;
if (nfiles > header_threshhold) {
tail_xprint_header(fmt, argv[i]);
fmt = header_fmt;
@ -173,12 +171,11 @@ int tail_main(int argc, char **argv)
/* Optimizing count-bytes case if the file is seekable.
* Beware of backing up too far.
* Also we exclude files with size 0 (because of /proc/xxx) */
current = lseek(fds[i], 0, SEEK_END);
if (COUNT_BYTES && !from_top) {
off_t current = lseek(fds[i], 0, SEEK_END);
if (current > 0) {
if (!from_top) {
if (count == 0)
continue; /* showing zero lines is easy :) */
if (COUNT_BYTES) {
current -= count;
if (current < 0)
current = 0;
@ -187,7 +184,6 @@ int tail_main(int argc, char **argv)
continue;
}
}
}
buf = tailbuf;
taillen = 0;

View File

@ -1,4 +1,4 @@
[ -n "$d" ] || d=..
tail -n 2 "$d/README" > logfile.gnu
busybox tail -n 2 "$d/README" > logfile.bb
cmp logfile.gnu logfile.bb
echo -ne "abc\ndef\n123\n" >input
echo -ne "def\n123\n" >logfile.ok
busybox tail -n 2 input > logfile.bb
cmp logfile.ok logfile.bb

View File

@ -1,4 +1,4 @@
[ -n "$d" ] || d=..
tail -n 2 "$d/README" > logfile.gnu
busybox tail -n 2 "$d/README" > logfile.bb
cmp logfile.gnu logfile.bb
echo -ne "abc\ndef\n123\n" >input
echo -ne "def\n123\n" >logfile.ok
busybox tail -2 input > logfile.bb
cmp logfile.ok logfile.bb