comparison src/fileio.c @ 83292:ad07ff6e4555

Merged from miles@gnu.org--gnu-2005 (patch 67, 270-278) Patches applied: * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-270 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-271 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-272 src/xdisp.c (dump_glyph_row): Don't display overlay_arrow_p field. * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-273 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-274 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-275 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-276 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-277 Merge from gnus--rel--5.10 * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-278 Update from CVS * miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-67 Update from CVS git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-332
author Karoly Lorentey <lorentey@elte.hu>
date Mon, 25 Apr 2005 11:49:38 +0000
parents 360860a0006f f1787300a867
children effe22690419
comparison
equal deleted inserted replaced
83291:bbf359ec4a59 83292:ad07ff6e4555
43 43
44 #if !defined (S_ISREG) && defined (S_IFREG) 44 #if !defined (S_ISREG) && defined (S_IFREG)
45 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) 45 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
46 #endif 46 #endif
47 47
48 #ifdef VMS 48 #ifdef HAVE_PWD_H
49 #include "vms-pwd.h"
50 #else
51 #include <pwd.h> 49 #include <pwd.h>
52 #endif 50 #endif
53 51
54 #include <ctype.h> 52 #include <ctype.h>
55 53
2390 statptr->st_mode = 0; 2388 statptr->st_mode = 0;
2391 } 2389 }
2392 return; 2390 return;
2393 } 2391 }
2394 2392
2395 DEFUN ("copy-file", Fcopy_file, Scopy_file, 2, 4, 2393 DEFUN ("copy-file", Fcopy_file, Scopy_file, 2, 5,
2396 "fCopy file: \nGCopy %s to file: \np\nP", 2394 "fCopy file: \nGCopy %s to file: \np\nP",
2397 doc: /* Copy FILE to NEWNAME. Both args must be strings. 2395 doc: /* Copy FILE to NEWNAME. Both args must be strings.
2398 If NEWNAME names a directory, copy FILE there. 2396 If NEWNAME names a directory, copy FILE there.
2399 Signals a `file-already-exists' error if file NEWNAME already exists, 2397 Signals a `file-already-exists' error if file NEWNAME already exists,
2400 unless a third argument OK-IF-ALREADY-EXISTS is supplied and non-nil. 2398 unless a third argument OK-IF-ALREADY-EXISTS is supplied and non-nil.
2401 A number as third arg means request confirmation if NEWNAME already exists. 2399 A number as third arg means request confirmation if NEWNAME already exists.
2402 This is what happens in interactive use with M-x. 2400 This is what happens in interactive use with M-x.
2403 Always sets the file modes of the output file to match the input file. 2401 Always sets the file modes of the output file to match the input file.
2402
2404 Fourth arg KEEP-TIME non-nil means give the output file the same 2403 Fourth arg KEEP-TIME non-nil means give the output file the same
2405 last-modified time as the old one. (This works on only some systems.) 2404 last-modified time as the old one. (This works on only some systems.)
2406 A prefix arg makes KEEP-TIME non-nil. */) 2405
2407 (file, newname, ok_if_already_exists, keep_time) 2406 A prefix arg makes KEEP-TIME non-nil.
2408 Lisp_Object file, newname, ok_if_already_exists, keep_time; 2407
2408 The optional fifth arg MUSTBENEW, if non-nil, insists on a check
2409 for an existing file with the same name. If MUSTBENEW is `excl',
2410 that means to get an error if the file already exists; never overwrite.
2411 If MUSTBENEW is neither nil nor `excl', that means ask for
2412 confirmation before overwriting, but do go ahead and overwrite the file
2413 if the user confirms. */)
2414 (file, newname, ok_if_already_exists, keep_time, mustbenew)
2415 Lisp_Object file, newname, ok_if_already_exists, keep_time, mustbenew;
2409 { 2416 {
2410 int ifd, ofd, n; 2417 int ifd, ofd, n;
2411 char buf[16 * 1024]; 2418 char buf[16 * 1024];
2412 struct stat st, out_st; 2419 struct stat st, out_st;
2413 Lisp_Object handler; 2420 Lisp_Object handler;
2418 2425
2419 encoded_file = encoded_newname = Qnil; 2426 encoded_file = encoded_newname = Qnil;
2420 GCPRO4 (file, newname, encoded_file, encoded_newname); 2427 GCPRO4 (file, newname, encoded_file, encoded_newname);
2421 CHECK_STRING (file); 2428 CHECK_STRING (file);
2422 CHECK_STRING (newname); 2429 CHECK_STRING (newname);
2430
2431 if (!NILP (mustbenew) && !EQ (mustbenew, Qexcl))
2432 barf_or_query_if_file_exists (newname, "overwrite", 1, 0, 1);
2423 2433
2424 if (!NILP (Ffile_directory_p (newname))) 2434 if (!NILP (Ffile_directory_p (newname)))
2425 newname = Fexpand_file_name (Ffile_name_nondirectory (file), newname); 2435 newname = Fexpand_file_name (Ffile_name_nondirectory (file), newname);
2426 else 2436 else
2427 newname = Fexpand_file_name (newname, Qnil); 2437 newname = Fexpand_file_name (newname, Qnil);
2519 /* Create the copy file with the same record format as the input file */ 2529 /* Create the copy file with the same record format as the input file */
2520 ofd = sys_creat (SDATA (encoded_newname), 0666, ifd); 2530 ofd = sys_creat (SDATA (encoded_newname), 0666, ifd);
2521 #else 2531 #else
2522 #ifdef MSDOS 2532 #ifdef MSDOS
2523 /* System's default file type was set to binary by _fmode in emacs.c. */ 2533 /* System's default file type was set to binary by _fmode in emacs.c. */
2524 ofd = creat (SDATA (encoded_newname), S_IREAD | S_IWRITE); 2534 ofd = emacs_open (SDATA (encoded_newname),
2525 #else /* not MSDOS */ 2535 O_WRONLY | O_TRUNC | O_CREAT
2526 ofd = creat (SDATA (encoded_newname), 0666); 2536 | (EQ (mustbenew, Qexcl) ? O_EXCL : 0),
2537 S_IREAD | S_IWRITE);
2538 #else /* not MSDOS */
2539 ofd = emacs_open (SDATA (encoded_newname),
2540 O_WRONLY | O_TRUNC | O_CREAT
2541 | (EQ (mustbenew, Qexcl) ? O_EXCL : 0),
2542 0666);
2527 #endif /* not MSDOS */ 2543 #endif /* not MSDOS */
2528 #endif /* VMS */ 2544 #endif /* VMS */
2529 if (ofd < 0) 2545 if (ofd < 0)
2530 report_file_error ("Opening output file", Fcons (newname, Qnil)); 2546 report_file_error ("Opening output file", Fcons (newname, Qnil));
2531 2547
2751 else 2767 else
2752 #endif 2768 #endif
2753 Fcopy_file (file, newname, 2769 Fcopy_file (file, newname,
2754 /* We have already prompted if it was an integer, 2770 /* We have already prompted if it was an integer,
2755 so don't have copy-file prompt again. */ 2771 so don't have copy-file prompt again. */
2756 NILP (ok_if_already_exists) ? Qnil : Qt, Qt); 2772 NILP (ok_if_already_exists) ? Qnil : Qt,
2773 Qt, Qnil);
2757 Fdelete_file (file); 2774 Fdelete_file (file);
2758 } 2775 }
2759 else 2776 else
2760 #ifdef NO_ARG_ARRAY 2777 #ifdef NO_ARG_ARRAY
2761 { 2778 {