From: Paul Eggert Date: Mon, 13 Feb 2023 01:52:46 +0000 (-0800) Subject: Improve insert-file-contents on non-regular files X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=b0842671e750be08356425e2fc38251e7b08d5d7;p=emacs.git 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. --- 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)