Try the statvfs glibc function, or the statfs system call
#include <sys/statvfs.h>
int statvfs(const char *path, struct statvfs *buf);
#include <sys/vfs.h> /* or <sys/statfs.h> */
int statfs(const char *path, struct statfs *buf);
// in both structures you can get the free memory
// by the following formula.
free_Bytes = s->f_bsize * s->f_bfree