Skip to content

Instantly share code, notes, and snippets.

@briangreenery
Created November 23, 2013 00:09
Show Gist options
  • Save briangreenery/7609011 to your computer and use it in GitHub Desktop.
Save briangreenery/7609011 to your computer and use it in GitHub Desktop.
(Incorrectly) calculate the free size of the directory
#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