summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2023-02-12 17:52:46 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2023-02-13 12:32:58 -0800
commitb0842671e750be08356425e2fc38251e7b08d5d7 (patch)
treeb20cd42a82e045a906b9a474a4a7965c92703538
parent5284af27ee5250c631ff4ee2f3d8682f0c5df8bc (diff)
downloademacs-b0842671e750be08356425e2fc38251e7b08d5d7.tar.gz
Improve insert-file-contents on non-regular files
* src/fileio.c (Finsert_file_contents): If the file is not a regular file, check REPLACE and VISIT before doing further syscalls that won’t matter in this case.
-rw-r--r--src/fileio.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/fileio.c b/src/fileio.c
index 64337abdaef..751b8ec573c 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -4022,7 +4022,6 @@ by calling `format-decode', which see. */)
if (!S_ISREG (st.st_mode))
{
regular = false;
- seekable = lseek (fd, 0, SEEK_CUR) < 0;
if (! NILP (visit))
{
@@ -4030,14 +4029,15 @@ by calling `format-decode', which see. */)
goto notfound;
}
+ if (!NILP (replace))
+ xsignal2 (Qfile_error,
+ build_string ("not a regular file"), orig_filename);
+
+ seekable = lseek (fd, 0, SEEK_CUR) < 0;
if (!NILP (beg) && !seekable)
xsignal2 (Qfile_error,
build_string ("cannot use a start position in a non-seekable file/device"),
orig_filename);
-
- if (!NILP (replace))
- xsignal2 (Qfile_error,
- build_string ("not a regular file"), orig_filename);
}
if (end_offset < 0)