aboutsummaryrefslogtreecommitdiff
path: root/src/util.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.lisp')
-rw-r--r--src/util.lisp14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/util.lisp b/src/util.lisp
index cd59fb7..3260de0 100644
--- a/src/util.lisp
+++ b/src/util.lisp
@@ -363,3 +363,17 @@ of this macro."
"Cancel the CLEANUP forms in all enclosing uses of UNWIND-PROTECT-IN-PARENT.
Should be called soon after fork(2) in child processes."
(signal 'in-child-process))
+
+
+;;;; Lisp data files
+
+(defmacro with-lisp-data-file ((data file) &body forms)
+ (with-gensyms (before)
+ `(let* ((,before (and (file-exists-p ,file) (read-file-string ,file)))
+ (,data (and ,before (plusp (length ,before))
+ (safe-read-from-string ,before))))
+ (unwind-protect-in-parent (progn ,@forms)
+ (with-open-file
+ (stream ,file :direction :output :if-exists :supersede)
+ (with-standard-io-syntax
+ (prin1 ,data stream)))))))