[plt-scheme] ffi question and accessing errno

From: Marco Maggi (marco.maggi-ipsu at poste.it)
Date: Wed Mar 5 00:41:47 EST 2008


I am experimenting with the FFI with PLT 372 on GNU+Linux;
is it possible to access "errno"?

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...

(module unix mzscheme
  (require (all-except (lib "foreign.ss") ->)
  	   (lib "contract.ss"))


  (define-cstruct _passwd
    ([pw_name	_string]
     [pw_passwd	_string]
     [pw_uid	_uint]
     [pw_gid	_uint]
     [pw_gecos	_string]
     [pw_dir	_string]
     [pw_shell	_string]))

  (define getpwnam
    (get-ffi-obj "getpwnam" #f
		 (_cprocedure (list _string) _passwd)))

  (define (get-uid-of-user username)
    (passwd-pw_uid (getpwnam username)))

  (define (get-gid-of-user username)
    (passwd-pw_gid (getpwnam username)))

   [getpwnam		(-> string? any)]
;;   [passwd-pw_name	(-> passwd? string?)]
   [passwd-pw_name	(-> passwd? any)]
   [get-uid-of-user	(-> string? integer?)]
   [get-gid-of-user	(-> string? integer?)]))

(require unix)

(display (format "uid of ~A is ~A~% "
	   (passwd-pw_name (getpwnam "marco"))
	   (get-uid-of-user "marco")))

Marco Maggi

"Now feel the funk blast!"
Rage Against the Machine - "Calm like a bomb"

Posted on the users mailing list.