aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/files.el37
1 files changed, 37 insertions, 0 deletions
diff --git a/lisp/files.el b/lisp/files.el
index 3706ad54edf..89ff4da76a6 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -861,6 +861,43 @@ it means chase no more than that many links and then stop."
861 (setq count (1+ count)))) 861 (setq count (1+ count))))
862 newname)) 862 newname))
863 863
864(defun make-temp-file (prefix &optional dir-flag suffix)
865 "Create a temporary file.
866The returned file name (created by appending some random characters at the end
867of PREFIX, and expanding against `temporary-file-directory' if necessary),
868is guaranteed to point to a newly created empty file.
869You can then use `write-region' to write new data into the file.
870
871If DIR-FLAG is non-nil, create a new empty directory instead of a file.
872
873If SUFFIX is non-nil, add that at the end of the file name."
874 (let ((umask (default-file-modes))
875 file)
876 (unwind-protect
877 (progn
878 ;; Create temp files with strict access rights. It's easy to
879 ;; loosen them later, whereas it's impossible to close the
880 ;; time-window of loose permissions otherwise.
881 (set-default-file-modes ?\700)
882 (while (condition-case ()
883 (progn
884 (setq file
885 (make-temp-name
886 (expand-file-name prefix temporary-file-directory)))
887 (if suffix
888 (setq file (concat file suffix)))
889 (if dir-flag
890 (make-directory file)
891 (write-region "" nil file nil 'silent nil 'excl))
892 nil)
893 (file-already-exists t))
894 ;; the file was somehow created by someone else between
895 ;; `make-temp-name' and `write-region', let's try again.
896 nil)
897 file)
898 ;; Reset the umask.
899 (set-default-file-modes umask))))
900
864(defun recode-file-name (file coding new-coding &optional ok-if-already-exists) 901(defun recode-file-name (file coding new-coding &optional ok-if-already-exists)
865 "Change the encoding of FILE's name from CODING to NEW-CODING. 902 "Change the encoding of FILE's name from CODING to NEW-CODING.
866The value is a new name of FILE. 903The value is a new name of FILE.