module Data.UnixTime.Sys (getUnixTime) where
import Data.UnixTime.Types
import Foreign.C.Error
import Foreign.C.Types
import Foreign.Marshal.Alloc
import Foreign.Ptr
import Foreign.Storable
type CTimeVal = ()
type CTimeZone = ()
foreign import ccall unsafe "gettimeofday"
c_gettimeofday :: Ptr CTimeVal -> Ptr CTimeZone -> IO CInt
getUnixTime :: IO UnixTime
getUnixTime = allocaBytes (16) $ \ p_timeval -> do
throwErrnoIfMinus1_ "getClockTime" $ c_gettimeofday p_timeval nullPtr
sec <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) p_timeval
usec <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) p_timeval
return $ UnixTime sec usec