Code: Select all
char hostname[128];
gethostname(hostname, sizeof hostname);
> gethostname<FEFC95F0>
> (set 'hostname nil)
> (gethostname hostname)
0
How to handle to the sizeof part?
Code: Select all
char hostname[128];
gethostname(hostname, sizeof hostname);
Code: Select all
(set 'hostname (dup "\000" 64))
(set 'lpNum (pack "lu" (length str)))
(gethostname str lpNum)
(trim str)
Code: Select all
gethostname(char *name, size_t namelen);
Code: Select all
(import "libc.dylib" "gethostname") ; import the function
(set 'host (dup "\000" 64)) ; reserve enough space
(gethostname host 64) ; get the name into variable host
(get-string host) => "officemacmini.local" ; cut of trailing 0's