Last active
January 22, 2016 22:26
-
-
Save nirbhayc/07bba0ed221f130467eb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Free disk space using statvfs() and df -h. | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <sys/statvfs.h> | |
float _statvfs() | |
{ | |
int err; | |
struct statvfs stat; | |
if ((statvfs("/", &stat)) < 0 ) | |
{ | |
printf("failed to stat!\n"); | |
exit(1); | |
} | |
return (stat.f_bavail * stat.f_bsize) / 1024 / 1024 / 1024; | |
} | |
char * _system(const char *cmd, char *buf) | |
{ | |
FILE *f; | |
f = popen(cmd, "r"); | |
if (!f) | |
{ | |
printf("failed to open pipe!\n"); | |
exit(1); | |
} | |
fgets(buf, 10, f); | |
pclose(f); | |
return buf; | |
} | |
void main() | |
{ | |
char buf[10]; | |
printf("statvfs() : %.2fG\n", _statvfs()); | |
printf("df -f : %s", | |
_system("df -h / | tail -1 | awk '{print $4}'", buf)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment