Subject: questions regarding ffi

From: [email-masked] (Dan Stanger)
Date: Mon, 19 Jun 1995 12:23:41 -0600

my declaration of utsname is
#.(defconstant _SYS_NMLN           32) ; Important: do not change this value !
(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))
)
and uname is
(def-c-call-out uname (:arguments (name (c-ptr utsname) :out :alloca))
(:return-type int))

when i call uname as follows i get
(multiple-value-setq (r s) (uname)
s has the value
#S(UTSNAME :SYSNAME #(65 73 88 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) :NODENAME #(109 97 100 97 109 101 0 48 51 56 48 48 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) :RELEASE #(50 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) :VERSION #(51 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) :MACHINE #(48 48 48 48 51 49 57 48 51 56 48 48 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0))

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.
thanks,
dan stanger

---

From: haible (Bruno Haible)
Date: Tue, 20 Jun 95 12:53:15 +0200

> 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
                    [email-masked]

---

From: haible (Bruno Haible)
Date: Thu, 22 Jun 95 16:19:03 +0200

> rather than these arrays.

In the next clisp version, you will be able to write

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

The conversions will then have exactly the desired behaviour.

                    Bruno Haible