-- -----------------------------------------------------------------------------
--- $Id: Directory.hsc,v 1.8 2001/03/01 12:25:33 rrt Exp $
+-- $Id: Directory.hsc,v 1.13 2001/07/13 11:48:52 rrt 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>
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
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
foreign import ccall unsafe stat :: UCString -> Ptr CStat -> IO CInt
type CDirent = ()
-type CStat = ()