getting 'df' info from inside a program?

Jay A. Konigsberg jak at sactoh0.UUCP
Thu Jun 28 11:08:55 AEST 1990


In article <797 at massey.ac.nz> GEustace at massey.ac.nz (Glen Eustace) writes:
>We are trying to write some code that will check whether a file will
>fit on a given file system prior to copying it.  It would be great if
>the information given in a 'df' were available with some system call.
>Does anyone know whether there is one and if so how one uses it.
>
This looks like a job for the stat() system call. (Sys V)

#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>

main()
{
struct stat *buf;

buf = (struct stat *)malloc(sizeof(struct stat)); /* error check removed */

if ( stat("filename", buf) == -1 )
    {
    fprintf("stat: error=%d\n", errno);
    exit(2);
    }
else
    {
    printf("%s is %ld bytes.\n", "filename", buf->st_size);
    }
}
-- 
-------------------------------------------------------------
Jay @ SAC-UNIX, Sacramento, Ca.   UUCP=...pacbell!sactoh0!jak
If something is worth doing, its worth doing correctly.



More information about the Comp.sys.pyramid mailing list