From 5e398b10aa96e1ade714b535eafcbeba054abea0 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 12 Jul 2025 18:14:26 -0700 Subject: [PATCH] insert-file-contents errno confusion * src/fileio.c (read_non_regular): Return negation of errno on failure, instead of -1. (Finsert_file_contents): Signal with correct errno when a read fails. (cherry picked from commit 490311f86a97fd8d6633e28143a26e7618f15e79) --- src/fileio.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/fileio.c b/src/fileio.c index 748e8aadc0c..7aa2113454b 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -3924,7 +3924,7 @@ read_non_regular (Lisp_Object state) ((char *) BEG_ADDR + PT_BYTE - BEG_BYTE + data->s.inserted), data->s.trytry); - return make_int (nbytes); + return make_int (nbytes < 0 ? -errno : nbytes); } @@ -4094,8 +4094,8 @@ by calling `format-decode', which see. */) bool replace_handled = false; bool set_coding_system = false; Lisp_Object coding_system; - /* Negative if read error, 0 if OK so far, positive if quit. */ - ptrdiff_t read_quit = 0; + /* errno if read error, 0 if OK so far, negative if quit. */ + int read_quit = 0; /* If the undo log only contains the insertion, there's no point keeping it. It's typically when we first fill a file-buffer. */ bool empty_undo_list_p @@ -4843,7 +4843,7 @@ by calling `format-decode', which see. */) if (NILP (nbytes)) { - read_quit = 1; + read_quit = -1; break; } @@ -4857,14 +4857,18 @@ by calling `format-decode', which see. */) /* Allow quitting out of the actual I/O. We don't make text part of the buffer until all the reading is done, so a C-g here doesn't do any harm. */ - this = emacs_fd_read (fd, - ((char *) BEG_ADDR + PT_BYTE - BEG_BYTE - + inserted), - trytry); + { + this = emacs_fd_read (fd, + ((char *) BEG_ADDR + PT_BYTE - BEG_BYTE + + inserted), + trytry); + if (this < 0) + this = -errno; + } if (this <= 0) { - read_quit = this; + read_quit = -this; break; } @@ -4889,8 +4893,8 @@ by calling `format-decode', which see. */) emacs_fd_close (fd); clear_unwind_protect (fd_index); - if (read_quit < 0) - report_file_error ("Read error", orig_filename); + if (0 < read_quit) + report_file_errno ("Read error", orig_filename, read_quit); notfound: -- 2.39.5