DEFUN ("make-temp-name", Fmake_temp_name, Smake_temp_name, 1, 1, 0,
doc: /* Generate temporary file name (string) starting with PREFIX (a string).
-The Emacs process number forms part of the result,
-so there is no danger of generating a name being used by another process.
+The Emacs process number forms part of the result, so there is no
+danger of generating a name being used by another Emacs process
+\(so long as only a single host can access the containing directory...).
-In addition, this function makes an attempt to choose a name
-which has no existing file. To make this work,
-PREFIX should be an absolute file name.
+This function tries to choose a name that has no existing file.
+For this to work, PREFIX should be an absolute file name.
There is a race condition between calling `make-temp-name' and creating the
-file which opens all kinds of security holes. For that reason, you should
-probably use `make-temp-file' instead, except in three circumstances:
-
-* If you are creating the file in the user's home directory.
-* If you are creating a directory rather than an ordinary file.
-* If you are taking special precautions as `make-temp-file' does. */)
+file, which opens all kinds of security holes. For that reason, you should
+normally use `make-temp-file' instead. */)
(Lisp_Object prefix)
{
return make_temp_name (prefix, 0);
xsignal2 (Qfile_already_exists,
build_string ("File already exists"), absname);
GCPRO1 (absname);
- tem = format2 ("File %s already exists; %s anyway? ",
- absname, build_string (querystring));
+ AUTO_STRING (format, "File %s already exists; %s anyway? ");
+ tem = CALLN (Fformat, format, absname, build_string (querystring));
if (quick)
tem = call1 (intern ("y-or-n-p"), tem);
else
bool already_exists = false;
mode_t new_mask;
int ifd, ofd;
- int n;
- char buf[16 * 1024];
struct stat st;
#endif
record_unwind_protect_int (close_file_unwind, ofd);
+ off_t oldsize = 0, newsize = 0;
+
if (already_exists)
{
struct stat out_st;
if (st.st_dev == out_st.st_dev && st.st_ino == out_st.st_ino)
report_file_errno ("Input and output files are the same",
list2 (file, newname), 0);
- if (ftruncate (ofd, 0) != 0)
- report_file_error ("Truncating output file", newname);
+ if (S_ISREG (out_st.st_mode))
+ oldsize = out_st.st_size;
}
immediate_quit = 1;
QUIT;
- while ((n = emacs_read (ifd, buf, sizeof buf)) > 0)
- if (emacs_write_sig (ofd, buf, n) != n)
- report_file_error ("Write error", newname);
+ while (true)
+ {
+ char buf[MAX_ALLOCA];
+ ptrdiff_t n = emacs_read (ifd, buf, sizeof buf);
+ if (n < 0)
+ report_file_error ("Read error", file);
+ if (n == 0)
+ break;
+ if (emacs_write_sig (ofd, buf, n) != n)
+ report_file_error ("Write error", newname);
+ newsize += n;
+ }
+
+ /* Truncate any existing output file after writing the data. This
+ is more likely to work than truncation before writing, if the
+ file system is out of space or the user is over disk quota. */
+ if (newsize < oldsize && ftruncate (ofd, newsize) != 0)
+ report_file_error ("Truncating output file", newname);
+
immediate_quit = 0;
#ifndef MSDOS
DEFUN ("make-symbolic-link", Fmake_symbolic_link, Smake_symbolic_link, 2, 3,
"FMake symbolic link to file: \nGMake symbolic link to file %s: \np",
- doc: /* Make a symbolic link to FILENAME, named LINKNAME.
+ doc: /* Make a symbolic link to TARGET, named LINKNAME.
Both args must be strings.
Signals a `file-already-exists' error if a file LINKNAME already exists
unless optional third argument OK-IF-ALREADY-EXISTS is non-nil.
A number as third arg means request confirmation if LINKNAME already exists.
This happens for interactive use with M-x. */)
- (Lisp_Object filename, Lisp_Object linkname, Lisp_Object ok_if_already_exists)
+ (Lisp_Object target, Lisp_Object linkname, Lisp_Object ok_if_already_exists)
{
Lisp_Object handler;
- Lisp_Object encoded_filename, encoded_linkname;
+ Lisp_Object encoded_target, encoded_linkname;
struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
- GCPRO4 (filename, linkname, encoded_filename, encoded_linkname);
- encoded_filename = encoded_linkname = Qnil;
- CHECK_STRING (filename);
+ GCPRO4 (target, linkname, encoded_target, encoded_linkname);
+ encoded_target = encoded_linkname = Qnil;
+ CHECK_STRING (target);
CHECK_STRING (linkname);
/* If the link target has a ~, we must expand it to get
a truly valid file name. Otherwise, do not expand;
we want to permit links to relative file names. */
- if (SREF (filename, 0) == '~')
- filename = Fexpand_file_name (filename, Qnil);
+ if (SREF (target, 0) == '~')
+ target = Fexpand_file_name (target, Qnil);
if (!NILP (Ffile_directory_p (linkname)))
- linkname = Fexpand_file_name (Ffile_name_nondirectory (filename), linkname);
+ linkname = Fexpand_file_name (Ffile_name_nondirectory (target), linkname);
else
linkname = Fexpand_file_name (linkname, Qnil);
/* If the file name has special constructs in it,
call the corresponding file handler. */
- handler = Ffind_file_name_handler (filename, Qmake_symbolic_link);
+ handler = Ffind_file_name_handler (target, Qmake_symbolic_link);
if (!NILP (handler))
- RETURN_UNGCPRO (call4 (handler, Qmake_symbolic_link, filename,
+ RETURN_UNGCPRO (call4 (handler, Qmake_symbolic_link, target,
linkname, ok_if_already_exists));
/* If the new link name has special constructs in it,
call the corresponding file handler. */
handler = Ffind_file_name_handler (linkname, Qmake_symbolic_link);
if (!NILP (handler))
- RETURN_UNGCPRO (call4 (handler, Qmake_symbolic_link, filename,
+ RETURN_UNGCPRO (call4 (handler, Qmake_symbolic_link, target,
linkname, ok_if_already_exists));
- encoded_filename = ENCODE_FILE (filename);
+ encoded_target = ENCODE_FILE (target);
encoded_linkname = ENCODE_FILE (linkname);
if (NILP (ok_if_already_exists)
|| INTEGERP (ok_if_already_exists))
barf_or_query_if_file_exists (linkname, false, "make it a link",
INTEGERP (ok_if_already_exists), false);
- if (symlink (SSDATA (encoded_filename), SSDATA (encoded_linkname)) < 0)
+ if (symlink (SSDATA (encoded_target), SSDATA (encoded_linkname)) < 0)
{
/* If we didn't complain already, silently delete existing file. */
int symlink_errno;
if (errno == EEXIST)
{
unlink (SSDATA (encoded_linkname));
- if (symlink (SSDATA (encoded_filename), SSDATA (encoded_linkname))
+ if (symlink (SSDATA (encoded_target), SSDATA (encoded_linkname))
>= 0)
{
UNGCPRO;
}
symlink_errno = errno;
- report_file_errno ("Making symbolic link", list2 (filename, linkname),
+ report_file_errno ("Making symbolic link", list2 (target, linkname),
symlink_errno);
}
UNGCPRO;
{
/* If we have not yet decided a coding system, check
file-coding-system-alist. */
- Lisp_Object args[6];
-
- args[0] = Qinsert_file_contents, args[1] = orig_filename;
- args[2] = visit, args[3] = beg, args[4] = end, args[5] = replace;
- coding_system = Ffind_operation_coding_system (6, args);
+ coding_system = CALLN (Ffind_operation_coding_system,
+ Qinsert_file_contents, orig_filename,
+ visit, beg, end, replace);
if (CONSP (coding_system))
coding_system = XCAR (coding_system);
}
Vdeactivate_mark = old_Vdeactivate_mark;
}
else
- Vdeactivate_mark = Qt;
+ Fset (Qdeactivate_mark, Qt);
emacs_close (fd);
clear_unwind_protect (fd_index);
{
/* If the coding system is not yet decided, check
file-coding-system-alist. */
- Lisp_Object args[6];
-
- args[0] = Qinsert_file_contents, args[1] = orig_filename;
- args[2] = visit, args[3] = beg, args[4] = end, args[5] = Qnil;
- coding_system = Ffind_operation_coding_system (6, args);
+ coding_system = CALLN (Ffind_operation_coding_system,
+ Qinsert_file_contents, orig_filename,
+ visit, beg, end, Qnil);
if (CONSP (coding_system))
coding_system = XCAR (coding_system);
}
if (NILP (val))
{
/* Check file-coding-system-alist. */
- Lisp_Object args[7], coding_systems;
-
- args[0] = Qwrite_region; args[1] = start; args[2] = end;
- args[3] = filename; args[4] = append; args[5] = visit;
- args[6] = lockname;
- coding_systems = Ffind_operation_coding_system (7, args);
+ Lisp_Object coding_systems
+ = CALLN (Ffind_operation_coding_system, Qwrite_region, start, end,
+ filename, append, visit, lockname);
if (CONSP (coding_systems) && !NILP (XCDR (coding_systems)))
val = XCDR (coding_systems);
}
doc: /* Return t if (car A) is numerically less than (car B). */)
(Lisp_Object a, Lisp_Object b)
{
- Lisp_Object args[2];
- args[0] = Fcar (a);
- args[1] = Fcar (b);
- return Flss (2, args);
+ return CALLN (Flss, Fcar (a), Fcar (b));
}
/* Build the complete list of annotations appropriate for writing out
struct gcpro gcpro1, gcpro2;
Lisp_Object original_buffer;
int i;
- bool used_global = 0;
+ bool used_global = false;
XSETBUFFER (original_buffer, current_buffer);
struct buffer *given_buffer = current_buffer;
if (EQ (Qt, XCAR (p)) && !used_global)
{ /* Use the global value of the hook. */
- Lisp_Object arg[2];
- used_global = 1;
- arg[0] = Fdefault_value (Qwrite_region_annotate_functions);
- arg[1] = XCDR (p);
- p = Fappend (2, arg);
+ used_global = true;
+ p = CALLN (Fappend,
+ Fdefault_value (Qwrite_region_annotate_functions),
+ XCDR (p));
continue;
}
Vwrite_region_annotations_so_far = annotations;
ring_bell (XFRAME (selected_frame));
AUTO_STRING (format, "Auto-saving %s: %s");
- msg = Fformat (3, ((Lisp_Object [])
- {format, BVAR (current_buffer, name),
- Ferror_message_string (error_val)}));
+ msg = CALLN (Fformat, format, BVAR (current_buffer, name),
+ Ferror_message_string (error_val));
GCPRO1 (msg);
for (i = 0; i < 3; ++i)
DEFSYM (Qcopy_file, "copy-file");
DEFSYM (Qmake_directory_internal, "make-directory-internal");
DEFSYM (Qmake_directory, "make-directory");
- DEFSYM (Qdelete_directory_internal, "delete-directory-internal");
DEFSYM (Qdelete_file, "delete-file");
DEFSYM (Qrename_file, "rename-file");
DEFSYM (Qadd_name_to_file, "add-name-to-file");
If it is nil, `default-file-name-coding-system' (which see) is used.
On MS-Windows, the value of this variable is largely ignored if
-\`w32-unicode-filenames' (which see) is non-nil. Emacs on Windows
+`w32-unicode-filenames' (which see) is non-nil. Emacs on Windows
behaves as if file names were encoded in `utf-8'. */);
Vfile_name_coding_system = Qnil;
of file names regardless of the current language environment.
On MS-Windows, the value of this variable is largely ignored if
-\`w32-unicode-filenames' (which see) is non-nil. Emacs on Windows
+`w32-unicode-filenames' (which see) is non-nil. Emacs on Windows
behaves as if file names were encoded in `utf-8'. */);
Vdefault_file_name_coding_system = Qnil;