From: Andrea Fazzi Date: 2009-08-09T17:54:28+09:00 Subject: Re: FFI, getutxent question Daniel Berger wrote: > Info.getstuff # Null Pointer object Your script runs smoothly on my system (Ubuntu Linux) returning a proper NativePointer object. It seems that the issue is related to your environment rather then FFI. > However, the call to getutxent() returns a NULL pointer. I'm guessing I > have to tell it what kind of pointer to return, but I wasn't sure how to > do that. How do I do that? You don't. Once you get a proper pointer object you'll use it to instantiate the Utmpx class: Utmpx.new(getutxent) The Utmpx class will be a subclass of FFI::Struct that mirrors the layout of the C counterpart. Moreover, as I can see from libc reference manual[1], utmpx has nested structs within. The good news is that Ruby-FFI has support for nested structs. The bad one is that you have to define all the nested structs by hand: class Pid < FFI::Struct layout ... end ... class Utmpx < FFI::Struct layout :ut_type, :short, :ut_pid, Pid ... end Regards, Andrea -- Posted via http://www.ruby-forum.com/.