[plt-scheme] ffi question and accessing errno

From: Eli Barzilay (eli at barzilay.org)
Date: Thu Mar 6 21:46:44 EST 2008

On Mar  5, Marco Maggi wrote:
> Ciao,
> 
> I am experimenting with the FFI with PLT 372 on GNU+Linux; is it
> possible to access "errno"?

Not really.  You can, like any other C variable, but the problem is
that you want the value grabbed right after the foreign call -- if you
do it later, then the value is likely to have changed so that it
doesn't help.  I'll need to extend the C part of the foreign interface
to make it available somehow (I still didn't figure out what's the
best way to address this problem).


> Can someone explain me why the following outputs "the uid
> of #f is 0"? Maybe it is a dumb error but I cannot figure
> it out...
> [...]
>   (define getpwnam
>     (get-ffi-obj "getpwnam" #f
> 		 (_cprocedure (list _string) _passwd)))

Your problem is here -- getpwnam() does not return a passwd struct, it
returns a pointer to one.  Change this to `_passwd-pointer' and things
should work.

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!


Posted on the users mailing list.