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);