[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: questions regarding ffi



Dan Stanger <dxs@evolving.com> asks:

> (def-c-struct utsname
>   (sysname (c-array char #._SYS_NMLN))
>   (nodename (c-array char #._SYS_NMLN))
>   (release (c-array char #._SYS_NMLN))
>   (version (c-array char #._SYS_NMLN))
>   (machine (c-array char #._SYS_NMLN))
> )

> is there a way to declare utsname so that the structure members are strings
> rather than these arrays.  simply declareing as follows
> (def-c-struct utsname
>   (sysname (c-string #._SYS_NMLN)) ...
> gives me a error as c-string is a pointer to a string, not a actual string.

If you use the simple foreign type `character' instead of `char', you
will get simple arrays of characters, i.e. strings. But you will still
have to remove everything after the first #\Null character:
    (subseq string 0 (or (position #\Null string) (length string)))


                    Bruno Haible
                    haible@ma2s2.mathematik.uni-karlsruhe.de