Skip to content

Instantly share code, notes, and snippets.

@codestation
Created July 23, 2013 00:25
Show Gist options
  • Save codestation/6058882 to your computer and use it in GitHub Desktop.
Save codestation/6058882 to your computer and use it in GitHub Desktop.
#include <inttypes.h>
#include <stdio.h>
#include <sys/statvfs.h>
int getDiskSpace(const char *path, uint64_t *free, uint64_t *total) {
struct statvfs stat;
if (statvfs(path, &stat) < 0) {
return -1;
}
*total = stat.f_frsize * stat.f_blocks;
*free = stat.f_frsize * stat.f_bfree;
return 0;
}
int main(int argc, char **argv) {
uint64_t free, total;
if(getDiskSpace(argv[1], &free, &total) < 0) {
printf("Error");
return 1;
} else {
printf("total: %" PRIu64 "\n", total);
printf("free: %" PRIu64 "\n", free);
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment