aboutsummaryrefslogtreecommitdiffstats
path: root/e-util/e-fsutils.c
diff options
context:
space:
mode:
authorNot Zed <NotZed@Ximian.com>2004-06-01 18:03:03 +0800
committerMichael Zucci <zucchi@src.gnome.org>2004-06-01 18:03:03 +0800
commita29f73349a81fa8d418865b55b9a5a1ddddcfd44 (patch)
treee71a0eb9dbbe3c53be4f21a5caabe2860e65b0e7 /e-util/e-fsutils.c
parentbffff379d074321fb69661aeaa2e2fe38c566810 (diff)
downloadgsoc2013-evolution-a29f73349a81fa8d418865b55b9a5a1ddddcfd44.tar.gz
gsoc2013-evolution-a29f73349a81fa8d418865b55b9a5a1ddddcfd44.tar.zst
gsoc2013-evolution-a29f73349a81fa8d418865b55b9a5a1ddddcfd44.zip
use statvfs if available. Should make it actually work, if not portable.
2004-06-01 Not Zed <NotZed@Ximian.com> * e-fsutils.c (e_fsutils_avail): use statvfs if available. Should make it actually work, if not portable. This is for a bug but I can't recall the number. svn path=/trunk/; revision=26139
Diffstat (limited to 'e-util/e-fsutils.c')
-rw-r--r--e-util/e-fsutils.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/e-util/e-fsutils.c b/e-util/e-fsutils.c
index d2c615124b..923dd5ec42 100644
--- a/e-util/e-fsutils.c
+++ b/e-util/e-fsutils.c
@@ -29,10 +29,12 @@
#include <dirent.h>
/* This isn't as portable as, say, the stuff in GNU coreutils. But I care not for OSF1. */
-#ifdef HAVE_STATFS
-# ifdef HAVE_SYS_VFS_H
-# include <sys/vfs.h> /* linux interface */
+#ifdef HAVE_STATVFS
+# ifdef HAVE_SYS_STATVFS_H
+# include <sys/statvfs.h>
# endif
+#else
+#ifdef HAVE_STATFS
# ifdef HAVE_SYS_PARAM_H
# include <sys/param.h> /* bsd interface */
# endif
@@ -40,6 +42,7 @@
# include <sys/mount.h>
# endif
#endif
+#endif
#include <errno.h>
#include <string.h>
@@ -128,14 +131,24 @@ fail:
long
e_fsutils_avail(const char *path)
{
-#ifdef HAVE_STATFS
+#if defined(HAVE_STATVFS)
+ struct statvfs stfs;
+
+ if (statvfs(path, &stfs) == -1)
+ return -1;
+
+ /* Assumes that frsize === power of 2 */
+ if (stfs.f_frsize >= 1024)
+ return stfs.f_bavail * (stfs.f_frsize / 1024);
+ else
+ return stfs.f_bavail / (1024 / stfs.f_frsize);
+#elif defined(HAVE_STATFS)
struct statfs stfs;
if (statfs(path, &stfs) == -1)
return -1;
- /* On linux at least, bavail is in 512 byte blocks */
- /* For BSD this isn't clear, it may be dependent on f_bsize, which on linux is rather, the page size! */
+ /* For BSD this isn't clear, it may be dependent on f_bsize */
return stfs.f_bavail / 2;
#else
errno = ENOSYS;