aboutsummaryrefslogtreecommitdiffhomepage
path: root/System/Posix/Directory.hsc
diff options
context:
space:
mode:
authorGravatar Max Bolingbroke <batterseapower@hotmail.com>2011-05-14 22:45:27 +0100
committerGravatar Max Bolingbroke <batterseapower@hotmail.com>2011-05-14 22:45:27 +0100
commitbb8a27d14a63fcd126a924d32c69b7694ea709d9 (patch)
treefc8fd365f738a6f77bc31a96efd470fbf2bd51dc /System/Posix/Directory.hsc
parentb7b180d23472dca03fb4c809cd86bcd6d3f01ea9 (diff)
Improved Unicode support in the light of PEP383
Diffstat (limited to 'System/Posix/Directory.hsc')
-rw-r--r--System/Posix/Directory.hsc28
1 files changed, 21 insertions, 7 deletions
diff --git a/System/Posix/Directory.hsc b/System/Posix/Directory.hsc
index cb357df..7f64e16 100644
--- a/System/Posix/Directory.hsc
+++ b/System/Posix/Directory.hsc
@@ -39,14 +39,28 @@ import System.Posix.Error
import System.Posix.Types
import Foreign
import Foreign.C
+#if __GLASGOW_HASKELL__ > 700
+import System.Posix.Internals (withFilePath, peekFilePath)
+#elif __GLASGOW_HASKELL__ > 611
+import System.Posix.Internals (withFilePath)
+
+peekFilePath :: CString -> IO FilePath
+peekFilePath = peekCString
+#else
+withFilePath :: FilePath -> (CString -> IO a) -> IO a
+withFilePath = withCString
+
+peekFilePath :: CString -> IO FilePath
+peekFilePath = peekCString
+#endif
-- | @createDirectory dir mode@ calls @mkdir@ to
-- create a new directory, @dir@, with permissions based on
-- @mode@.
createDirectory :: FilePath -> FileMode -> IO ()
createDirectory name mode =
- withCString name $ \s ->
- throwErrnoPathIfMinus1Retry_ "createDirectory" name (c_mkdir s mode)
+ withFilePath name $ \s ->
+ throwErrnoPathIfMinus1Retry_ "createDirectory" name (c_mkdir s mode)
-- POSIX doesn't allow mkdir() to return EINTR, but it does on
-- OS X (#5184), so we need the Retry variant here.
@@ -59,7 +73,7 @@ newtype DirStream = DirStream (Ptr CDir)
-- directory stream for @dir@.
openDirStream :: FilePath -> IO DirStream
openDirStream name =
- withCString name $ \s -> do
+ withFilePath name $ \s -> do
dirp <- throwErrnoPathIfNullRetry "openDirStream" name $ c_opendir s
return (DirStream dirp)
@@ -82,7 +96,7 @@ readDirStream (DirStream dirp) =
if (dEnt == nullPtr)
then return []
else do
- entry <- (d_name dEnt >>= peekCString)
+ entry <- (d_name dEnt >>= peekFilePath)
c_freeDirEnt dEnt
return entry
else do errno <- getErrno
@@ -154,7 +168,7 @@ getWorkingDirectory = do
where go p bytes = do
p' <- c_getcwd p (fromIntegral bytes)
if p' /= nullPtr
- then do s <- peekCString p'
+ then do s <- peekFilePath p'
free p'
return s
else do errno <- getErrno
@@ -175,7 +189,7 @@ foreign import ccall unsafe "__hsunix_long_path_size"
changeWorkingDirectory :: FilePath -> IO ()
changeWorkingDirectory path =
modifyIOError (`ioeSetFileName` path) $
- withCString path $ \s ->
+ withFilePath path $ \s ->
throwErrnoIfMinus1Retry_ "changeWorkingDirectory" (c_chdir s)
foreign import ccall unsafe "chdir"
@@ -184,7 +198,7 @@ foreign import ccall unsafe "chdir"
removeDirectory :: FilePath -> IO ()
removeDirectory path =
modifyIOError (`ioeSetFileName` path) $
- withCString path $ \s ->
+ withFilePath path $ \s ->
throwErrnoIfMinus1Retry_ "removeDirectory" (c_rmdir s)
foreign import ccall unsafe "rmdir"