summaryrefslogtreecommitdiff
path: root/StatFS.hsc
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-03-22 15:58:47 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-03-22 16:01:43 -0400
commitaa1bc31e0aede63a1e68d2ec3e2653a7f5be0ae7 (patch)
treee67d0591bdc9be3f36060f8668cb8eace344a553 /StatFS.hsc
parent8ede2e255ffd2397f0714df066d078bc45d839ca (diff)
be a no-op on non-linux, non-freebsd systems
Todo later: use POSIX statvfs Note: Re OSX, see http://code.google.com/p/xmobar/issues/detail?id=28 Apparently xmobar's code will work on OSX, probably __FreeBSD__ is defined there.
Diffstat (limited to 'StatFS.hsc')
-rw-r--r--StatFS.hsc14
1 files changed, 13 insertions, 1 deletions
diff --git a/StatFS.hsc b/StatFS.hsc
index f91a6912c..8b453dc19 100644
--- a/StatFS.hsc
+++ b/StatFS.hsc
@@ -1,7 +1,7 @@
-----------------------------------------------------------------------------
-- |
--
--- (This code comes from xmobar)
+-- (This code originally comes from xmobar)
--
-- Module : StatFS
-- Copyright : (c) Jose A Ortega Ruiz
@@ -57,7 +57,11 @@ import Data.ByteString.Char8 (pack)
# include <sys/param.h>
# include <sys/mount.h>
#else
+#if defined (__linux__)
#include <sys/vfs.h>
+#else
+#define UNKNOWN
+#endif
#endif
data FileSystemStats = FileSystemStats {
@@ -77,18 +81,25 @@ data FileSystemStats = FileSystemStats {
data CStatfs
+#ifdef UNKNOWN
+#warning free space checking code not available for this OS
+#else
#if defined(__FreeBSD__)
foreign import ccall unsafe "sys/mount.h statfs"
#else
foreign import ccall unsafe "sys/vfs.h statfs64"
#endif
c_statfs :: CString -> Ptr CStatfs -> IO CInt
+#endif
toI :: CLong -> Integer
toI = toInteger
getFileSystemStats :: String -> IO (Maybe FileSystemStats)
getFileSystemStats path =
+#ifdef UNKNOWN
+ return Nothing
+#else
allocaBytes (#size struct statfs) $ \vfs ->
useAsCString (pack path) $ \cpath -> do
res <- c_statfs cpath vfs
@@ -107,3 +118,4 @@ getFileSystemStats path =
, fsStatBytesAvailable = toI bavail * bpb
, fsStatBytesUsed = toI (bcount - bfree) * bpb
}
+#endif