]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 4374 / 2: Add make-tmpfile procedure
authorMasamichi Hosoda <trueroad@trueroad.jp>
Sat, 16 May 2015 11:46:55 +0000 (20:46 +0900)
committerMasamichi Hosoda <trueroad@trueroad.jp>
Sat, 16 May 2015 11:56:31 +0000 (20:56 +0900)
Procedure "make-tmpfile" is
to create a unique temporary file using "mkstemp!".

scm/backend-library.scm

index 3a70c5c07d081c2efaae7ed951685249a93b0be8..ffb96852687c5690643aaa85f570879a52db8ba0 100644 (file)
                     #:pixmap-format (ly:get-option 'pixmap-format))
     (ly:progress "\n")))
 
+(define-public (make-tmpfile)
+  (let* ((tmpl
+          (string-append (cond
+                          ;; MINGW hack: TMP / TEMP may include
+                          ;; unusable characters (Unicode etc.).
+                          ((eq? PLATFORM 'windows) "./tmp-")
+                          ;; Cygwin can handle any characters
+                          ;; including Unicode.
+                          ((eq? PLATFORM 'cygwin) (string-append
+                                                   (or (getenv "TMP")
+                                                       (getenv "TEMP"))
+                                                   "/"))
+                          ;; Other platforms (POSIX platforms)
+                          ;; use TMPDIR or /tmp.
+                          (else (string-append
+                                 (or (getenv "TMPDIR")
+                                     "/tmp")
+                                 "/")))
+                          "lilypond-XXXXXX"))
+         (port-tmp (mkstemp! tmpl)))
+    (if (eq? PLATFORM 'windows)
+        ;; MINGW hack: MinGW Guile's mkstemp! is broken.
+        ;; It creates a file by the text mode instead of the binary mode.
+        ;; (It is fixed from Guile 2.0.9.)
+        ;; We need the binary mode for embeddings CFFs.
+        ;; So, we re-open the same file by the binary mode.
+        (let* ((filename (port-filename port-tmp))
+               (port (open-file filename "r+b")))
+          (close port-tmp)
+          port)
+        ;; Cygwin and other platforms:
+        ;; Pass through the return value of mkstemp!
+        port-tmp)))
+
 (define-public (postprocess-output paper-book module filename formats)
   (let* ((completed (completize-formats formats))
          (base (dir-basename filename ".ps" ".eps"))