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
)
27 foreign import ccall
"time" c_ctime
:: Ptr CTime
-> IO CInt
29 epochTime
:: IO EpochTime
31 allocaBytes
(sizeOf
(undefined :: CTime
)) $ \p
-> do
33 t
<- peek p
:: IO CTime
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!"