changeset 25631:0987f52a0674

(make-temp-file): New function.
author Richard M. Stallman <rms@gnu.org>
date Sat, 11 Sep 1999 01:08:15 +0000
parents 4feb8ce584a5
children 82ebdf9967da
files lisp/subr.el
diffstat 1 files changed, 24 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/subr.el	Fri Sep 10 18:08:06 1999 +0000
+++ b/lisp/subr.el	Sat Sep 11 01:08:15 1999 +0000
@@ -1302,4 +1302,28 @@
       (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