> How do you make an ffi call to something like gethostname where the
> value of host is passed through a pointer and not returned?
>
Unfortunately, I still don't have an answer for that.
I did:
(defconstant *hostname* (make-string 15))
(def-call-out gethostname
(:arguments (hostname c-string)
(len int))
(:return-type int))
(gethostname *hostname* 15)
but that does not set the value of *hostname*.
myriam

Thanks but it's my understanding that def-c-var has to be the name of a c
variable. You can't make your own c-variables on the lisp side.
Since there is no such c variable, the code below does not link:
Undefined first referenced
symbol in file
_lisp__c_2Dhostname foreign.o
ld: fatal: Symbol referencing errors. No output written to lisp.run
> > Any ideas?
>
> defvar assigns a variable on the lisp heap, but the def-c-call-out gethostname
> needs
> a memory location on the extra c-heap, which is similar to a simple malloc
> there.
> does gethostname() strcpy the name to char* name or points to the string on
> the system heap?
>
> you would need something like this (untested) with a strcpy'ing gethostname.
>
> (ffi:def-c-call-out gethostname (:arguments (name c-string) (len
> size_t))(:return-type int))
> (ffi:def-c-var c-hostname (:type c-string) (:alloc :malloc-free))
> (if (zerop (linux:gethostname c-hostname 15) ; 0 on success
> (defvar hostname (ffi:deref c-hostname))) ; deref converts c-string
> to lisp type
>
> and link the glibc to clisp. don't know if the dynamic-ffi works here.
>
> I've written a short and simple summary and overview of various FFI's at
> http://xarch.tu-graz.ac.at/autocad/lisp/ffis.html
> --
> Reini Urban
> http://xarch.tu-graz.ac.at/home/rurban/
> http://tv.mur.at/ (kulturelles)
>
> _______________________________________________
> clisp-list mailing list
> clisp-list@...
> https://lists.sourceforge.net/lists/listinfo/clisp-list
--
myriam