diff src/fileio.c @ 592:e65af468dcc2

*** empty log message ***
author Richard M. Stallman <rms@gnu.org>
date Fri, 20 Mar 1992 20:54:03 +0000
parents d909f2be7ee1
children 114b502d0822
line wrap: on
line diff
--- a/src/fileio.c	Fri Mar 20 17:00:55 1992 +0000
+++ b/src/fileio.c	Fri Mar 20 20:54:03 1992 +0000
@@ -117,6 +117,12 @@
     Fsignal (Qfile_error,
 	     Fcons (build_string (string), Fcons (errstring, data)));
 }
+
+close_file_unwind (fd)
+     Lisp_Object fd;
+{
+  close (XFASTINT (fd));
+}
 
 DEFUN ("file-name-directory", Ffile_name_directory, Sfile_name_directory,
   1, 1, 0,
@@ -1374,6 +1380,7 @@
   char buf[16 * 1024];
   struct stat st;
   struct gcpro gcpro1, gcpro2;
+  int count = specpdl_ptr - specpdl;
 
   GCPRO2 (filename, newname);
   CHECK_STRING (filename, 0);
@@ -1389,6 +1396,8 @@
   if (ifd < 0)
     report_file_error ("Opening input file", Fcons (filename, Qnil));
 
+  record_unwind_protect (close_file_unwind, make_number (ifd));
+
 #ifdef VMS
   /* Create the copy file with the same record format as the input file */
   ofd = sys_creat (XSTRING (newname)->data, 0666, ifd);
@@ -1396,18 +1405,16 @@
   ofd = creat (XSTRING (newname)->data, 0666);
 #endif /* VMS */
   if (ofd < 0)
-    {
-      close (ifd);
-      report_file_error ("Opening output file", Fcons (newname, Qnil));
-    }
+    report_file_error ("Opening output file", Fcons (newname, Qnil));
 
+  record_unwind_protect (close_file_unwind, make_number (ofd));
+
+  immediate_quit = 1;
+  QUIT;
   while ((n = read (ifd, buf, sizeof buf)) > 0)
     if (write (ofd, buf, n) != n)
-      {
-	close (ifd);
-	close (ofd);
-	report_file_error ("I/O error", Fcons (newname, Qnil));
-      }
+      report_file_error ("I/O error", Fcons (newname, Qnil));
+  immediate_quit = 0;
 
   if (fstat (ifd, &st) >= 0)
     {
@@ -1424,6 +1431,9 @@
 	chmod (XSTRING (newname)->data, st.st_mode & 07777);
     }
 
+  /* Discard the unwind protects.  */
+  specpdl_ptr = specpdl + count;
+
   close (ifd);
   if (close (ofd) < 0)
     report_file_error ("I/O error", Fcons (newname, Qnil));
@@ -1949,12 +1959,6 @@
   return (mtime1 > st.st_mtime) ? Qt : Qnil;
 }
 
-close_file_unwind (fd)
-     Lisp_Object fd;
-{
-  close (XFASTINT (fd));
-}
-
 DEFUN ("insert-file-contents", Finsert_file_contents, Sinsert_file_contents,
   1, 2, 0,
   "Insert contents of file FILENAME after point.\n\
@@ -2022,7 +2026,13 @@
   while (1)
     {
       int try = min (st.st_size - inserted, 64 << 10);
-      int this = read (fd, &FETCH_CHAR (point + inserted - 1) + 1, try);
+      int this;
+
+      /* Allow quitting out of the actual I/O.  */
+      immediate_quit = 1;
+      QUIT;
+      this = read (fd, &FETCH_CHAR (point + inserted - 1) + 1, try);
+      immediate_quit = 0;
 
       if (this <= 0)
 	{