Today, Russell McManus <russell_mcmanus@...> wrote:
>
> While writing some code using run-program, I came upon the need for
> the following:
autobench uses a similar macro, so I have a few questions about your
code.
One, wouldn't it be better if the macro also bound
*default-pathname-defaults* to the new-dir? (My implementation assumes
that the user(me) will consistently use with-current-directory and so
skips the whole getcwd thing in favor of just chdir-ing back into
*d-p-defaults*)
> (defmacro with-current-directory ((new-dir) &body body)
> (let ((start (gensym)))
> `(let ((,start (sb-unix:posix-getcwd)))
> (unless (char= #\\ (aref ,start (1- (length ,start))))
> (setf ,start (concatenate 'string ,start "/")))
Two, what's with that #\\ check? In which cases does getcwd return the
\ character as the last element?
> (setf ,start (parse-namestring ,start))
> (unwind-protect
> (progn
> (sb-posix:chdir ,new-dir)
> ,@body)
> (sb-posix:chdir ,start)))))
Cheers,
--
Andreas Fuchs, <asf@...>, asf@..., antifuchs
|