[EMAIL PROTECTED] writes:
> okay, maybe i am missing the point totally with structures. here is my code, let
> me know whats wrong with it:
>
> struct utsname *host_uname;
>
> host_uname = (struct utsname *)malloc(sizeof(struct utsname));
> uname(host_uname);
>
> system_os = malloc(strlen(host_uname->sysname)+1);
> strncpy(system_os, (host_uname->sysname), sizeof(system_os));
sizeof(system_os) tells you the size of a character pointer on your
system. This is likely to be 4, and has nothing to do with the string
that the pointer is pointing to.
You might want to use strlen(host_uname->sysname)+1 instead.
Fact: sizeof(system_os) gets resolved at compile time, not at
runtime. sizeof is a C operator.
Fact: you can just use strcpy() here, since these fields are
guaranteed to be null-terminated anyways (POSIX says so).
--kevin
--
Kevin D. Clark (CetaceanNetworks.com!kclark) |
Cetacean Networks, Inc. | Give me a decent UNIX
Portsmouth, N.H. (USA) | and I can move the world
alumni.unh.edu!kdc (PGP Key Available) |
**********************************************************
To unsubscribe from this list, send mail to
[EMAIL PROTECTED] with the following text in the
*body* (*not* the subject line) of the letter:
unsubscribe gnhlug
**********************************************************