Follow upstream changes -- Bytestring updates
[git-darcs-import.git] / src / win32 / System / Posix.hs
blob67f12a888b6d8c15b7790f278c8f7cd315ff1003
1 {-# OPTIONS_GHC -fglasgow-exts -fffi #-}
2 {-# LANGUAGE ForeignFunctionInterface #-}
4 module System.Posix where
6 import Foreign.Ptr ( Ptr, castPtr, plusPtr )
7 import Foreign.Storable ( peek, poke, sizeOf )
8 import Foreign.C.Types ( CInt, CUInt, CULong, CTime )
9 import Foreign.C.String ( CString, withCString )
10 import Foreign.Marshal.Alloc ( allocaBytes )
12 import System.Posix.Types ( EpochTime )
13 import System.IO ( Handle )
16 foreign import ccall "sys/utime.h _utime" c_utime :: CString -> Ptr a -> IO CInt
18 setFileTimes :: FilePath -> EpochTime -> EpochTime -> IO ()
19 setFileTimes path atime mtime = path `withCString` \s -> do
20 allocaBytes 8 $ \p -> do
21 poke (castPtr p :: Ptr CTime) (atime)
22 poke (castPtr (plusPtr p 4) :: Ptr CTime) (mtime)
23 c_utime s p
24 return ()
27 foreign import ccall "time" c_ctime :: Ptr CTime -> IO CInt
29 epochTime :: IO EpochTime
30 epochTime = do
31 allocaBytes (sizeOf (undefined :: CTime)) $ \p -> do
32 c_ctime p
33 t <- peek p :: IO CTime
34 return t
36 foreign import stdcall "winbase.h SleepEx" c_SleepEx :: CULong -> CUInt -> IO CInt
38 sleep :: Integer -> IO CInt
39 sleep n = c_SleepEx (1000 * fromIntegral n) 1
41 handleToFd :: Handle -> IO Int
42 handleToFd _ = fail "handleToFd not supported!"