2009/8/2 Daniel Berger <>:
> [...]
> =A0 =A0 =A0class GroupStruct < FFI::Struct
> =A0 =A0 =A0 =A0 layout(
> [...]
> =A0 =A0 =A0 =A0 =A0 =A0:gr_mem, =A0 =A0
ointer
> =A0 =A0 =A0 =A0 )
> =A0 =A0 =A0end
>
> =A0 =A0 =A0attach_function :getgrgid, [:int],
ointer
>
> =A0 =A0 =A0def self.get_group(gid)
> =A0 =A0 =A0 =A0 GroupStruct.new(getgrgid(gid))
> =A0 =A0 =A0end
> [...]
> # How do I unravel the gr_mem struct member?
> struct =3D Sys::Admin.get_group(84)
> p struct[:gr_mem]
Hello,
the gr_mem member of the group structure is a NULL terminated array of
zero terminated strings, so you need to read all the string pointers
from the array until you encounter a null pointer and then read the
string data from each string pointer.
I would suggest the use of an auxiliary method, which could actually
be added to the FFI:

ointer class for convenience:
class FFI:

ointer
def read_string_array_to_null()
elements =3D []
psz =3D self.class.size
loc =3D self
until ((element =3D loc.read_pointer).null?)
elements << element.read_string_to_null
loc +=3D psz
end
elements
end
end
Using this method, you can unravel the mysterious pointer member as follows=
:
p struct[:gr_mem].read_string_array_to_null
I hope that helps,
Thomas
--=20
When C++ is your hammer, every problem looks like your thumb.