summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coreutils/tail.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/coreutils/tail.c b/coreutils/tail.c
index e3f89d2..d495399 100644
--- a/coreutils/tail.c
+++ b/coreutils/tail.c
@@ -79,7 +79,19 @@ static void tail_xbb_full_write(const char *buf, size_t len)
static ssize_t tail_read(int fd, char *buf, size_t count)
{
ssize_t r;
+ off_t current,end;
+ struct stat sbuf;
+ int ret;
+ end = current = lseek (fd, 0, SEEK_CUR);
+ if (!fstat(fd, &sbuf)){
+ end = sbuf.st_size;
+ }
+ if ( end < current) {
+ lseek(fd, 0, SEEK_SET);
+ } else {
+ lseek(fd, current, SEEK_SET);
+ }
if ((r = safe_read(fd, buf, count)) < 0) {
bb_perror_msg("read");
status = EXIT_FAILURE;