Mercurial > emacs
comparison src/fileio.c @ 25595:6671095a2649
(Qexcl): New variable.
(report_file_error): Handle EEXIST specially.
(Fwrite_region): Special handling for CONFIRM = `excl'.
(syms_of_fileio): Initialize Qexcl.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 07 Sep 1999 18:20:27 +0000 |
parents | 4d553f7390dc |
children | 16a9c3c6f90e |
comparison
equal
deleted
inserted
replaced
25594:2d1ef4eb8297 | 25595:6671095a2649 |
---|---|
234 | 234 |
235 static Lisp_Object Vinhibit_file_name_handlers; | 235 static Lisp_Object Vinhibit_file_name_handlers; |
236 static Lisp_Object Vinhibit_file_name_operation; | 236 static Lisp_Object Vinhibit_file_name_operation; |
237 | 237 |
238 Lisp_Object Qfile_error, Qfile_already_exists, Qfile_date_error; | 238 Lisp_Object Qfile_error, Qfile_already_exists, Qfile_date_error; |
239 | 239 Lisp_Object Qexcl; |
240 Lisp_Object Qfile_name_history; | 240 Lisp_Object Qfile_name_history; |
241 | 241 |
242 Lisp_Object Qcar_less_than_car; | 242 Lisp_Object Qcar_less_than_car; |
243 | 243 |
244 static int a_write P_ ((int, char *, int, int, | 244 static int a_write P_ ((int, char *, int, int, |
249 report_file_error (string, data) | 249 report_file_error (string, data) |
250 char *string; | 250 char *string; |
251 Lisp_Object data; | 251 Lisp_Object data; |
252 { | 252 { |
253 Lisp_Object errstring; | 253 Lisp_Object errstring; |
254 int errorno = errno; | |
254 | 255 |
255 errstring = build_string (strerror (errno)); | 256 errstring = build_string (strerror (errno)); |
256 | |
257 /* System error messages are capitalized. Downcase the initial | |
258 unless it is followed by a slash. */ | |
259 if (XSTRING (errstring)->data[1] != '/') | |
260 XSTRING (errstring)->data[0] = DOWNCASE (XSTRING (errstring)->data[0]); | |
261 | |
262 while (1) | 257 while (1) |
263 Fsignal (Qfile_error, | 258 switch (errorno) |
264 Fcons (build_string (string), Fcons (errstring, data))); | 259 { |
260 case EEXIST: | |
261 Fsignal (Qfile_already_exists, Fcons (errstring, data)); | |
262 break; | |
263 default: | |
264 /* System error messages are capitalized. Downcase the initial | |
265 unless it is followed by a slash. */ | |
266 if (XSTRING (errstring)->data[1] != '/') | |
267 XSTRING (errstring)->data[0] = DOWNCASE (XSTRING (errstring)->data[0]); | |
268 | |
269 Fsignal (Qfile_error, | |
270 Fcons (build_string (string), Fcons (errstring, data))); | |
271 } | |
265 } | 272 } |
266 | 273 |
267 Lisp_Object | 274 Lisp_Object |
268 close_file_unwind (fd) | 275 close_file_unwind (fd) |
269 Lisp_Object fd; | 276 Lisp_Object fd; |
4261 If VISIT is neither t nor nil nor a string,\n\ | 4268 If VISIT is neither t nor nil nor a string,\n\ |
4262 that means do not print the \"Wrote file\" message.\n\ | 4269 that means do not print the \"Wrote file\" message.\n\ |
4263 The optional sixth arg LOCKNAME, if non-nil, specifies the name to\n\ | 4270 The optional sixth arg LOCKNAME, if non-nil, specifies the name to\n\ |
4264 use for locking and unlocking, overriding FILENAME and VISIT.\n\ | 4271 use for locking and unlocking, overriding FILENAME and VISIT.\n\ |
4265 The optional seventh arg CONFIRM, if non-nil, says ask for confirmation\n\ | 4272 The optional seventh arg CONFIRM, if non-nil, says ask for confirmation\n\ |
4266 before overwriting an existing file.\n\ | 4273 before overwriting an existing file and if equal to `excl', specifies\n\ |
4274 that an error should be raised if the file already exists.\n\ | |
4267 Kludgy feature: if START is a string, then that string is written\n\ | 4275 Kludgy feature: if START is a string, then that string is written\n\ |
4268 to the file, instead of any buffer contents, and END is ignored.\n\ | 4276 to the file, instead of any buffer contents, and END is ignored.\n\ |
4269 \n\ | 4277 \n\ |
4270 This does code conversion according to the value of\n\ | 4278 This does code conversion according to the value of\n\ |
4271 `coding-system-for-write', `buffer-file-coding-system', or\n\ | 4279 `coding-system-for-write', `buffer-file-coding-system', or\n\ |
4399 | 4407 |
4400 Vlast_coding_system_used = coding.symbol; | 4408 Vlast_coding_system_used = coding.symbol; |
4401 | 4409 |
4402 filename = Fexpand_file_name (filename, Qnil); | 4410 filename = Fexpand_file_name (filename, Qnil); |
4403 | 4411 |
4404 if (! NILP (confirm)) | 4412 if (! NILP (confirm) && confirm != Qexcl) |
4405 barf_or_query_if_file_exists (filename, "overwrite", 1, 0, 1); | 4413 barf_or_query_if_file_exists (filename, "overwrite", 1, 0, 1); |
4406 | 4414 |
4407 if (STRINGP (visit)) | 4415 if (STRINGP (visit)) |
4408 visit_file = Fexpand_file_name (visit, Qnil); | 4416 visit_file = Fexpand_file_name (visit, Qnil); |
4409 else | 4417 else |
4536 #ifdef DOS_NT | 4544 #ifdef DOS_NT |
4537 desc = open (fn, | 4545 desc = open (fn, |
4538 O_WRONLY | O_TRUNC | O_CREAT | buffer_file_type, | 4546 O_WRONLY | O_TRUNC | O_CREAT | buffer_file_type, |
4539 S_IREAD | S_IWRITE); | 4547 S_IREAD | S_IWRITE); |
4540 #else /* not DOS_NT */ | 4548 #else /* not DOS_NT */ |
4541 desc = creat (fn, auto_saving ? auto_save_mode_bits : 0666); | 4549 desc = open (fn, O_WRONLY | O_TRUNC | O_CREAT |
4550 | (confirm == Qexcl ? O_EXCL : 0), | |
4551 auto_saving ? auto_save_mode_bits : 0666); | |
4542 #endif /* not DOS_NT */ | 4552 #endif /* not DOS_NT */ |
4543 #endif /* not VMS */ | 4553 #endif /* not VMS */ |
4544 | 4554 |
4545 UNGCPRO; | 4555 UNGCPRO; |
4546 | 4556 |
5646 staticpro (&Qfile_error); | 5656 staticpro (&Qfile_error); |
5647 Qfile_already_exists = intern ("file-already-exists"); | 5657 Qfile_already_exists = intern ("file-already-exists"); |
5648 staticpro (&Qfile_already_exists); | 5658 staticpro (&Qfile_already_exists); |
5649 Qfile_date_error = intern ("file-date-error"); | 5659 Qfile_date_error = intern ("file-date-error"); |
5650 staticpro (&Qfile_date_error); | 5660 staticpro (&Qfile_date_error); |
5661 Qexcl = intern ("excl"); | |
5662 staticpro (&Qexcl); | |
5651 | 5663 |
5652 #ifdef DOS_NT | 5664 #ifdef DOS_NT |
5653 Qfind_buffer_file_type = intern ("find-buffer-file-type"); | 5665 Qfind_buffer_file_type = intern ("find-buffer-file-type"); |
5654 staticpro (&Qfind_buffer_file_type); | 5666 staticpro (&Qfind_buffer_file_type); |
5655 #endif /* DOS_NT */ | 5667 #endif /* DOS_NT */ |