summaryrefslogtreecommitdiff
path: root/lisp/subr.el
diff options
context:
space:
mode:
authorRichard M. Stallman <rms@gnu.org>1999-09-11 01:08:15 +0000
committerRichard M. Stallman <rms@gnu.org>1999-09-11 01:08:15 +0000
commitcdd9f64394f26d60c2c0ffe99719f8df9586ed80 (patch)
tree0f7ec636b39c9c3b5e418d4eefb92e4e0a4ac45a /lisp/subr.el
parente596094db5644575a362e7cbbd233d3f6432e81f (diff)
downloademacs-cdd9f64394f26d60c2c0ffe99719f8df9586ed80.tar.gz
(make-temp-file): New function.
Diffstat (limited to 'lisp/subr.el')
-rw-r--r--lisp/subr.el24
1 files changed, 24 insertions, 0 deletions
diff --git a/lisp/subr.el b/lisp/subr.el
index 7f145861ab3..8ade8bc85de 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -1302,4 +1302,28 @@ Return the modified alist."
(setq tail (cdr tail)))
alist))
+(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 ()
+ (progn
+ (setq file
+ (make-temp-name
+ (expand-file-name prefix temporary-file-directory)))
+ (if dir-flag
+ (make-directory file)
+ (write-region "" nil file nil 'silent nil 'excl))
+ nil)
+ (file-already-exists t))
+ ;; the file was somehow created by someone else between
+ ;; `make-temp-name' and `write-region', let's try again.
+ nil)
+ file))
+
;;; subr.el ends here