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.scm9
1 files changed, 9 insertions, 0 deletions
diff --git a/module/hnh/util/io.scm b/module/hnh/util/io.scm
index 6aed85ac..2fbad39f 100644
--- a/module/hnh/util/io.scm
+++ b/module/hnh/util/io.scm
@@ -5,6 +5,7 @@
open-output-port
read-lines
with-atomic-output-to-file
+ call-with-tmpfile
read-file))
(define (open-input-port str)
@@ -64,6 +65,14 @@
;; 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))))))
(define (read-file path)
(call-with-input-file path read-string))