From b0842671e750be08356425e2fc38251e7b08d5d7 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 12 Feb 2023 17:52:46 -0800 Subject: [PATCH 2/5] Improve insert-file-contents on non-regular files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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. --- src/fileio.c | 10 +++++----- 1 file 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 @@ because (1) it preserves some marker positions (in unchanged portions if (!S_ISREG (st.st_mode)) { regular = false; - seekable = lseek (fd, 0, SEEK_CUR) < 0; if (! NILP (visit)) { @@ -4030,14 +4029,15 @@ because (1) it preserves some marker positions (in unchanged portions 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) -- 2.37.2