]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tail: optimize tail -n +2**63
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 29 Jul 2025 16:37:44 +0000 (09:37 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 4 Aug 2025 02:48:05 +0000 (19:48 -0700)
* src/tail.c (tail_lines): Also optimize ‘tail -n +N’
on a seekable file, where OFF_T_MAX <= N < UINTMAX_MAX.
Of course this is very unlikely.

src/tail.c

index 4715bd1d8567d17b879628d43d98bc1ad794fe24..db6aea4a041850585897dc879b980747ad72c4a9 100644 (file)
@@ -1955,7 +1955,7 @@ tail_lines (char const *pretty_filename, int fd, struct stat const *st,
     {
       /* If skipping all input use lseek if possible, for speed.  */
       off_t pos;
-      if (n_lines == UINTMAX_MAX && 0 <= (pos = lseek (fd, 0, SEEK_END)))
+      if (OFF_T_MAX <= n_lines && 0 <= (pos = lseek (fd, 0, SEEK_END)))
         *read_pos = pos;
       else
         {