unix-time 0.4.12 → 0.4.13
raw patch · 3 files changed
+25/−7 lines, 3 filesdep ~base
Dependency ranges changed: base
Files
- Data/UnixTime/Sys.hsc +2/−1
- Data/UnixTime/Types.hsc +21/−4
- unix-time.cabal +2/−2
Data/UnixTime/Sys.hsc view
@@ -1,3 +1,4 @@+{-# LANGUAGE CApiFFI #-} {-# LANGUAGE ForeignFunctionInterface #-} module Data.UnixTime.Sys (getUnixTime) where@@ -17,7 +18,7 @@ type CTimeVal = () type CTimeZone = () -foreign import ccall unsafe "gettimeofday"+foreign import capi unsafe "sys/time.h gettimeofday" c_gettimeofday :: Ptr CTimeVal -> Ptr CTimeZone -> IO CInt -- |
Data/UnixTime/Types.hsc view
@@ -64,12 +64,29 @@ (#poke struct timeval, tv_sec) ptr (fromIntegral sec :: Word32) (#poke struct timeval, tv_usec) ptr (utMicroSeconds ut) #else- peek ptr = UnixTime- <$> (#peek struct timeval, tv_sec) ptr- <*> (#peek struct timeval, tv_usec) ptr+ -- On Unix, the struct `timeval` is defined as+ --+ -- struct timeval+ -- {+ -- time_t tv_sec;+ -- suseconds_t tv_usec;+ -- };+ --+ -- The type `suseconds_t` is a signed integer type capable of storing+ -- values at least in the range `[-1, 1000000]`. It's size is platform+ -- specific, and it is 8 bytes long on 64-bit platforms.+ --+ -- Here we peek `tv_usec` using the `CSUSeconds` type and then convert it+ -- to `Int32` (the type of `utMicroSeconds`) relying on the fact that+ -- `tv_usec` is no bigger than `1000000`, and hence we will not overflow.+ peek ptr = do+ sec <- (#peek struct timeval, tv_sec) ptr+ CSUSeconds msec <- (#peek struct timeval, tv_usec) ptr+ return $ UnixTime sec (fromIntegral msec) poke ptr ut = do+ let msec = CSUSeconds $ fromIntegral (utMicroSeconds ut) (#poke struct timeval, tv_sec) ptr (utSeconds ut)- (#poke struct timeval, tv_usec) ptr (utMicroSeconds ut)+ (#poke struct timeval, tv_usec) ptr msec #endif #if __GLASGOW_HASKELL__ >= 704
unix-time.cabal view
@@ -1,6 +1,6 @@ cabal-version: 1.18 name: unix-time-version: 0.4.12+version: 0.4.13 license: BSD3 license-file: LICENSE maintainer: Kazu Yamamoto <kazu@iij.ad.jp>@@ -43,7 +43,7 @@ include-dirs: cbits ghc-options: -Wall build-depends:- base >=4 && <5,+ base >=4.4 && <5, bytestring, old-time, binary