]> git.eshelyaron.com Git - emacs.git/commit
Improve insert-file-contents on non-regular files
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 11 Jul 2025 23:32:31 +0000 (16:32 -0700)
committerEshel Yaron <me@eshelyaron.com>
Thu, 24 Jul 2025 08:47:28 +0000 (10:47 +0200)
commitc08a568715323a676f0f3557aff88cd3cc053b37
tree3982f2826c1e6dd653c4aa6f1e1cc1fa7f7c8522
parentdce99f6a9861a71bc8bc300195651be64c540485
Improve insert-file-contents on non-regular files

This is part of a fix for Bug#77315,
and improves on the fix for Bug#71258.
* src/fileio.c (Finsert_file_contents): Do not pretend that
directories are regular files.  Instead, signal an error when
attempting to read from them in the usual case where the OS
prohibits that; and otherwise read from them.  However, when
visiting a directory report an error right away rather than
waiting until later, as this function is documented to not allow
visiting non-regular files.  Nest the struct stat into a small
code block, to keep the code simpler and so that the compiler can
see what parts are used and can issue better diagnostics if
uninitialized storage is accessed.  Be more skeptical of st_size,
when the file is not regular.

(cherry picked from commit 6d09a339ceb986de6d2a49ac8c20a7360f57b7d6)
src/fileio.c