diff options
author | Joey Hess <joeyh@joeyh.name> | 2016-03-05 11:22:32 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2016-03-05 11:22:32 -0400 |
commit | 80de75d25c19f37564ac6db97db534f40d26f108 (patch) | |
tree | 0ccf8611ba4fdfdccb6f90cee16c76a481d9feaa /Utility/libdiskfree.c | |
parent | aa5de5e25c46cbf5c0eb2cd6e0fb6e84be5586fb (diff) | |
parent | cd8e2e4eeb70d22f9a7daa375474d80aa188574b (diff) |
Merge branch 'no-cbits'
Diffstat (limited to 'Utility/libdiskfree.c')
-rw-r--r-- | Utility/libdiskfree.c | 84 |
1 files changed, 0 insertions, 84 deletions
diff --git a/Utility/libdiskfree.c b/Utility/libdiskfree.c deleted file mode 100644 index a682bb3bd..000000000 --- a/Utility/libdiskfree.c +++ /dev/null @@ -1,84 +0,0 @@ -/* disk free space checking, C mini-library - * - * Copyright 2012, 2014 Joey Hess <id@joeyh.name> - * - * License: BSD-2-clause - */ - -/* Include appropriate headers for the OS, and define what will be used to - * check the free space. */ -#if defined (__FreeBSD__) -# include <sys/param.h> -# include <sys/mount.h> -# define STATCALL statfs /* statfs64 not yet tested on a real FreeBSD machine */ -# define STATSTRUCT statfs -# define BSIZE f_bsize -#else -#if defined __ANDROID__ -# warning free space checking code not available for Android -# define UNKNOWN -#else -#if defined (__linux__) || defined (__APPLE__) || defined (__FreeBSD_kernel__) || (defined (__SVR4) && defined (__sun)) -/* Linux or OSX or Debian kFreeBSD or Solaris */ -/* This is a POSIX standard, so might also work elsewhere too. */ -# include <sys/statvfs.h> -# define STATCALL statvfs -# define STATSTRUCT statvfs -# define BSIZE f_frsize -#else -# warning free space checking code not available for this OS -# define UNKNOWN -#endif -#endif -#endif - -#include <errno.h> -#include <stdio.h> - -unsigned long long int get(const char *path, int req) { -#ifdef UNKNOWN - errno = 1; - return 0; -#else - unsigned long long int v, blocksize; - struct STATSTRUCT buf; - - if (STATCALL(path, &buf) != 0) - return 0; /* errno is set */ - else - errno = 0; - - switch (req) { - case 0: - v = buf.f_blocks; - break; - case 1: - v = buf.f_bavail; - break; - default: - v = 0; - } - - blocksize = buf.BSIZE; - return v * blocksize; -#endif -} - -/* Checks the amount of disk that is available to regular (non-root) users. - * (If there's an error, or this is not supported, - * returns 0 and sets errno to nonzero.) - */ -unsigned long long int diskfree(const char *path) { - return get(path, 1); -} - -/* Gets the total size of the disk. */ -unsigned long long int disksize(const char *path) { - return get(path, 0); -} - -/* -main () { - printf("%lli\n", diskfree(".")); -} -*/ |