    {-# LINE 1 "Data/UnixTime/Sys.hsc" #-}
    {-# LANGUAGE CApiFFI #-}
    {-# LANGUAGE ForeignFunctionInterface #-}

    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

    -- from System.Time

    type CTimeVal = ()
    type CTimeZone = ()

    foreign import capi unsafe "sys/time.h gettimeofday"
        c_gettimeofday :: Ptr CTimeVal -> Ptr CTimeZone -> IO CInt

    -- |
    -- Get current 'UnixTime' from OS.

    getUnixTime :: IO UnixTime
    getUnixTime :: IO UnixTime
    getUnixTime = Int -> (Ptr CTimeVal -> IO UnixTime) -> IO UnixTime
    forall a b. Int -> (Ptr a -> IO b) -> IO b
    allocaBytes (Int
    16) ((Ptr CTimeVal -> IO UnixTime) -> IO UnixTime)
    -> (Ptr CTimeVal -> IO UnixTime) -> IO UnixTime
    forall a b. (a -> b) -> a -> b
    $ \ Ptr CTimeVal
    p_timeval -> do
    {-# LINE 29 "Data/UnixTime/Sys.hsc" #-}
        throwErrnoIfMinus1_ "getClockTime" $ c_gettimeofday p_timeval nullPtr
        peek (castPtr p_timeval)