1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
--- skk.el.orig 2003-07-07 18:05:40.000000000 +0900
+++ skk.el 2003-07-07 18:05:10.000000000 +0900
@@ -3888,35 +3888,94 @@
(defun skk-make-temp-jisyo ()
;; SKK $B8D?M<-=qJ]B8$N$?$a$N:n6HMQ$N%U%!%$%k$r:n$j!"%U%!%$%k$N%b!<%I$r(B
;; skk-jisyo $B$N$b$N$HF1$8$K@_Dj$9$k!#:n$C$?:n6HMQ%U%!%$%k$NL>A0$rJV$9!#(B
- (let ((tempo-name (skk-make-temp-file "skkdic")))
- (skk-create-file tempo-name)
- ;; temporary file $B$K(B remote file $B$r;XDj$9$k$3$H$J$IM-$jF@$J$$!)(B
- ;;(if (or
- ;; ;; XEmacs has efs.el
- ;; (eq skk-emacs-type 'xemacs)
- ;; ;; ange-ftp.el does not have a wrapper to set-file-modes.
- ;; (not (and (featurep 'ange-ftp) (boundp 'ange-ftp-name-format)
- ;; (string-match (car ange-ftp-name-format) tempo-name))))
- (set-file-modes tempo-name (file-modes skk-jisyo))
- ;;)
- tempo-name))
-
-(defun skk-make-temp-file (prefix)
- (let ((dir
- (cond ((skk-file-exists-and-writable-p temporary-file-directory)
- (expand-file-name temporary-file-directory))
- ((and (memq system-type '(ms-dos windows-nt))
- (skk-file-exists-and-writable-p "a:/temp"))
- ;; NEC PC-9800 series.
- "a:/temp")
- (t (or (file-exists-p "~/tmp") (make-directory "~/tmp"))
- (or (file-writable-p "~/tmp") (set-file-modes "~/tmp" 1023))
- "~/tmp"))))
- (make-temp-name
- (concat dir
- (if (memq (skk-str-ref dir (1- (length dir))) '(?/ ?\\))
- "" "/")
- prefix))))
+ (skk-make-temp-file "skk"))
+
+;;; This function is written by Tatsuya Kinoshita <tats@vega.ocn.ne.jp>.
+;;; It is derived from APEL 10.5, apel/poe.el (make-temp-file).
+;;; APEL is copyrighted under the GNU GPL version 2 or later.
+;;; The make-temp-file function is written by Shuhei KOBAYASHI
+;;; <shuhei@aqua.ocn.ne.jp> and Yuuichi Teranishi <teranisi@gohome.org>.
+(defun skk-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)))
+ (unwind-protect
+ (let ((prefix (expand-file-name prefix
+ (if (boundp 'temporary-file-directory)
+ temporary-file-directory
+ (or (getenv "TMPDIR")
+ (getenv "TEMP")
+ (getenv "TMP")
+ "/tmp")))))
+ ;; 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 448)
+ (if dir-flag
+ ;; Create a new empty directory.
+ (let (dir)
+ (while (condition-case ()
+ (progn
+ (setq dir (make-temp-name prefix))
+ (if suffix
+ (setq dir (concat dir suffix)))
+ ;; `make-directory' returns nil for success,
+ ;; otherwise signals an error.
+ (make-directory dir))
+ ;; the dir was somehow created by someone else
+ ;; between `make-temp-name' and `make-directory',
+ ;; let's try again.
+ (file-already-exists t)))
+ dir)
+ ;; Create a new empty file.
+ (let (tempdir tempfile)
+ (unwind-protect
+ (let (file)
+ ;; First, create a temporary directory.
+ (while (condition-case ()
+ (progn
+ (setq tempdir (make-temp-name
+ (concat
+ (file-name-directory prefix)
+ "DIR")))
+ ;; return nil or signal an error.
+ (make-directory tempdir))
+ ;; let's try again.
+ (file-already-exists t)))
+ ;; Second, create a temporary file in the tempdir.
+ ;; There *is* a race condition between `make-temp-name'
+ ;; and `write-region', but we don't care it since we are
+ ;; in a private directory now.
+ (setq tempfile (make-temp-name (concat tempdir "/EMU")))
+ (write-region "" nil tempfile nil 'silent)
+ ;; Finally, make a hard-link from the tempfile.
+ (while (condition-case ()
+ (progn
+ (setq file (make-temp-name prefix))
+ (if suffix
+ (setq file (concat file suffix)))
+ ;; return nil or signal an error.
+ (add-name-to-file tempfile file))
+ ;; let's try again.
+ (file-already-exists t)))
+ file)
+ ;; Cleanup the tempfile.
+ (and tempfile
+ (file-exists-p tempfile)
+ (delete-file tempfile))
+ ;; Cleanup the tempdir.
+ (and tempdir
+ (file-directory-p tempdir)
+ (delete-directory tempdir))))))
+ ;; Reset the umask.
+ (set-default-file-modes umask))))
(defun skk-make-new-jisyo (tempo-file)
;; TEMPO-FILE $B$r?75,$N(B skk-jisyo $B$K$9$k!#(Bskk-backup-jisyo $B$,(B non-nil $B$@$C$?(B
|