Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Accesing struct! after routine! exec

From: nitsch-lists:netcologne at: 3-Jun-2003 3:54

Jaime Vargas wrote:
>Hello All. I've been having problems with the following script >when trying to access a subroutine in libc. I am using openbsd. > >Everything executes well but rebol crashes with a coredump >when I try to access the fields of the struct! after calling the >external function. > >REBOL[] >stdclib: %/usr/lib/libc.so.29.0 >clib: load/library stdclib > >c-string: func [ > "Returns a null terminated c-string of size strsize" > strsize [integer!] "The size of the string" > /fill blank [char!] "Character to fill the blanks" > /local str >][ > if none? fill [ blank: #"." ] > > ; fill the blancs > str: make string! strsize > loop strsize [ > insert str blank > ] > > ; insert null to terminate the c-string > poke str strsize #"^(null)" > > return str >] > >utsname: make struct! [ > sysname [string!] > nodename [string!] > release [string!] > version [string!] > machine [string!] >] reduce [ > c-string 256 > c-string 256 > c-string 256 > c-string 256 > c-string 256 > c-string 256 >] > >uname: make routine! compose/deep [ > name [struct! [(first utsname)]] > return: [integer!] >] clib "_uname" > >uname utsname > >probe utsname > >Here are the c definitions: > >int uname (struct utsname *name ); >#define SYS_NMLN 256 > >struct utsname { > char
sysname[SYS_NMLN]; /* Name of this OS. */
> char
nodename[SYS_NMLN]; /* Name of this network node. */
> char
release[SYS_NMLN]; /* Release level. */
> char
version[SYS_NMLN]; /* Version level. */
> char
machine[SYS_NMLN]; /* Hardware type. */
>}; >
Trying to remember c, the rebol-definition means struct utsname { char * sysname; /* Name of this OS. */ char * nodename; /* Name of this network node. */ char * release; /* Release level. */ char * version; /* Version level. */ char * machine; /* Hardware type. */ }; which means a struct with pointers. while the c-defenition is a struct with char-arrays. if i am right, eventually this works: string: insert/dup "" " " 5 * SYS_NMLN ; make a filled string sysname: string nodename: skip string SYS_NMLN release: skip nodename SYS_NMLN ... and pass the string as argument. sysname: copy/part sysname find sysname #"^(null)" to get it back.
>Ideas anyone??? Thanks for your help, Jaime > >-- The best way to predict the future is to invent it -- Steve Jobs >
-Volker