emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] Changes to emacs/lisp/files.el


From: Richard M . Stallman
Subject: [Emacs-diffs] Changes to emacs/lisp/files.el
Date: Sat, 22 Oct 2005 11:34:38 -0400

Index: emacs/lisp/files.el
diff -c emacs/lisp/files.el:1.790 emacs/lisp/files.el:1.791
*** emacs/lisp/files.el:1.790   Sun Sep 18 12:25:02 2005
--- emacs/lisp/files.el Sat Oct 22 15:34:37 2005
***************
*** 861,866 ****
--- 861,903 ----
        (setq count (1+ count))))
      newname))
  
+ (defun make-temp-file (prefix &optional dir-flag suffix)
+   "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.
+ 
+ If SUFFIX is non-nil, add that at the end of the file name."
+   (let ((umask (default-file-modes))
+       file)
+     (unwind-protect
+       (progn
+         ;; Create temp files with strict access rights.  It's easy to
+         ;; loosen them later, whereas it's impossible to close the
+         ;; time-window of loose permissions otherwise.
+         (set-default-file-modes ?\700)
+         (while (condition-case ()
+                    (progn
+                      (setq file
+                            (make-temp-name
+                             (expand-file-name prefix 
temporary-file-directory)))
+                      (if suffix
+                          (setq file (concat file suffix)))
+                      (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)
+       ;; Reset the umask.
+       (set-default-file-modes umask))))
+ 
  (defun recode-file-name (file coding new-coding &optional 
ok-if-already-exists)
    "Change the encoding of FILE's name from CODING to NEW-CODING.
  The value is a new name of FILE.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]