Hi Elliot,
According to that section in docs It is not very clear (at least for a
newbie like me) how to perform the cast to my custom type.
Eventually I was able to get what I was after - thanks to the link below,
which by the way was dealing with the exactly same case.
https://groups.google.com/forum/m/#!topic/julia-users/V6v14Cg94ak
What was not clear to me but now it makes sense, is that the return type of
the ccall has to be a pointer of my custom type. I still don't understand
though why do I need to perform unsafe_load(passwd) after?
Anyway attaching the code below:
julia> type c_passwd
name::Ptr{Uint8}
passwd::Ptr{Uint8}
uid::Int32
gid::Int32
gecos::Ptr{Uint8}
dir::Ptr{Uint8}
shell::Ptr{Uint8}
end
julia> uid = int(stat("/Users/kuba/temp").uid)
501
julia> passwd = ccall( (:getpwuid, "libc"), Ptr{c_passwd}, (Ptr{Int32},),
uid)
Ptr{c_passwd} @0x00007f8418daa870
julia> cpwd = unsafe_load(passwd)
c_passwd(Ptr{Uint8} @0x00007f8418daa8c0,Ptr{Uint8}
@0x00007f8418daa8c5,501,20,Ptr{Uint8} @0x0000000000000000,Ptr{Uint8}
@0x00007f8418daa8ce,Ptr{Uint8} @0x00007f8418daa8cf)
julia> bytestring(cpwd.name)
"kuba"