]> git.eshelyaron.com Git - emacs.git/commit
insert-file-contents 1 KiB seek fix
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 19 Jul 2025 00:29:25 +0000 (17:29 -0700)
committerEshel Yaron <me@eshelyaron.com>
Fri, 25 Jul 2025 08:11:36 +0000 (10:11 +0200)
commitf4373bb03455261fad90ecb0fd5a9a658055f02d
treeab88aa9e2625f883e42de3961b2acbde8106bf31
parent2b8e0bc7dd6a5c2943549239272dc10e3217e6a0
insert-file-contents 1 KiB seek fix

This improves on recent fixes to Bug#77315.
When sampling the first 1 KiB and last 3 KiB, do not seek before
BEG if given.  Instead, sample starting at BEG, to be consistent
with the non-optimized version.
* src/fileio.c (xlseek): Return POS, for convenience.
(Finsert_file_contents): Sample the first 1 KiB correctly when BEG.
In a CURPOS local, keep track of the input file offset, or for
nonseekable files the number of bytes read, while this value is
important.  This lets us avoid some unnecessary seeks.  Report an
error earlier if the file is not seekable and BEG is nonzero,
to save work and simplify the code.  When sampling, discard less
data, as this is simpler and there’s little point to discarding it.

(cherry picked from commit 2903b0b92cfdf87fbbb764c4f202479e9a1ac941)
src/fileio.c