From aa1bc31e0aede63a1e68d2ec3e2653a7f5be0ae7 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 22 Mar 2011 15:58:47 -0400 Subject: [PATCH] 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. --- StatFS.hsc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/StatFS.hsc b/StatFS.hsc index f91a6912ce..8b453dc199 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 # include #else +#if defined (__linux__) #include +#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