bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#29259: tail does not seek to the end of block device


From: Pádraig Brady
Subject: bug#29259: tail does not seek to the end of block device
Date: Sun, 12 Nov 2017 22:21:14 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0

On 12/11/17 21:52, Paul Eggert wrote:
> Why doesn't lseek work for this?

Good call, it probably would.
Something like the following is more acceptable
since it adds very little complexity:

diff --git a/src/tail.c b/src/tail.c
index 1c7418d..a10470b 100644
--- a/src/tail.c
+++ b/src/tail.c
@@ -1846,9 +1846,13 @@ tail_bytes (const char *pretty_filename, int fd, uintmax_
     }
   else
     {
-      off_t end_pos = ((! presume_input_pipe && usable_st_size (&stats)
-                        && n_bytes <= OFF_T_MAX)
-                       ? stats.st_size : -1);
+      off_t end_pos = -1;
+      if (! presume_input_pipe && n_bytes <= OFF_T_MAX)
+        {
+          end_pos = usable_st_size (&stats)
+                    ? stats.st_size
+                    : lseek (fd, n_bytes, SEEK_END);
+        }
       if (end_pos <= ST_BLKSIZE (stats))
         return pipe_bytes (pretty_filename, fd, n_bytes, read_pos);
       off_t current_pos = xlseek (fd, 0, SEEK_CUR, pretty_filename);






reply via email to

[Prev in Thread] Current Thread [Next in Thread]