Mercurial > emacs
comparison src/fileio.c @ 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 | 2338261796d2 |
children | 8208c168c5cc |
comparison
equal
deleted
inserted
replaced
18269:888bfd80db2c | 18270:fd2ccbdc5660 |
---|---|
22 | 22 |
23 #if defined (USG5) || defined (BSD_SYSTEM) || defined (LINUX) | 23 #if defined (USG5) || defined (BSD_SYSTEM) || defined (LINUX) |
24 #include <fcntl.h> | 24 #include <fcntl.h> |
25 #endif | 25 #endif |
26 | 26 |
27 #include <stdio.h> | |
27 #include <sys/types.h> | 28 #include <sys/types.h> |
28 #include <sys/stat.h> | 29 #include <sys/stat.h> |
29 | 30 |
30 #ifdef HAVE_UNISTD_H | 31 #ifdef HAVE_UNISTD_H |
31 #include <unistd.h> | 32 #include <unistd.h> |
3200 else if (nread == 0) | 3201 else if (nread == 0) |
3201 break; | 3202 break; |
3202 | 3203 |
3203 if (coding.type == coding_type_undecided) | 3204 if (coding.type == coding_type_undecided) |
3204 detect_coding (&coding, buffer, nread); | 3205 detect_coding (&coding, buffer, nread); |
3205 if (CODING_REQUIRE_TEXT_CONVERSION (&coding)) | 3206 if (coding.type != coding_type_undecided |
3207 && CODING_REQUIRE_TEXT_CONVERSION (&coding)) | |
3206 /* We found that the file should be decoded somehow. | 3208 /* We found that the file should be decoded somehow. |
3207 Let's give up here. */ | 3209 Let's give up here. */ |
3208 { | 3210 { |
3209 giveup_match_end = 1; | 3211 giveup_match_end = 1; |
3210 break; | 3212 break; |
3211 } | 3213 } |
3212 | 3214 |
3213 if (coding.eol_type == CODING_EOL_UNDECIDED) | 3215 if (coding.eol_type == CODING_EOL_UNDECIDED) |
3214 detect_eol (&coding, buffer, nread); | 3216 detect_eol (&coding, buffer, nread); |
3215 if (CODING_REQUIRE_EOL_CONVERSION (&coding)) | 3217 if (coding.eol_type != CODING_EOL_UNDECIDED |
3218 && CODING_REQUIRE_EOL_CONVERSION (&coding)) | |
3216 /* We found that the format of eol should be decoded. | 3219 /* We found that the format of eol should be decoded. |
3217 Let's give up here. */ | 3220 Let's give up here. */ |
3218 { | 3221 { |
3219 giveup_match_end = 1; | 3222 giveup_match_end = 1; |
3220 break; | 3223 break; |
4450 current_buffer->auto_save_file_name, | 4453 current_buffer->auto_save_file_name, |
4451 Qnil, Qlambda, Qnil); | 4454 Qnil, Qlambda, Qnil); |
4452 } | 4455 } |
4453 | 4456 |
4454 static Lisp_Object | 4457 static Lisp_Object |
4455 do_auto_save_unwind (desc) /* used as unwind-protect function */ | 4458 do_auto_save_unwind (stream) /* used as unwind-protect function */ |
4456 Lisp_Object desc; | 4459 Lisp_Object stream; |
4457 { | 4460 { |
4458 auto_saving = 0; | 4461 auto_saving = 0; |
4459 if (XINT (desc) >= 0) | 4462 if (!NILP (stream)) |
4460 close (XINT (desc)); | 4463 fclose ((FILE *) (XFASTINT (XCONS (stream)->car) << 16 |
4464 | XFASTINT (XCONS (stream)->cdr))); | |
4461 return Qnil; | 4465 return Qnil; |
4462 } | 4466 } |
4463 | 4467 |
4464 DEFUN ("do-auto-save", Fdo_auto_save, Sdo_auto_save, 0, 2, "", | 4468 DEFUN ("do-auto-save", Fdo_auto_save, Sdo_auto_save, 0, 2, "", |
4465 "Auto-save all buffers that need it.\n\ | 4469 "Auto-save all buffers that need it.\n\ |
4479 int auto_saved = 0; | 4483 int auto_saved = 0; |
4480 char *omessage = echo_area_glyphs; | 4484 char *omessage = echo_area_glyphs; |
4481 int omessage_length = echo_area_glyphs_length; | 4485 int omessage_length = echo_area_glyphs_length; |
4482 int do_handled_files; | 4486 int do_handled_files; |
4483 Lisp_Object oquit; | 4487 Lisp_Object oquit; |
4484 int listdesc; | 4488 FILE *stream; |
4489 Lisp_Object lispstream; | |
4485 int count = specpdl_ptr - specpdl; | 4490 int count = specpdl_ptr - specpdl; |
4486 int *ptr; | 4491 int *ptr; |
4487 | 4492 |
4488 /* Ordinarily don't quit within this function, | 4493 /* Ordinarily don't quit within this function, |
4489 but don't make it impossible to quit (in case we get hung in I/O). */ | 4494 but don't make it impossible to quit (in case we get hung in I/O). */ |
4501 | 4506 |
4502 if (STRINGP (Vauto_save_list_file_name)) | 4507 if (STRINGP (Vauto_save_list_file_name)) |
4503 { | 4508 { |
4504 Lisp_Object listfile; | 4509 Lisp_Object listfile; |
4505 listfile = Fexpand_file_name (Vauto_save_list_file_name, Qnil); | 4510 listfile = Fexpand_file_name (Vauto_save_list_file_name, Qnil); |
4506 #ifdef DOS_NT | 4511 stream = fopen (XSTRING (listfile)->data, "w"); |
4507 listdesc = open (XSTRING (listfile)->data, | 4512 |
4508 O_WRONLY | O_TRUNC | O_CREAT | O_TEXT, | 4513 /* Arrange to close that file whether or not we get an error. |
4509 S_IREAD | S_IWRITE); | 4514 Also reset auto_saving to 0. */ |
4510 #else /* not DOS_NT */ | 4515 lispstream = Fcons (Qnil, Qnil); |
4511 listdesc = creat (XSTRING (listfile)->data, 0666); | 4516 XSETFASTINT (XCONS (lispstream)->car, (EMACS_UINT)stream >> 16); |
4512 #endif /* not DOS_NT */ | 4517 XSETFASTINT (XCONS (lispstream)->cdr, (EMACS_UINT)stream & 0xffff); |
4513 } | 4518 } |
4514 else | 4519 else |
4515 listdesc = -1; | 4520 { |
4516 | 4521 stream = NULL; |
4517 /* Arrange to close that file whether or not we get an error. | 4522 lispstream = Qnil; |
4518 Also reset auto_saving to 0. */ | 4523 } |
4519 record_unwind_protect (do_auto_save_unwind, make_number (listdesc)); | 4524 |
4525 record_unwind_protect (do_auto_save_unwind, lispstream); | |
4520 | 4526 |
4521 auto_saving = 1; | 4527 auto_saving = 1; |
4522 | 4528 |
4523 /* First, save all files which don't have handlers. If Emacs is | 4529 /* First, save all files which don't have handlers. If Emacs is |
4524 crashing, the handlers may tweak what is causing Emacs to crash | 4530 crashing, the handlers may tweak what is causing Emacs to crash |
4533 | 4539 |
4534 /* Record all the buffers that have auto save mode | 4540 /* Record all the buffers that have auto save mode |
4535 in the special file that lists them. For each of these buffers, | 4541 in the special file that lists them. For each of these buffers, |
4536 Record visited name (if any) and auto save name. */ | 4542 Record visited name (if any) and auto save name. */ |
4537 if (STRINGP (b->auto_save_file_name) | 4543 if (STRINGP (b->auto_save_file_name) |
4538 && listdesc >= 0 && do_handled_files == 0) | 4544 && stream != NULL && do_handled_files == 0) |
4539 { | 4545 { |
4540 if (!NILP (b->filename)) | 4546 if (!NILP (b->filename)) |
4541 { | 4547 { |
4542 write (listdesc, XSTRING (b->filename)->data, | 4548 fwrite (XSTRING (b->filename)->data, 1, |
4543 XSTRING (b->filename)->size); | 4549 XSTRING (b->filename)->size, stream); |
4544 } | 4550 } |
4545 write (listdesc, "\n", 1); | 4551 putc ('\n', stream); |
4546 write (listdesc, XSTRING (b->auto_save_file_name)->data, | 4552 fwrite (XSTRING (b->auto_save_file_name)->data, 1, |
4547 XSTRING (b->auto_save_file_name)->size); | 4553 XSTRING (b->auto_save_file_name)->size, stream); |
4548 write (listdesc, "\n", 1); | 4554 putc ('\n', stream); |
4549 } | 4555 } |
4550 | 4556 |
4551 if (!NILP (current_only) | 4557 if (!NILP (current_only) |
4552 && b != current_buffer) | 4558 && b != current_buffer) |
4553 continue; | 4559 continue; |