aboutsummaryrefslogtreecommitdiffstats
path: root/src/fileio.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fileio.c')
-rw-r--r--src/fileio.c94
1 files changed, 38 insertions, 56 deletions
diff --git a/src/fileio.c b/src/fileio.c
index 8c8cba9e49c..38400623793 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -316,7 +316,7 @@ use the standard functions without calling themselves recursively. */)
316 } 316 }
317 } 317 }
318 318
319 QUIT; 319 maybe_quit ();
320 } 320 }
321 return result; 321 return result;
322} 322}
@@ -1960,9 +1960,7 @@ permissions. */)
1960 report_file_error ("Copying permissions to", newname); 1960 report_file_error ("Copying permissions to", newname);
1961 } 1961 }
1962#else /* not WINDOWSNT */ 1962#else /* not WINDOWSNT */
1963 immediate_quit = 1;
1964 ifd = emacs_open (SSDATA (encoded_file), O_RDONLY, 0); 1963 ifd = emacs_open (SSDATA (encoded_file), O_RDONLY, 0);
1965 immediate_quit = 0;
1966 1964
1967 if (ifd < 0) 1965 if (ifd < 0)
1968 report_file_error ("Opening input file", file); 1966 report_file_error ("Opening input file", file);
@@ -2024,8 +2022,7 @@ permissions. */)
2024 oldsize = out_st.st_size; 2022 oldsize = out_st.st_size;
2025 } 2023 }
2026 2024
2027 immediate_quit = 1; 2025 maybe_quit ();
2028 QUIT;
2029 2026
2030 if (clone_file (ofd, ifd)) 2027 if (clone_file (ofd, ifd))
2031 newsize = st.st_size; 2028 newsize = st.st_size;
@@ -2033,9 +2030,9 @@ permissions. */)
2033 { 2030 {
2034 char buf[MAX_ALLOCA]; 2031 char buf[MAX_ALLOCA];
2035 ptrdiff_t n; 2032 ptrdiff_t n;
2036 for (newsize = 0; 0 < (n = emacs_read (ifd, buf, sizeof buf)); 2033 for (newsize = 0; 0 < (n = emacs_read_quit (ifd, buf, sizeof buf));
2037 newsize += n) 2034 newsize += n)
2038 if (emacs_write_sig (ofd, buf, n) != n) 2035 if (emacs_write_quit (ofd, buf, n) != n)
2039 report_file_error ("Write error", newname); 2036 report_file_error ("Write error", newname);
2040 if (n < 0) 2037 if (n < 0)
2041 report_file_error ("Read error", file); 2038 report_file_error ("Read error", file);
@@ -2047,8 +2044,6 @@ permissions. */)
2047 if (newsize < oldsize && ftruncate (ofd, newsize) != 0) 2044 if (newsize < oldsize && ftruncate (ofd, newsize) != 0)
2048 report_file_error ("Truncating output file", newname); 2045 report_file_error ("Truncating output file", newname);
2049 2046
2050 immediate_quit = 0;
2051
2052#ifndef MSDOS 2047#ifndef MSDOS
2053 /* Preserve the original file permissions, and if requested, also its 2048 /* Preserve the original file permissions, and if requested, also its
2054 owner and group. */ 2049 owner and group. */
@@ -2682,7 +2677,7 @@ DEFUN ("file-writable-p", Ffile_writable_p, Sfile_writable_p, 1, 1, 0,
2682 2677
2683DEFUN ("access-file", Faccess_file, Saccess_file, 2, 2, 0, 2678DEFUN ("access-file", Faccess_file, Saccess_file, 2, 2, 0,
2684 doc: /* Access file FILENAME, and get an error if that does not work. 2679 doc: /* Access file FILENAME, and get an error if that does not work.
2685The second argument STRING is used in the error message. 2680The second argument STRING is prepended to the error message.
2686If there is no error, returns nil. */) 2681If there is no error, returns nil. */)
2687 (Lisp_Object filename, Lisp_Object string) 2682 (Lisp_Object filename, Lisp_Object string)
2688{ 2683{
@@ -2815,7 +2810,17 @@ really is a readable and searchable directory. */)
2815 if (!NILP (handler)) 2810 if (!NILP (handler))
2816 { 2811 {
2817 Lisp_Object r = call2 (handler, Qfile_accessible_directory_p, absname); 2812 Lisp_Object r = call2 (handler, Qfile_accessible_directory_p, absname);
2818 errno = 0; 2813
2814 /* Set errno in case the handler failed. EACCES might be a lie
2815 (e.g., the directory might not exist, or be a regular file),
2816 but at least it does TRT in the "usual" case of an existing
2817 directory that is not accessible by the current user, and
2818 avoids reporting "Success" for a failed operation. Perhaps
2819 someday we can fix this in a better way, by improving
2820 file-accessible-directory-p's API; see Bug#25419. */
2821 if (!EQ (r, Qt))
2822 errno = EACCES;
2823
2819 return r; 2824 return r;
2820 } 2825 }
2821 2826
@@ -3391,15 +3396,10 @@ decide_coding_unwind (Lisp_Object unwind_data)
3391static Lisp_Object 3396static Lisp_Object
3392read_non_regular (Lisp_Object state) 3397read_non_regular (Lisp_Object state)
3393{ 3398{
3394 int nbytes; 3399 int nbytes = emacs_read_quit (XSAVE_INTEGER (state, 0),
3395 3400 ((char *) BEG_ADDR + PT_BYTE - BEG_BYTE
3396 immediate_quit = 1; 3401 + XSAVE_INTEGER (state, 1)),
3397 QUIT; 3402 XSAVE_INTEGER (state, 2));
3398 nbytes = emacs_read (XSAVE_INTEGER (state, 0),
3399 ((char *) BEG_ADDR + PT_BYTE - BEG_BYTE
3400 + XSAVE_INTEGER (state, 1)),
3401 XSAVE_INTEGER (state, 2));
3402 immediate_quit = 0;
3403 /* Fast recycle this object for the likely next call. */ 3403 /* Fast recycle this object for the likely next call. */
3404 free_misc (state); 3404 free_misc (state);
3405 return make_number (nbytes); 3405 return make_number (nbytes);
@@ -3743,17 +3743,17 @@ by calling `format-decode', which see. */)
3743 int nread; 3743 int nread;
3744 3744
3745 if (st.st_size <= (1024 * 4)) 3745 if (st.st_size <= (1024 * 4))
3746 nread = emacs_read (fd, read_buf, 1024 * 4); 3746 nread = emacs_read_quit (fd, read_buf, 1024 * 4);
3747 else 3747 else
3748 { 3748 {
3749 nread = emacs_read (fd, read_buf, 1024); 3749 nread = emacs_read_quit (fd, read_buf, 1024);
3750 if (nread == 1024) 3750 if (nread == 1024)
3751 { 3751 {
3752 int ntail; 3752 int ntail;
3753 if (lseek (fd, - (1024 * 3), SEEK_END) < 0) 3753 if (lseek (fd, - (1024 * 3), SEEK_END) < 0)
3754 report_file_error ("Setting file position", 3754 report_file_error ("Setting file position",
3755 orig_filename); 3755 orig_filename);
3756 ntail = emacs_read (fd, read_buf + nread, 1024 * 3); 3756 ntail = emacs_read_quit (fd, read_buf + nread, 1024 * 3);
3757 nread = ntail < 0 ? ntail : nread + ntail; 3757 nread = ntail < 0 ? ntail : nread + ntail;
3758 } 3758 }
3759 } 3759 }
@@ -3858,15 +3858,11 @@ by calling `format-decode', which see. */)
3858 report_file_error ("Setting file position", orig_filename); 3858 report_file_error ("Setting file position", orig_filename);
3859 } 3859 }
3860 3860
3861 immediate_quit = 1;
3862 QUIT;
3863 /* Count how many chars at the start of the file 3861 /* Count how many chars at the start of the file
3864 match the text at the beginning of the buffer. */ 3862 match the text at the beginning of the buffer. */
3865 while (1) 3863 while (true)
3866 { 3864 {
3867 int nread, bufpos; 3865 int nread = emacs_read_quit (fd, read_buf, sizeof read_buf);
3868
3869 nread = emacs_read (fd, read_buf, sizeof read_buf);
3870 if (nread < 0) 3866 if (nread < 0)
3871 report_file_error ("Read error", orig_filename); 3867 report_file_error ("Read error", orig_filename);
3872 else if (nread == 0) 3868 else if (nread == 0)
@@ -3888,7 +3884,7 @@ by calling `format-decode', which see. */)
3888 break; 3884 break;
3889 } 3885 }
3890 3886
3891 bufpos = 0; 3887 int bufpos = 0;
3892 while (bufpos < nread && same_at_start < ZV_BYTE 3888 while (bufpos < nread && same_at_start < ZV_BYTE
3893 && FETCH_BYTE (same_at_start) == read_buf[bufpos]) 3889 && FETCH_BYTE (same_at_start) == read_buf[bufpos])
3894 same_at_start++, bufpos++; 3890 same_at_start++, bufpos++;
@@ -3897,7 +3893,6 @@ by calling `format-decode', which see. */)
3897 if (bufpos != nread) 3893 if (bufpos != nread)
3898 break; 3894 break;
3899 } 3895 }
3900 immediate_quit = false;
3901 /* If the file matches the buffer completely, 3896 /* If the file matches the buffer completely,
3902 there's no need to replace anything. */ 3897 there's no need to replace anything. */
3903 if (same_at_start - BEGV_BYTE == end_offset - beg_offset) 3898 if (same_at_start - BEGV_BYTE == end_offset - beg_offset)
@@ -3909,8 +3904,7 @@ by calling `format-decode', which see. */)
3909 del_range_1 (same_at_start, same_at_end, 0, 0); 3904 del_range_1 (same_at_start, same_at_end, 0, 0);
3910 goto handled; 3905 goto handled;
3911 } 3906 }
3912 immediate_quit = true; 3907
3913 QUIT;
3914 /* Count how many chars at the end of the file 3908 /* Count how many chars at the end of the file
3915 match the text at the end of the buffer. But, if we have 3909 match the text at the end of the buffer. But, if we have
3916 already found that decoding is necessary, don't waste time. */ 3910 already found that decoding is necessary, don't waste time. */
@@ -3932,7 +3926,8 @@ by calling `format-decode', which see. */)
3932 total_read = nread = 0; 3926 total_read = nread = 0;
3933 while (total_read < trial) 3927 while (total_read < trial)
3934 { 3928 {
3935 nread = emacs_read (fd, read_buf + total_read, trial - total_read); 3929 nread = emacs_read_quit (fd, read_buf + total_read,
3930 trial - total_read);
3936 if (nread < 0) 3931 if (nread < 0)
3937 report_file_error ("Read error", orig_filename); 3932 report_file_error ("Read error", orig_filename);
3938 else if (nread == 0) 3933 else if (nread == 0)
@@ -3967,7 +3962,6 @@ by calling `format-decode', which see. */)
3967 if (nread == 0) 3962 if (nread == 0)
3968 break; 3963 break;
3969 } 3964 }
3970 immediate_quit = 0;
3971 3965
3972 if (! giveup_match_end) 3966 if (! giveup_match_end)
3973 { 3967 {
@@ -4059,18 +4053,13 @@ by calling `format-decode', which see. */)
4059 inserted = 0; /* Bytes put into CONVERSION_BUFFER so far. */ 4053 inserted = 0; /* Bytes put into CONVERSION_BUFFER so far. */
4060 unprocessed = 0; /* Bytes not processed in previous loop. */ 4054 unprocessed = 0; /* Bytes not processed in previous loop. */
4061 4055
4062 while (1) 4056 while (true)
4063 { 4057 {
4064 /* Read at most READ_BUF_SIZE bytes at a time, to allow 4058 /* Read at most READ_BUF_SIZE bytes at a time, to allow
4065 quitting while reading a huge file. */ 4059 quitting while reading a huge file. */
4066 4060
4067 /* Allow quitting out of the actual I/O. */ 4061 this = emacs_read_quit (fd, read_buf + unprocessed,
4068 immediate_quit = 1; 4062 READ_BUF_SIZE - unprocessed);
4069 QUIT;
4070 this = emacs_read (fd, read_buf + unprocessed,
4071 READ_BUF_SIZE - unprocessed);
4072 immediate_quit = 0;
4073
4074 if (this <= 0) 4063 if (this <= 0)
4075 break; 4064 break;
4076 4065
@@ -4284,13 +4273,10 @@ by calling `format-decode', which see. */)
4284 /* Allow quitting out of the actual I/O. We don't make text 4273 /* Allow quitting out of the actual I/O. We don't make text
4285 part of the buffer until all the reading is done, so a C-g 4274 part of the buffer until all the reading is done, so a C-g
4286 here doesn't do any harm. */ 4275 here doesn't do any harm. */
4287 immediate_quit = 1; 4276 this = emacs_read_quit (fd,
4288 QUIT; 4277 ((char *) BEG_ADDR + PT_BYTE - BEG_BYTE
4289 this = emacs_read (fd, 4278 + inserted),
4290 ((char *) BEG_ADDR + PT_BYTE - BEG_BYTE 4279 trytry);
4291 + inserted),
4292 trytry);
4293 immediate_quit = 0;
4294 } 4280 }
4295 4281
4296 if (this <= 0) 4282 if (this <= 0)
@@ -4602,7 +4588,7 @@ by calling `format-decode', which see. */)
4602 } 4588 }
4603 } 4589 }
4604 4590
4605 QUIT; 4591 maybe_quit ();
4606 p = XCDR (p); 4592 p = XCDR (p);
4607 } 4593 }
4608 4594
@@ -4992,8 +4978,6 @@ write_region (Lisp_Object start, Lisp_Object end, Lisp_Object filename,
4992 } 4978 }
4993 } 4979 }
4994 4980
4995 immediate_quit = 1;
4996
4997 if (STRINGP (start)) 4981 if (STRINGP (start))
4998 ok = a_write (desc, start, 0, SCHARS (start), &annotations, &coding); 4982 ok = a_write (desc, start, 0, SCHARS (start), &annotations, &coding);
4999 else if (XINT (start) != XINT (end)) 4983 else if (XINT (start) != XINT (end))
@@ -5016,8 +5000,6 @@ write_region (Lisp_Object start, Lisp_Object end, Lisp_Object filename,
5016 save_errno = errno; 5000 save_errno = errno;
5017 } 5001 }
5018 5002
5019 immediate_quit = 0;
5020
5021 /* fsync is not crucial for temporary files. Nor for auto-save 5003 /* fsync is not crucial for temporary files. Nor for auto-save
5022 files, since they might lose some work anyway. */ 5004 files, since they might lose some work anyway. */
5023 if (open_and_close_file && !auto_saving && !write_region_inhibit_fsync) 5005 if (open_and_close_file && !auto_saving && !write_region_inhibit_fsync)
@@ -5407,7 +5389,7 @@ e_write (int desc, Lisp_Object string, ptrdiff_t start, ptrdiff_t end,
5407 : (STRINGP (coding->dst_object) 5389 : (STRINGP (coding->dst_object)
5408 ? SSDATA (coding->dst_object) 5390 ? SSDATA (coding->dst_object)
5409 : (char *) BYTE_POS_ADDR (coding->dst_pos_byte))); 5391 : (char *) BYTE_POS_ADDR (coding->dst_pos_byte)));
5410 coding->produced -= emacs_write_sig (desc, buf, coding->produced); 5392 coding->produced -= emacs_write_quit (desc, buf, coding->produced);
5411 5393
5412 if (coding->raw_destination) 5394 if (coding->raw_destination)
5413 { 5395 {