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);
> 
> well actually i get a warning when compiling.

Memory needs to be allocated for the stat structure.  stat() will not
allocate it for you.

Try:
....blah...
    struct stat buf;
    status = stat ("/root/.procmailrc", &buf);
....blah...

-Drago

-
    Drago
[EMAIL PROTECTED]

Reply via email to