/* File IO for GNU Emacs.
Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995, 1996,
1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
- 2005 Free Software Foundation, Inc.
+ 2005, 2006 Free Software Foundation, Inc.
This file is part of GNU Emacs.
{
*o++ = *p++;
}
- else if (IS_DIRECTORY_SEP (p[0])
- && p[1] == '.'
+ else if (p[1] == '.'
&& (IS_DIRECTORY_SEP (p[2])
|| p[2] == 0))
{
*o++ = *p;
p += 2;
}
- else if (IS_DIRECTORY_SEP (p[0]) && p[1] == '.' && p[2] == '.'
+ else if (p[1] == '.' && p[2] == '.'
/* `/../' is the "superroot" on certain file systems.
Turned off on DOS_NT systems because they have no
"superroot" and because this causes us to produce
++o;
p += 3;
}
- else if (p > target
- && IS_DIRECTORY_SEP (p[0]) && IS_DIRECTORY_SEP (p[1]))
- {
- /* Collapse multiple `/' in a row. */
- *o++ = *p++;
- while (IS_DIRECTORY_SEP (*p))
- ++p;
- }
+ else if (p > target && IS_DIRECTORY_SEP (p[1]))
+ /* Collapse multiple `/' in a row. */
+ p++;
else
{
*o++ = *p++;
return;
}
-DEFUN ("copy-file", Fcopy_file, Scopy_file, 2, 6,
+DEFUN ("copy-file", Fcopy_file, Scopy_file, 2, 5,
"fCopy file: \nGCopy %s to file: \np\nP",
doc: /* Copy FILE to NEWNAME. Both args must be strings.
If NEWNAME names a directory, copy FILE there.
-Signals a `file-already-exists' error if file NEWNAME already exists,
-unless a third argument OK-IF-ALREADY-EXISTS is supplied and non-nil.
-A number as third arg means request confirmation if NEWNAME already exists.
-This is what happens in interactive use with M-x.
-Always sets the file modes of the output file to match the input file.
+
+This function always sets the file modes of the output file to match
+the input file.
+
+The optional third argument OK-IF-ALREADY-EXISTS specifies what to do
+if file NEWNAME already exists. If OK-IF-ALREADY-EXISTS is nil, we
+signal a `file-already-exists' error without overwriting. If
+OK-IF-ALREADY-EXISTS is a number, we request confirmation from the user
+about overwriting; this is what happens in interactive use with M-x.
+Any other value for OK-IF-ALREADY-EXISTS means to overwrite the
+existing file.
Fourth arg KEEP-TIME non-nil means give the output file the same
last-modified time as the old one. (This works on only some systems.)
A prefix arg makes KEEP-TIME non-nil.
-The optional fifth arg MUSTBENEW, if non-nil, insists on a check
-for an existing file with the same name. If MUSTBENEW is `excl',
-that means to get an error if the file already exists; never overwrite.
-If MUSTBENEW is neither nil nor `excl', that means ask for
-confirmation before overwriting, but do go ahead and overwrite the file
-if the user confirms.
-
If PRESERVE-UID-GID is non-nil, we try to transfer the
uid and gid of FILE to NEWNAME. */)
- (file, newname, ok_if_already_exists, keep_time, mustbenew, preserve_uid_gid)
- Lisp_Object file, newname, ok_if_already_exists, keep_time, mustbenew;
+ (file, newname, ok_if_already_exists, keep_time, preserve_uid_gid)
+ Lisp_Object file, newname, ok_if_already_exists, keep_time;
Lisp_Object preserve_uid_gid;
{
int ifd, ofd, n;
CHECK_STRING (file);
CHECK_STRING (newname);
- if (!NILP (mustbenew) && !EQ (mustbenew, Qexcl))
- barf_or_query_if_file_exists (newname, "overwrite", 1, 0, 1);
-
if (!NILP (Ffile_directory_p (newname)))
newname = Fexpand_file_name (Ffile_name_nondirectory (file), newname);
else
/* System's default file type was set to binary by _fmode in emacs.c. */
ofd = emacs_open (SDATA (encoded_newname),
O_WRONLY | O_TRUNC | O_CREAT
- | (EQ (mustbenew, Qexcl) ? O_EXCL : 0),
+ | (NILP (ok_if_already_exists) ? O_EXCL : 0),
S_IREAD | S_IWRITE);
#else /* not MSDOS */
ofd = emacs_open (SDATA (encoded_newname),
O_WRONLY | O_TRUNC | O_CREAT
- | (EQ (mustbenew, Qexcl) ? O_EXCL : 0),
+ | (NILP (ok_if_already_exists) ? O_EXCL : 0),
0666);
#endif /* not MSDOS */
#endif /* VMS */
internal_delete_file (filename)
Lisp_Object filename;
{
- return NILP (internal_condition_case_1 (Fdelete_file, filename,
- Qt, internal_delete_file_1));
+ Lisp_Object tem;
+ tem = internal_condition_case_1 (Fdelete_file, filename,
+ Qt, internal_delete_file_1);
+ return NILP (tem);
}
\f
DEFUN ("rename-file", Frename_file, Srename_file, 2, 3,
/* We have already prompted if it was an integer,
so don't have copy-file prompt again. */
NILP (ok_if_already_exists) ? Qnil : Qt,
- Qt, Qnil, Qt);
+ Qt, Qt);
Fdelete_file (file);
}
}
DEFUN ("file-regular-p", Ffile_regular_p, Sfile_regular_p, 1, 1, 0,
- doc: /* Return t if file FILENAME is the name of a regular file.
-This is the sort of file that holds an ordinary stream of data bytes. */)
+ doc: /* Return t if FILENAME names a regular file.
+This is the sort of file that holds an ordinary stream of data bytes.
+Symbolic links to regular files count as regular files.
+See `file-symlink-p' to distinguish symlinks. */)
(filename)
Lisp_Object filename;
{
if we couldn't read the file. */
if (how_much < 0)
- {
- if (how_much == -1)
- error ("IO error reading %s: %s",
- SDATA (orig_filename), emacs_strerror (errno));
- else if (how_much == -2)
- error ("maximum buffer size exceeded");
- }
+ error ("IO error reading %s: %s",
+ SDATA (orig_filename), emacs_strerror (errno));
if (unprocessed > 0)
{
same_at_start_charpos, inserted_chars, 0);
/* Set `inserted' to the number of inserted characters. */
inserted = PT - temp;
+ /* Set point before the inserted characters. */
+ SET_PT_BOTH (temp, same_at_start);
unbind_to (this_count, Qnil);
#endif
Vdeactivate_mark = old_Vdeactivate_mark;
}
+ else
+ Vdeactivate_mark = Qt;
/* Make the text read part of the buffer. */
GAP_SIZE -= inserted;
val = raw_text_coding_system (val);
}
+ val = coding_inherit_eol_type (val, Qnil);
setup_coding_system (val, coding);
- if (! NILP (val)
- && VECTORP (CODING_ID_EOL_TYPE (coding->id)))
- val = AREF (CODING_ID_EOL_TYPE (coding->id), 0);
if (!STRINGP (start) && !NILP (current_buffer->selective_display))
coding->mode |= CODING_MODE_SELECTIVE_DISPLAY;
if (!NILP (start) && !STRINGP (start))
validate_region (&start, &end);
+ visit_file = Qnil;
GCPRO5 (start, filename, visit, visit_file, lockname);
filename = Fexpand_file_name (filename, Qnil);
Fsleep_for (make_number (1), Qnil);
}
+ SAFE_FREE ();
UNGCPRO;
return Qnil;
}
#endif
{
/* Must do it the hard (and slow) way. */
+ Lisp_Object tem;
GCPRO3 (all, comp, specdir);
count = SPECPDL_INDEX ();
record_unwind_protect (read_file_name_cleanup, current_buffer->directory);
current_buffer->directory = realdir;
for (comp = Qnil; CONSP (all); all = XCDR (all))
- if (!NILP (call1 (Vread_file_name_predicate, XCAR (all))))
- comp = Fcons (XCAR (all), comp);
+ {
+ tem = call1 (Vread_file_name_predicate, XCAR (all));
+ if (!NILP (tem))
+ comp = Fcons (XCAR (all), comp);
+ }
unbind_to (count, Qnil);
UNGCPRO;
}