aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-07-21 15:58:21 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2022-07-21 16:01:16 +0200
commit322a9e0620931e39f6727c55d7c970044336c26f (patch)
tree564823809b5e3a72bf609c5ed5df7a7818b623f5
parentCleanup in fetch-liu-map script. (diff)
downloadcalp-322a9e0620931e39f6727c55d7c970044336c26f.tar.gz
calp-322a9e0620931e39f6727c55d7c970044336c26f.tar.xz
Add call-with-tmpfile.
-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))))))