comparison lisp/files.el @ 66309:3bea1353ceed

(make-temp-file): Moved from subr.el.
author Richard M. Stallman <rms@gnu.org>
date Sat, 22 Oct 2005 15:34:37 +0000
parents 4d1085b02d64
children fda96ff4c7e5
comparison
equal deleted inserted replaced
66308:cd1db33ab0d9 66309:3bea1353ceed
858 ;; Now find the parent of that dir. 858 ;; Now find the parent of that dir.
859 (setq newname (file-name-directory newname))) 859 (setq newname (file-name-directory newname)))
860 (setq newname (expand-file-name tem (file-name-directory newname))) 860 (setq newname (expand-file-name tem (file-name-directory newname)))
861 (setq count (1+ count)))) 861 (setq count (1+ count))))
862 newname)) 862 newname))
863
864 (defun make-temp-file (prefix &optional dir-flag suffix)
865 "Create a temporary file.
866 The returned file name (created by appending some random characters at the end
867 of PREFIX, and expanding against `temporary-file-directory' if necessary),
868 is guaranteed to point to a newly created empty file.
869 You can then use `write-region' to write new data into the file.
870
871 If DIR-FLAG is non-nil, create a new empty directory instead of a file.
872
873 If 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))))
863 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.
866 The value is a new name of FILE. 903 The value is a new name of FILE.
867 Signals a `file-already-exists' error if a file of the new name 904 Signals a `file-already-exists' error if a file of the new name