Commit cdd9f643 authored by Richard M. Stallman's avatar Richard M. Stallman
Browse files

(make-temp-file): New function.

parent e596094d
......@@ -1302,4 +1302,28 @@ Return the modified alist."
(setq tail (cdr tail)))
(defun make-temp-file (prefix &optional dir-flag)
"Create a temporary file.
The returned file name (created by appending some random characters at the end
of PREFIX, and expanding against `temporary-file-directory' if necessary,
is guaranteed to point to a newly created empty file.
You can then use `write-region' to write new data into the file.
If DIR-FLAG is non-nil, create a new empty directory instead of a file."
(let (file)
(while (condition-case ()
(setq file
(expand-file-name prefix temporary-file-directory)))
(if dir-flag
(make-directory file)
(write-region "" nil file nil 'silent nil 'excl))
(file-already-exists t))
;; the file was somehow created by someone else between
;; `make-temp-name' and `write-region', let's try again.
;;; subr.el ends here
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment