summaryrefslogtreecommitdiff
path: root/Utility/StatFS.hsc
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-02-04 14:30:28 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-02-04 14:30:28 -0400
commit56470ce3e5a417dd81c985711b7927db0ce9015e (patch)
tree83201edc76758e5dc73ae3170cc51b3016380c91 /Utility/StatFS.hsc
parentdc682e53a2971a4e1ca89a997dcb44406aa5be75 (diff)
really fix foreign C functions filename encodings
GHC should probably export withFilePath.
Diffstat (limited to 'Utility/StatFS.hsc')
-rw-r--r--Utility/StatFS.hsc7
1 files changed, 6 insertions, 1 deletions
diff --git a/Utility/StatFS.hsc b/Utility/StatFS.hsc
index 6b9627463..51a6bda1e 100644
--- a/Utility/StatFS.hsc
+++ b/Utility/StatFS.hsc
@@ -50,6 +50,11 @@ module Utility.StatFS ( FileSystemStats(..), getFileSystemStats ) where
import Foreign
import Foreign.C.Types
import Foreign.C.String
+import GHC.IO.Encoding (getFileSystemEncoding)
+import GHC.Foreign as GHC
+
+withFilePath :: FilePath -> (CString -> IO a) -> IO a
+withFilePath fp f = getFileSystemEncoding >>= \enc -> GHC.withCString enc fp f
#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined (__APPLE__)
# include <sys/param.h>
@@ -103,7 +108,7 @@ getFileSystemStats path =
return Nothing
#else
allocaBytes (#size struct statfs) $ \vfs ->
- withCAString path $ \cpath -> do
+ withFilePath path $ \cpath -> do
res <- c_statfs cpath vfs
if res == -1 then return Nothing
else do