X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=System%2FDirectory.hs;h=00aa07a290522a2a1b91527858023376d9c14f59;hb=4ea71f2a9ade50ca74a091338948ef02c4e23d6d;hp=d3245df0b0a07cb1f6f57bb2b6c122a6610ced07;hpb=a3e56f82973d7117fe4544e5702d1c0180ae7d79;p=haskell-directory.git diff --git a/System/Directory.hs b/System/Directory.hs index d3245df..00aa07a 100644 --- a/System/Directory.hs +++ b/System/Directory.hs @@ -55,12 +55,19 @@ module System.Directory , getModificationTime -- :: FilePath -> IO ClockTime ) where +#ifdef __NHC__ +import Directory +#elif defined(__HUGS__) +import Hugs.Directory +#else + import Prelude import Control.Exception ( bracket ) import System.Posix.Types import System.Time ( ClockTime(..) ) import System.IO +import System.IO.Error import Foreign import Foreign.C @@ -231,6 +238,7 @@ The operand refers to an existing non-directory object. removeDirectory :: FilePath -> IO () removeDirectory path = do + modifyIOError (`ioeSetFileName` path) $ withCString path $ \s -> throwErrnoIfMinus1Retry_ "removeDirectory" (c_rmdir s) @@ -270,6 +278,7 @@ The operand refers to an existing directory. removeFile :: FilePath -> IO () removeFile path = do + modifyIOError (`ioeSetFileName` path) $ withCString path $ \s -> throwErrnoIfMinus1Retry_ "removeFile" (c_unlink s) @@ -422,6 +431,7 @@ The path refers to an existing non-directory object. getDirectoryContents :: FilePath -> IO [FilePath] getDirectoryContents path = do + modifyIOError (`ioeSetFileName` path) $ alloca $ \ ptr_dEnt -> bracket (withCString path $ \s -> @@ -531,6 +541,7 @@ The path refers to an existing non-directory object. setCurrentDirectory :: FilePath -> IO () setCurrentDirectory path = do + modifyIOError (`ioeSetFileName` path) $ withCString path $ \s -> throwErrnoIfMinus1Retry_ "setCurrentDirectory" (c_chdir s) -- ToDo: add path to error @@ -560,6 +571,7 @@ getModificationTime name = withFileStatus :: FilePath -> (Ptr CStat -> IO a) -> IO a withFileStatus name f = do + modifyIOError (`ioeSetFileName` name) $ allocaBytes sizeof_stat $ \p -> withCString (fileNameEndClean name) $ \s -> do throwErrnoIfMinus1Retry_ "withFileStatus" (c_stat s p) @@ -567,6 +579,7 @@ withFileStatus name f = do withFileOrSymlinkStatus :: FilePath -> (Ptr CStat -> IO a) -> IO a withFileOrSymlinkStatus name f = do + modifyIOError (`ioeSetFileName` name) $ allocaBytes sizeof_stat $ \p -> withCString name $ \s -> do throwErrnoIfMinus1Retry_ "withFileOrSymlinkStatus" (lstat s p) @@ -621,3 +634,5 @@ foreign import ccall unsafe "__hscore_X_OK" x_OK :: CMode foreign import ccall unsafe "__hscore_S_IRUSR" s_IRUSR :: CMode foreign import ccall unsafe "__hscore_S_IWUSR" s_IWUSR :: CMode foreign import ccall unsafe "__hscore_S_IXUSR" s_IXUSR :: CMode + +#endif