format everything with hindent
[packages/time.git] / lib / Data / Time / Clock / Internal / CTimeval.hs
1 module Data.Time.Clock.Internal.CTimeval where
2 #ifndef mingw32_HOST_OS
3 -- All Unix-specific, this
4 import Foreign
5 import Foreign.C
6
7 data CTimeval =
8 MkCTimeval CLong
9 CLong
10
11 instance Storable CTimeval where
12 sizeOf _ = (sizeOf (undefined :: CLong)) * 2
13 alignment _ = alignment (undefined :: CLong)
14 peek p = do
15 s <- peekElemOff (castPtr p) 0
16 mus <- peekElemOff (castPtr p) 1
17 return (MkCTimeval s mus)
18 poke p (MkCTimeval s mus) = do
19 pokeElemOff (castPtr p) 0 s
20 pokeElemOff (castPtr p) 1 mus
21
22 foreign import ccall unsafe "time.h gettimeofday" gettimeofday :: Ptr CTimeval -> Ptr () -> IO CInt
23
24 -- | Get the current POSIX time from the system clock.
25 getCTimeval :: IO CTimeval
26 getCTimeval =
27 with
28 (MkCTimeval 0 0)
29 (\ptval -> do
30 throwErrnoIfMinus1_ "gettimeofday" $ gettimeofday ptval nullPtr
31 peek ptval)
32 #endif