-- -----------------------------------------------------------------------------
--- $Id: Directory.hsc,v 1.8 2001/03/01 12:25:33 rrt Exp $
+-- $Id: Directory.hsc,v 1.14 2001/08/10 13:48:06 simonmar Exp $
--
-- (c) The University of Glasgow, 1994-2000
--
import Time ( ClockTime(..) )
+import PrelPosix
import PrelStorable
import PrelCString
import PrelMarshalAlloc
import PrelCTypesISO
import PrelCTypes
-import PrelPosixTypes
import PrelCError
import PrelPtr
import PrelIOBase
import PrelBase
--- Fix mingw stat problem
-#include "../includes/Stg.h"
+#include "config.h"
#include <sys/stat.h>
#include <dirent.h>
#include <limits.h>
createDirectory :: FilePath -> IO ()
createDirectory path = do
- withUnsafeCString path $ \s -> do
+ withCString path $ \s -> do
throwErrnoIfMinus1Retry_ "createDirectory" $
#if defined(mingw32_TARGET_OS)
mkdir s
removeDirectory :: FilePath -> IO ()
removeDirectory path = do
- withUnsafeCString path $ \s ->
+ withCString path $ \s ->
throwErrnoIfMinus1Retry_ "removeDirectory" (rmdir s)
{-
removeFile :: FilePath -> IO ()
removeFile path = do
- withUnsafeCString path $ \s ->
+ withCString path $ \s ->
throwErrnoIfMinus1Retry_ "removeFile" (unlink s)
{-
("not a directory") (Just opath))
else do
- withUnsafeCString opath $ \s1 ->
- withUnsafeCString npath $ \s2 ->
+ withCString opath $ \s1 ->
+ withCString npath $ \s2 ->
throwErrnoIfMinus1Retry_ "renameDirectory" (rename s1 s2)
{-
"is a directory" (Just opath))
else do
- withUnsafeCString opath $ \s1 ->
- withUnsafeCString npath $ \s2 ->
+ withCString opath $ \s1 ->
+ withCString npath $ \s2 ->
throwErrnoIfMinus1Retry_ "renameFile" (rename s1 s2)
{-
getDirectoryContents :: FilePath -> IO [FilePath]
getDirectoryContents path = do
- p <- withUnsafeCString path $ \s ->
+ p <- withCString path $ \s ->
throwErrnoIfNullRetry "getDirectoryContents" (opendir s)
loop p
where
setCurrentDirectory :: FilePath -> IO ()
setCurrentDirectory path = do
- withUnsafeCString path $ \s ->
+ withCString path $ \s ->
throwErrnoIfMinus1Retry_ "setCurrentDirectory" (chdir s)
-- ToDo: add path to error
getPermissions :: FilePath -> IO Permissions
getPermissions name = do
- withUnsafeCString name $ \s -> do
+ withCString name $ \s -> do
read <- access s (#const R_OK)
write <- access s (#const W_OK)
exec <- access s (#const X_OK)
mode = read `unionCMode` (write `unionCMode` exec)
- withUnsafeCString name $ \s ->
+ withCString name $ \s ->
throwErrnoIfMinus1_ "setPermissions" $ chmod s mode
withFileStatus :: FilePath -> (Ptr CStat -> IO a) -> IO a
withFileStatus name f = do
-#ifndef mingw32_TARGET_OS
allocaBytes (#const sizeof(struct stat)) $ \p ->
-#else
- allocaBytes (#const sizeof(struct _stati64)) $ \p ->
-#endif
- withUnsafeCString name $ \s -> do
+ withCString name $ \s -> do
throwErrnoIfMinus1Retry_ "withFileStatus" (stat s p)
f p
modificationTime :: Ptr CStat -> IO ClockTime
modificationTime stat = do
-#ifndef mingw32_TARGET_OS
mtime <- (#peek struct stat, st_mtime) stat
-#else
- mtime <- (#peek struct _stati64, st_mtime) stat
-#endif
return (TOD (toInteger (mtime :: CTime)) 0)
isDirectory :: Ptr CStat -> IO Bool
isDirectory stat = do
-#ifndef mingw32_TARGET_OS
mode <- (#peek struct stat, st_mode) stat
-#else
- mode <- (#peek struct _stati64, st_mode) stat
-#endif
return (s_ISDIR mode /= 0)
isRegularFile :: Ptr CStat -> IO Bool
isRegularFile stat = do
-#ifndef mingw32_TARGET_OS
mode <- (#peek struct stat, st_mode) stat
-#else
- mode <- (#peek struct _stati64, st_mode) stat
-#endif
return (s_ISREG mode /= 0)
foreign import ccall unsafe s_ISDIR :: CMode -> Int
unionCMode :: CMode -> CMode -> CMode
unionCMode = (+)
-type UCString = UnsafeCString
-
#if defined(mingw32_TARGET_OS)
-foreign import ccall unsafe mkdir :: UCString -> IO CInt
+foreign import ccall unsafe mkdir :: CString -> IO CInt
#else
-foreign import ccall unsafe mkdir :: UCString -> CInt -> IO CInt
+foreign import ccall unsafe mkdir :: CString -> CInt -> IO CInt
#endif
-foreign import ccall unsafe chmod :: UCString -> CMode -> IO CInt
-foreign import ccall unsafe access :: UCString -> CMode -> IO CInt
-foreign import ccall unsafe rmdir :: UCString -> IO CInt
-foreign import ccall unsafe chdir :: UCString -> IO CInt
+foreign import ccall unsafe chmod :: CString -> CMode -> IO CInt
+foreign import ccall unsafe access :: CString -> CMode -> IO CInt
+foreign import ccall unsafe rmdir :: CString -> IO CInt
+foreign import ccall unsafe chdir :: CString -> IO CInt
foreign import ccall unsafe getcwd :: Ptr CChar -> CInt -> IO (Ptr CChar)
-foreign import ccall unsafe unlink :: UCString -> IO CInt
-foreign import ccall unsafe rename :: UCString -> UCString -> IO CInt
+foreign import ccall unsafe unlink :: CString -> IO CInt
+foreign import ccall unsafe rename :: CString -> CString -> IO CInt
-foreign import ccall unsafe opendir :: UCString -> IO (Ptr CDir)
+foreign import ccall unsafe opendir :: CString -> IO (Ptr CDir)
foreign import ccall unsafe readdir :: Ptr CDir -> IO (Ptr CDirent)
foreign import ccall unsafe closedir :: Ptr CDir -> IO CInt
-foreign import ccall unsafe stat :: UCString -> Ptr CStat -> IO CInt
+foreign import ccall unsafe stat :: CString -> Ptr CStat -> IO CInt
type CDirent = ()
-type CStat = ()