Better fix for bug#65156

* src/fileio.c (Finsert_file_contents): Correct seek-ability
test, since lseek returns -1 upon failure.  (Bug#65156)
This commit is contained in:
Po Lu 2023-08-09 10:49:44 +08:00
parent dd1d8414b3
commit 4767f5eaee

View file

@ -4023,7 +4023,7 @@ by calling `format-decode', which see. */)
if (!S_ISREG (st.st_mode)) if (!S_ISREG (st.st_mode))
{ {
regular = false; regular = false;
seekable = lseek (fd, 0, SEEK_CUR) < 0; seekable = lseek (fd, 0, SEEK_CUR) != (off_t) -1;
if (! NILP (visit)) if (! NILP (visit))
{ {
@ -4581,7 +4581,7 @@ by calling `format-decode', which see. */)
goto handled; goto handled;
} }
if ((seekable && regular) || !NILP (end)) if (seekable || !NILP (end))
total = end_offset - beg_offset; total = end_offset - beg_offset;
else else
/* For a special file, all we can do is guess. */ /* For a special file, all we can do is guess. */
@ -4678,7 +4678,7 @@ by calling `format-decode', which see. */)
For a special file, where TOTAL is just a buffer size, For a special file, where TOTAL is just a buffer size,
so don't bother counting in HOW_MUCH. so don't bother counting in HOW_MUCH.
(INSERTED is where we count the number of characters inserted.) */ (INSERTED is where we count the number of characters inserted.) */
if ((seekable && regular) || !NILP (end)) if (seekable || !NILP (end))
how_much += this; how_much += this;
inserted += this; inserted += this;
} }