Don’t scan text twice to guess coding system
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 13 Feb 2023 16:51:45 +0000 (08:51 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 13 Feb 2023 20:32:59 +0000 (12:32 -0800)
* src/fileio.c (Finsert_file_contents): If the file shrank
below 4 KiB, don’t read duplicate text into READ_BUF.
This also removes a use of SEEK_END, which Linux /proc
file systems do not support (not that we should get here
with /proc).

src/fileio.c

index 751b8ec573c6663ece8f016f4fe9e9893634e322..47177be0f4d3f2b7262960b65ae6271f8548278a 100644 (file)
@@ -4119,7 +4119,7 @@ by calling `format-decode', which see.  */)
                  if (nread == 1024)
                    {
                      int ntail;
-                     if (lseek (fd, - (1024 * 3), SEEK_END) < 0)
+                     if (lseek (fd, st.st_size - 1024 * 3, SEEK_CUR) < 0)
                        report_file_error ("Setting file position",
                                           orig_filename);
                      ntail = emacs_read_quit (fd, read_buf + nread, 1024 * 3);