summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2022-06-22 18:21:51 +0530
committerArun Isaac2022-06-22 18:21:51 +0530
commit32d5e62a222fc1c542758016325839cdc705cd28 (patch)
tree6fb9c3b76ae1bb3b6687fddafd76772a5f896756
parent93881d86a1f660ffdb6c477f65acf99248dd8113 (diff)
downloadtissue-32d5e62a222fc1c542758016325839cdc705cd28.tar.gz
tissue-32d5e62a222fc1c542758016325839cdc705cd28.tar.lz
tissue-32d5e62a222fc1c542758016325839cdc705cd28.zip
utils: Add call-with-current-directory utility function.
* tissue/utils.scm (call-with-current-directory): New public function.
-rw-r--r--tissue/utils.scm11
1 files changed, 10 insertions, 1 deletions
diff --git a/tissue/utils.scm b/tissue/utils.scm
index 6832fb8..156d333 100644
--- a/tissue/utils.scm
+++ b/tissue/utils.scm
@@ -20,10 +20,19 @@
#:use-module (rnrs io ports)
#:use-module (srfi srfi-26)
#:use-module (ice-9 popen)
- #:export (call-with-input-pipe
+ #:export (call-with-current-directory
+ call-with-input-pipe
get-line-dos-or-unix
memoize-thunk))
+(define (call-with-current-directory curdir thunk)
+ "Call THUNK with current directory set to CURDIR. Restore current
+directory after THUNK returns."
+ (let ((original-current-directory (getcwd)))
+ (dynamic-wind (cut chdir curdir)
+ thunk
+ (cut chdir original-current-directory))))
+
(define (call-with-input-pipe proc program . args)
"Execute PROGRAM ARGS ... in a subprocess with a pipe to it. Call
PROC with an input port to that pipe. Close the pipe once PROC exits,