aboutsummaryrefslogtreecommitdiff
path: root/module/hnh/util/io.scm
diff options
context:
space:
mode:
Diffstat (limited to 'module/hnh/util/io.scm')
-rw-r--r--module/hnh/util/io.scm12
1 files changed, 11 insertions, 1 deletions
diff --git a/module/hnh/util/io.scm b/module/hnh/util/io.scm
index d638ebb4..d73a1de8 100644
--- a/module/hnh/util/io.scm
+++ b/module/hnh/util/io.scm
@@ -4,7 +4,8 @@
:export (open-input-port
open-output-port
read-lines
- with-atomic-output-to-file))
+ with-atomic-output-to-file
+ call-with-tmpfile))
(define (open-input-port str)
(if (string=? "-" str)
@@ -62,3 +63,12 @@
;; counted on, since anything with an unspecified return
;; value might as well return #f)
#f))))
+
+(define* (call-with-tmpfile proc key: (tmpl "/tmp/file-XXXXXXX"))
+ (let* ((filename (string-copy tmpl))
+ (port (mkstemp! filename)))
+ (with-continuation-barrier
+ (lambda ()
+ (begin1
+ (proc port filename)
+ (close-port port))))))