hi-

> 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;
>

you've allocated space only for the pointer. you need to allocat space for the
actualstat structure. stat() doesn't do this, so you'll have to do it on your
own. thats why you get the
seg fault.

try:
struct stat buf;
status = stat("...", &buf);
printf("...", buf.st_size);

that should work!

>         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.

rgds,
pm.

Reply via email to