[plt-scheme] foreign.ss dll path

From: Yoav Goldberg (yoav.goldberg at gmail.com)
Date: Sun Oct 16 14:54:22 EDT 2005

This works! Great!

Just a minor change though - for windows* users: the chdir and getcwd
functions are actually named "_chdir" "_getcwd", and are not in the
runtime, but in "msvcrt.dll", so:
(define rt (ffi-lib "msvcrt"))
(define chdir (get-ffi-obj "_chdir" rt (_fun _string -> _int)))
(define getcwd (get-ffi-obj "_getcwd" rt (_fun (_pointer = #f) (_int =
2048) -> _string)))

Thanks!

And now for a somewhat unrelated question: (how) can I define
top-level (actually module level) bindings from within a lambda
expression?

Yoav

[*] checked on win2000.


On 10/15/05, Daniel Pinto de Mello e Silva <daniel.silva at gmail.com> wrote:
> I think the Scheme current-directory parameter only changes the
> interpreter's view of what the current working directory is.  To
> change the working directory of the process and the libraries it
> loads, try the chdir function from the C runtime.  For Windows, look
> at
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt__chdir.2c_._wchdir.asp
>
> For UNIX (POSIX), look at
>
> http://www.umbi.umd.edu/cgi-bin/man-cgi?chdir+2
>
> You'll also want to import the getcwd function.  For Linux, you don't
> need to preallocate a buffer, but you do need to specify a maximum
> path length:
>
> http://linux.wku.edu/cgi-bin/man2html?getcwd+3
>
> Here's an example:
>
> > (require (lib "foreign.ss"))
> > (unsafe!)
> > (define rt (ffi-lib #f))
> > (define chdir (get-ffi-obj "chdir" rt (_fun _string -> _int)))
> > (define getcwd (get-ffi-obj "getcwd" rt (_fun (_pointer = #f) (_int = 1024) -> _string)))
> > (getcwd)
> "/home/dsilva"
> > (chdir "/tmp")
> 0
> > (getcwd)
> "/tmp"
> > (current-directory)
> #<path:/home/dsilva>
> > (define (with-c-dir path thunk)
>    (define cwd (getcwd))
>    (dynamic-wind (lambda () (chdir path))
>                  thunk
>                  (lambda () (chdir cwd))))
> > (with-c-dir "/usr"
>     (lambda () (printf "Do some work in ~a~n" (getcwd))))
> Do some work in /usr
> > (getcwd)
> "/tmp"
>
> Daniel


Posted on the users mailing list.