Re: broken structure??

2001-02-22 Thread Benjamin Scott
On Thu, 22 Feb 2001, Kevin D. Clark wrote: > Never place any code that has side-effects in an assert() statement. Doh! I knew that, too. Hell, I even considered mentioning it! Talk about missing the forest for the trees. Or, in this case, missing the tree I'm standing in front of for the

Re: broken structure??

2001-02-22 Thread Derek Martin
Today, Tony Lambiris gleaned this insight: > 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 = m

Re: broken structure??

2001-02-22 Thread Kevin D. Clark
[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

Re: broken structure??

2001-02-22 Thread Tony Lambiris
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

Re: broken structure??

2001-02-22 Thread Benjamin Scott
On Thu, 22 Feb 2001, John Abreau wrote: >> system_os = malloc(strlen(host_uname->sysname)); >> system_os = (host_uname->sysname); > > In both cases, you're malloc'ing one byte too little. Actually, in both cases, the OP is malloc'ing way too many bytes. Any amount is too many, you see. The O

Re: broken structure??

2001-02-22 Thread Benjamin Scott
On Thu, 22 Feb 2001, Tony Lambiris wrote: > when I set a pointer to the structure, and say, get the OS version: > > struct utsname *host_uname; Are you allocating a memory buffer and pointing host_uname to it before invoking uname: struct utsname buf; uname(&buf); > os_versio

Re: broken structure??

2001-02-22 Thread Tony Lambiris
yeah, i didnt take into account the NULL char see what happens when people make me get up before 10am :) John Abreau wrote: > On Thu, 22 Feb 2001, Tony Lambiris wrote: > > > struct utsname *host_uname; > > > > os_version = malloc(strlen(host_uname->release)); > > os_version = (host_un

Re: broken structure??

2001-02-22 Thread Kevin D. Clark
[EMAIL PROTECTED] writes: > when I set a pointer to the structure, and say, get the OS version: What do you mean by "set a pointer"? Are you actually allocating a "struct utsname" or merely a pointer to one? > struct utsname *host_uname; Only a pointer? Don't do that! You must allocate an

Re: broken structure??

2001-02-22 Thread John Abreau
On Thu, 22 Feb 2001, Tony Lambiris wrote: > struct utsname *host_uname; > > os_version = malloc(strlen(host_uname->release)); > os_version = (host_uname->release); > > it gives me 2.4.1, no problem... but when I try to get the OS name, > > system_os = malloc(strlen(host_uname->sysname)); > sys

broken structure??

2001-02-22 Thread Tony Lambiris
i highly doubt the structure is broken, but its not working for me... in sys/utsname.h (man 2 uname), the structure utsname is used to grab info about the system, like OS name, OS version, architechture, etc when I set a pointer to the structure, and say, get the OS version: struct utsname