On Sat, 22 Aug 1998, James wrote:

> i'm trying to use stat() to find out a file's size. So far i have :
> 
> /* Start Of Code */
> #include <sys/stat.h>
> #include <unistd.h>
> #include <stdio.h>
> 
> int main (void)
> {
>       int status;
>       struct stat *buf;
> 
>       status = stat ("/root/.procmailrc", buf);
>       /* don't ask why i'm using my procmailrc, it's the first file */
>       /* i thought of */
> 
>       return 0;
> }
> /* End Of Code */
> 
> that should have filled buf with info about that file, but how do i go about
> displaying the filesize? i know it's in buf->st_size, but that's of type
> off_t (what's that?) and printf() segfaults when i try to do
> 
>       printf ("File is %d bytes\n", buf->st_size);


try this:

struct stat buf;
status = stat("/root/.procmailrc", &buf);
printf ("File is %d bytes\n", buf.st_size);


stat doesnt' allocate its own memory, buf should point somewhere before you 
call it.

~Jesse Off

Reply via email to