Mercurial > hg > xemacs-beta
comparison src/fileio.c @ 4266:c5a2b80bc4fa
[xemacs-hg @ 2007-11-14 18:51:20 by aidan]
Import make-temp-name (the functionality of mkstemp(3)) from GNU.
author | aidan |
---|---|
date | Wed, 14 Nov 2007 18:51:31 +0000 |
parents | 5989b9bbb612 |
children | 5e526366d533 |
comparison
equal
deleted
inserted
replaced
4265:dc697b1b786f | 4266:c5a2b80bc4fa |
---|---|
120 | 120 |
121 static Lisp_Object Vinhibit_file_name_handlers; | 121 static Lisp_Object Vinhibit_file_name_handlers; |
122 static Lisp_Object Vinhibit_file_name_operation; | 122 static Lisp_Object Vinhibit_file_name_operation; |
123 | 123 |
124 Lisp_Object Qfile_already_exists; | 124 Lisp_Object Qfile_already_exists; |
125 Lisp_Object Qexcl; | |
125 | 126 |
126 Lisp_Object Qauto_save_hook; | 127 Lisp_Object Qauto_save_hook; |
127 Lisp_Object Qauto_save_error; | 128 Lisp_Object Qauto_save_error; |
128 Lisp_Object Qauto_saving; | 129 Lisp_Object Qauto_saving; |
129 | 130 |
621 The Emacs process number forms part of the result, so there is no | 622 The Emacs process number forms part of the result, so there is no |
622 danger of generating a name being used by another process. | 623 danger of generating a name being used by another process. |
623 | 624 |
624 In addition, this function makes an attempt to choose a name that | 625 In addition, this function makes an attempt to choose a name that |
625 does not specify an existing file. To make this work, PREFIX should | 626 does not specify an existing file. To make this work, PREFIX should |
626 be an absolute file name. A reasonable idiom is | 627 be an absolute file name. |
627 | 628 |
628 \(make-temp-name (expand-file-name "myprefix" (temp-directory))) | 629 This function is analagous to mktemp(3) under POSIX, and as with it, there |
629 | 630 exists a race condition between the test for the existence of the new file |
630 which puts the file in the OS-specified temporary directory. | 631 and its creation. See `make-temp-name' for a function which avoids this |
632 race condition by specifying the appropriate flags to `write-region'. | |
631 */ | 633 */ |
632 (prefix)) | 634 (prefix)) |
633 { | 635 { |
634 static const char tbl[64] = | 636 static const char tbl[64] = |
635 { | 637 { |
3311 Fset_buffer (buf); | 3313 Fset_buffer (buf); |
3312 Fkill_buffer (tembuf); | 3314 Fkill_buffer (tembuf); |
3313 return Qnil; | 3315 return Qnil; |
3314 } | 3316 } |
3315 | 3317 |
3316 DEFUN ("write-region-internal", Fwrite_region_internal, 3, 7, | 3318 DEFUN ("write-region-internal", Fwrite_region_internal, 3, 8, |
3317 "r\nFWrite region to file: ", /* | 3319 "r\nFWrite region to file: ", /* |
3318 Write current region into specified file; no coding-system frobbing. | 3320 Write current region into specified file; no coding-system frobbing. |
3319 This function is identical to `write-region' except for the handling | 3321 |
3320 of the CODESYS argument under XEmacs/Mule. (When Mule support is not | 3322 This function is almost identical to `write-region'; see that function for |
3321 present, both functions are identical and ignore the CODESYS argument.) | 3323 documentation of the START, END, FILENAME, APPEND, VISIT, and LOCKNAME |
3322 If support for Mule exists in this Emacs, the file is encoded according | 3324 arguments. CODESYS specifies the encoding to be used for the file; if it is |
3323 to the value of CODESYS. If this is nil, no code conversion occurs. | 3325 nil, no code conversion occurs. (With `write-region' the coding system is |
3326 determined automatically if not specified.) | |
3327 | |
3328 MUSTBENEW specifies that a check for an existing file of the same name | |
3329 should be made. If it is 'excl, XEmacs will error on detecting such a file | |
3330 and never write it. If it is some other non-nil value, the user will be | |
3331 prompted to confirm the overwriting of an existing file. If it is nil, | |
3332 existing files are silently overwritten when file system permissions allow | |
3333 this. | |
3324 | 3334 |
3325 As a special kludge to support auto-saving, when START is nil START and | 3335 As a special kludge to support auto-saving, when START is nil START and |
3326 END are set to the beginning and end, respectively, of the buffer, | 3336 END are set to the beginning and end, respectively, of the buffer, |
3327 regardless of any restrictions. Don't use this feature. It is documented | 3337 regardless of any restrictions. Don't use this feature. It is documented |
3328 here because write-region handler writers need to be aware of it. | 3338 here because write-region handler writers need to be aware of it. |
3329 */ | 3339 |
3330 (start, end, filename, append, visit, lockname, codesys)) | 3340 */ |
3341 (start, end, filename, append, visit, lockname, codesys, | |
3342 mustbenew)) | |
3331 { | 3343 { |
3332 /* This function can call lisp. GC checked 2000-07-28 ben */ | 3344 /* This function can call lisp. GC checked 2000-07-28 ben */ |
3333 int desc; | 3345 int desc; |
3334 int failure; | 3346 int failure; |
3335 int save_errno = 0; | 3347 int save_errno = 0; |
3370 get_buffer_range_char (current_buffer, start, end, &start1, &end1, 0); | 3382 get_buffer_range_char (current_buffer, start, end, &start1, &end1, 0); |
3371 | 3383 |
3372 { | 3384 { |
3373 Lisp_Object handler; | 3385 Lisp_Object handler; |
3374 | 3386 |
3387 if (!NILP (mustbenew) && !EQ (mustbenew, Qexcl)) | |
3388 barf_or_query_if_file_exists (filename, "overwrite", 1, NULL); | |
3389 | |
3375 if (visiting_other) | 3390 if (visiting_other) |
3376 visit_file = Fexpand_file_name (visit, Qnil); | 3391 visit_file = Fexpand_file_name (visit, Qnil); |
3377 else | 3392 else |
3378 visit_file = filename; | 3393 visit_file = filename; |
3379 filename = Fexpand_file_name (filename, Qnil); | 3394 filename = Fexpand_file_name (filename, Qnil); |
3431 | 3446 |
3432 fn = filename; | 3447 fn = filename; |
3433 desc = -1; | 3448 desc = -1; |
3434 if (!NILP (append)) | 3449 if (!NILP (append)) |
3435 { | 3450 { |
3436 desc = qxe_open (XSTRING_DATA (fn), O_WRONLY | OPEN_BINARY, 0); | 3451 desc = qxe_open (XSTRING_DATA (fn), O_WRONLY | OPEN_BINARY |
3452 | (EQ (mustbenew, Qexcl) ? O_EXCL : 0), 0); | |
3437 } | 3453 } |
3438 if (desc < 0) | 3454 if (desc < 0) |
3439 { | 3455 { |
3440 desc = qxe_open (XSTRING_DATA (fn), | 3456 desc = qxe_open (XSTRING_DATA (fn), |
3441 O_WRONLY | O_TRUNC | O_CREAT | OPEN_BINARY, | 3457 O_WRONLY | (EQ (mustbenew, Qexcl) ? O_EXCL : O_TRUNC) |
3458 | O_CREAT | OPEN_BINARY, | |
3442 auto_saving ? auto_save_mode_bits : CREAT_MODE); | 3459 auto_saving ? auto_save_mode_bits : CREAT_MODE); |
3443 } | 3460 } |
3444 | 3461 |
3445 if (desc < 0) | 3462 if (desc < 0) |
3446 { | 3463 { |
4005 | 4022 |
4006 return | 4023 return |
4007 Fwrite_region_internal (Qnil, Qnil, a, Qnil, Qlambda, Qnil, | 4024 Fwrite_region_internal (Qnil, Qnil, a, Qnil, Qlambda, Qnil, |
4008 #if 1 /* #### Kyle wants it changed to not use escape-quoted. Think | 4025 #if 1 /* #### Kyle wants it changed to not use escape-quoted. Think |
4009 carefully about how this works. */ | 4026 carefully about how this works. */ |
4010 Qescape_quoted | 4027 Qescape_quoted, |
4011 #else | 4028 #else |
4012 current_buffer->buffer_file_coding_system | 4029 current_buffer->buffer_file_coding_system, |
4013 #endif | 4030 #endif |
4014 ); | 4031 Qnil); |
4015 } | 4032 } |
4016 | 4033 |
4017 static Lisp_Object | 4034 static Lisp_Object |
4018 auto_save_expand_name_error (Lisp_Object condition_object, | 4035 auto_save_expand_name_error (Lisp_Object condition_object, |
4019 Lisp_Object UNUSED (ignored)) | 4036 Lisp_Object UNUSED (ignored)) |
4365 DEFSYMBOL (Qinsert_file_contents); | 4382 DEFSYMBOL (Qinsert_file_contents); |
4366 DEFSYMBOL (Qwrite_region); | 4383 DEFSYMBOL (Qwrite_region); |
4367 DEFSYMBOL (Qverify_visited_file_modtime); | 4384 DEFSYMBOL (Qverify_visited_file_modtime); |
4368 DEFSYMBOL (Qset_visited_file_modtime); | 4385 DEFSYMBOL (Qset_visited_file_modtime); |
4369 DEFSYMBOL (Qcar_less_than_car); /* Vomitous! */ | 4386 DEFSYMBOL (Qcar_less_than_car); /* Vomitous! */ |
4387 DEFSYMBOL (Qexcl); | |
4370 | 4388 |
4371 DEFSYMBOL (Qauto_save_hook); | 4389 DEFSYMBOL (Qauto_save_hook); |
4372 DEFSYMBOL (Qauto_save_error); | 4390 DEFSYMBOL (Qauto_save_error); |
4373 DEFSYMBOL (Qauto_saving); | 4391 DEFSYMBOL (Qauto_saving); |
4374 | 4392 |