how to get filesystem usage in c

hi, everyone
Can anybody tell me how to get free blocks and total blocks of filesystem in c.
I am working on a hp-unix
Thanks in advance.

See the manpages for statvfs() and fststvfs()

shamrock ,thank you! your answer is very useful.
Now i want to get filesystems mounted on my hp-ux in c, how can i get it?

The most straighforward way is to use the output of the df command.

df -n

gives output like this

/cgndev01              (/dev/vgdcgn01/lv01    ) :     vxfs
/cgndev02              (/dev/vgdcgn02/lv02    ) :     vxfs
/cgndev80              (/dev/vgdcgn80/lv80    ) :     vxfs
/dev_envs              (/dev/vgdenvs/lv01     ) :     vxfs
/home                  (/dev/vg00/lvol4       ) :     vxfs
/opt                   (/dev/vg00/lvol5       ) :     vxfs
/psw                   (/dev/vgdpsw/lv01      ) :     vxfs
/reorg                 (/dev/vgdreorg/lv01    ) :     vxfs
/tmp                   (/dev/vg00/lvol6       ) :     vxfs
/usr                   (/dev/vg00/lvol7       ) :     vxfs
/var                   (/dev/vg00/lvol8       ) :     vxfs
/stand                 (/dev/vg00/lvol1       ) :      hfs
/                        (/dev/vg00/lvol3       ) :     vxfs

Call popen (see the man page on how to use it) with "/usr/bin/df -n" as the command argument. You can generate a list of mounted filesystems that way. Column #1 is the filesystem.

See the manpage of the getmntent() system call.

shamrock ,thank you very much!
The getmntent() system call is exactly what i want.

jim, thank you all the same for your concern!
I know how to get filesystem mounted and its usage by using shell command.
but i just want to program in c so as to inform sysadmin when a filesystem usage reach certain limit.

All in one.

Why can't you try opening proc file system and read ?

getmntent is not listed as POSIX. Shamrock must have seen that it was avaialble for you system.

Sivaswami, there is no /proc filesystem on hp-ux.

jim, i am working on hp-ux.
I have tried the getmntent system call.It works!
Let's close this thread.
Thanks again!