summaryrefslogtreecommitdiff
path: root/openbsd-compat/bsd-statvfs.c
diff options
context:
space:
mode:
Diffstat (limited to 'openbsd-compat/bsd-statvfs.c')
-rw-r--r--openbsd-compat/bsd-statvfs.c55
1 files changed, 50 insertions, 5 deletions
diff --git a/openbsd-compat/bsd-statvfs.c b/openbsd-compat/bsd-statvfs.c
index 844d5b46..2b1da80e 100644
--- a/openbsd-compat/bsd-statvfs.c
+++ b/openbsd-compat/bsd-statvfs.c
@@ -1,7 +1,7 @@
-/* $Id: bsd-statvfs.c,v 1.1 2008/06/08 17:32:29 dtucker Exp $ */
+/* $Id: bsd-statvfs.c,v 1.2 2014/01/17 07:10:59 dtucker Exp $ */
/*
- * Copyright (c) 2008 Darren Tucker <dtucker@zip.com.au>
+ * Copyright (c) 2008,2014 Darren Tucker <dtucker@zip.com.au>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -18,20 +18,65 @@
#include "includes.h"
+#if !defined(HAVE_STATVFS) || !defined(HAVE_FSTATVFS)
+
+#include <sys/param.h>
+#ifdef HAVE_SYS_MOUNT_H
+# include <sys/mount.h>
+#endif
+
#include <errno.h>
-#ifndef HAVE_STATVFS
+static void
+copy_statfs_to_statvfs(struct statvfs *to, struct statfs *from)
+{
+ to->f_bsize = from->f_bsize;
+ to->f_frsize = from->f_bsize; /* no exact equivalent */
+ to->f_blocks = from->f_blocks;
+ to->f_bfree = from->f_bfree;
+ to->f_bavail = from->f_bavail;
+ to->f_files = from->f_files;
+ to->f_ffree = from->f_ffree;
+ to->f_favail = from->f_ffree; /* no exact equivalent */
+ to->f_fsid = 0; /* XXX fix me */
+ to->f_flag = from->f_flags;
+ to->f_namemax = MNAMELEN;
+}
+
+# ifndef HAVE_STATVFS
int statvfs(const char *path, struct statvfs *buf)
{
+# ifdef HAVE_STATFS
+ struct statfs fs;
+
+ memset(&fs, 0, sizeof(fs));
+ if (statfs(path, &fs) == -1)
+ return -1;
+ copy_statfs_to_statvfs(buf, &fs);
+ return 0;
+# else
errno = ENOSYS;
return -1;
+# endif
}
-#endif
+# endif
-#ifndef HAVE_FSTATVFS
+# ifndef HAVE_FSTATVFS
int fstatvfs(int fd, struct statvfs *buf)
{
+# ifdef HAVE_FSTATFS
+ struct statfs fs;
+
+ memset(&fs, 0, sizeof(fs));
+ if (fstatfs(fd, &fs) == -1)
+ return -1;
+ copy_statfs_to_statvfs(buf, &fs);
+ return 0;
+# else
errno = ENOSYS;
return -1;
+# endif
}
+# endif
+
#endif