Created
November 23, 2013 00:09
-
-
Save briangreenery/7609011 to your computer and use it in GitHub Desktop.
(Incorrectly) calculate the free size of the directory
This file contains 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
#include <stdio.h> | |
#include <inttypes.h> | |
#include <sys/statvfs.h> | |
typedef unsigned long long uint64; | |
uint64 get_free_size( const char* path ) | |
{ | |
struct statvfs buffer; | |
if ( statvfs( path, &buffer ) != -1 ) | |
{ | |
int64 size = (uint64)buffer.f_frsize * (uint64)buffer.f_bfree; | |
if ( size > 0 ) | |
return size; | |
} | |
return 0xffffffffffffffffuLL; | |
} | |
int main( int argc, const char* argv[] ) | |
{ | |
if ( argc != 2 ) | |
{ | |
printf( "Usage: %s <directory>\n", argv[0] ); | |
return 1; | |
} | |
printf( "%llu bytes free\n", get_free_size( argv[1] ) ); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment