changeset 18270:fd2ccbdc5660

(Fdo_auto_save): Use stdio to write the save-list file. (Finsert_file_contents): Don't give up on the fast replace method if the coding remains undecided.
author Richard M. Stallman <rms@gnu.org>
date Mon, 16 Jun 1997 07:31:56 +0000
parents 888bfd80db2c
children ead435447ea4
files src/fileio.c
diffstat 1 files changed, 32 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/src/fileio.c	Mon Jun 16 07:29:16 1997 +0000
+++ b/src/fileio.c	Mon Jun 16 07:31:56 1997 +0000
@@ -24,6 +24,7 @@
 #include <fcntl.h>
 #endif
 
+#include <stdio.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 
@@ -3202,7 +3203,8 @@
 
 	  if (coding.type == coding_type_undecided)
 	    detect_coding (&coding, buffer, nread);
-	  if (CODING_REQUIRE_TEXT_CONVERSION (&coding))
+	  if (coding.type != coding_type_undecided
+	      && CODING_REQUIRE_TEXT_CONVERSION (&coding))
 	    /* We found that the file should be decoded somehow.
                Let's give up here.  */
 	    {
@@ -3212,7 +3214,8 @@
 
 	  if (coding.eol_type == CODING_EOL_UNDECIDED)
 	    detect_eol (&coding, buffer, nread);
-	  if (CODING_REQUIRE_EOL_CONVERSION (&coding))
+	  if (coding.eol_type != CODING_EOL_UNDECIDED
+	      && CODING_REQUIRE_EOL_CONVERSION (&coding))
 	    /* We found that the format of eol should be decoded.
                Let's give up here.  */
 	    {
@@ -4452,12 +4455,13 @@
 }
 
 static Lisp_Object
-do_auto_save_unwind (desc)  /* used as unwind-protect function */
-     Lisp_Object desc;
+do_auto_save_unwind (stream)  /* used as unwind-protect function */
+     Lisp_Object stream;
 {
   auto_saving = 0;
-  if (XINT (desc) >= 0)
-    close (XINT (desc));
+  if (!NILP (stream))
+    fclose ((FILE *) (XFASTINT (XCONS (stream)->car) << 16
+		      | XFASTINT (XCONS (stream)->cdr)));
   return Qnil;
 }
 
@@ -4481,7 +4485,8 @@
   int omessage_length = echo_area_glyphs_length;
   int do_handled_files;
   Lisp_Object oquit;
-  int listdesc;
+  FILE *stream;
+  Lisp_Object lispstream;
   int count = specpdl_ptr - specpdl;
   int *ptr;
 
@@ -4503,20 +4508,21 @@
     {
       Lisp_Object listfile;
       listfile = Fexpand_file_name (Vauto_save_list_file_name, Qnil);
-#ifdef DOS_NT
-      listdesc = open (XSTRING (listfile)->data,
-		       O_WRONLY | O_TRUNC | O_CREAT | O_TEXT,
-		       S_IREAD | S_IWRITE);
-#else  /* not DOS_NT */
-      listdesc = creat (XSTRING (listfile)->data, 0666);
-#endif /* not DOS_NT */
+      stream = fopen (XSTRING (listfile)->data, "w");
+
+      /* Arrange to close that file whether or not we get an error.
+	 Also reset auto_saving to 0.  */
+      lispstream = Fcons (Qnil, Qnil);
+      XSETFASTINT (XCONS (lispstream)->car, (EMACS_UINT)stream >> 16);
+      XSETFASTINT (XCONS (lispstream)->cdr, (EMACS_UINT)stream & 0xffff);
     }
   else
-    listdesc = -1;
-
-  /* Arrange to close that file whether or not we get an error.
-     Also reset auto_saving to 0.  */
-  record_unwind_protect (do_auto_save_unwind, make_number (listdesc));
+    {
+      stream = NULL;
+      lispstream = Qnil;
+    }
+
+  record_unwind_protect (do_auto_save_unwind, lispstream);
 
   auto_saving = 1;
 
@@ -4535,17 +4541,17 @@
 	   in the special file that lists them.  For each of these buffers,
 	   Record visited name (if any) and auto save name.  */
 	if (STRINGP (b->auto_save_file_name)
-	    && listdesc >= 0 && do_handled_files == 0)
+	    && stream != NULL && do_handled_files == 0)
 	  {
 	    if (!NILP (b->filename))
 	      {
-		write (listdesc, XSTRING (b->filename)->data,
-		       XSTRING (b->filename)->size);
+		fwrite (XSTRING (b->filename)->data, 1,
+			XSTRING (b->filename)->size, stream);
 	      }
-	    write (listdesc, "\n", 1);
-	    write (listdesc, XSTRING (b->auto_save_file_name)->data,
-		   XSTRING (b->auto_save_file_name)->size);
-	    write (listdesc, "\n", 1);
+	    putc ('\n', stream);
+	    fwrite (XSTRING (b->auto_save_file_name)->data, 1,
+		    XSTRING (b->auto_save_file_name)->size, stream);
+	    putc ('\n', stream);
 	  }
 
 	if (!NILP (current_only)