49eabb90e2eb2060f3d0abe237e11459d3123c32 kent Tue Apr 30 17:18:59 2013 -0700 Adding freeSpaceOnFileSystem library function. diff --git src/lib/osunix.c src/lib/osunix.c index b44692d..63bf87a 100644 --- src/lib/osunix.c +++ src/lib/osunix.c @@ -1,47 +1,58 @@ /* Some wrappers around operating-system specific stuff. * * This file is copyright 2002 Jim Kent, but license is hereby * granted for all use - public, private or commercial. */ #include "common.h" #include #include #include +#include #include #include #include "portable.h" #include "portimpl.h" #include #include #include off_t fileSize(char *pathname) /* get file size for pathname. return -1 if not found */ { struct stat mystat; ZeroVar(&mystat); if (stat(pathname,&mystat)==-1) { return -1; } return mystat.st_size; } +long long freeSpaceOnFileSystem(char *path) +/* Given a path to a file or directory on a file system, return free space + * in bytes. */ +{ +struct statvfs fi; +int err = statvfs(path,&fi); +if (err < 0) + errnoAbort("freeSpaceOnFileSystem could not statvfs"); +return (long long)fi.f_bsize * fi.f_bavail; +} long clock1000() /* A millisecond clock. */ { struct timeval tv; static long origSec; gettimeofday(&tv, NULL); if (origSec == 0) origSec = tv.tv_sec; return (tv.tv_sec-origSec)*1000 + tv.tv_usec / 1000; } void sleep1000(int milli) /* Sleep for given number of 1000ths of second */ { @@ -656,15 +667,16 @@ if (stat(fileName, &st) < 0) return FALSE; if (S_ISREG(st.st_mode)) return TRUE; return FALSE; } void makeSymLink(char *oldName, char *newName) /* Return a symbolic link from newName to oldName or die trying */ { int err = symlink(oldName, newName); if (err < 0) errnoAbort("Couldn't make symbolic link from %s to %s\n", oldName, newName); } +