Commit 58772a1b authored by simonmar's avatar simonmar
Browse files

[project @ 2001-01-12 16:44:13 by simonmar]

re-order some of the conditional compilation & make it a bit more generic.
parent b7582e0e
-- -----------------------------------------------------------------------------
-- $Id: Time.hsc,v 1.2 2001/01/12 16:40:07 simonmar Exp $
-- $Id: Time.hsc,v 1.3 2001/01/12 16:44:13 simonmar Exp $
--
-- (c) The University of Glasgow, 1995-2001
--
......@@ -228,11 +228,19 @@ noTimeDiff = TimeDiff 0 0 0 0 0 0 0
-- -----------------------------------------------------------------------------
-- getClockTime returns the current time in its internal representation.
#if defined(_WIN32) && !defined(cygwin32_TARGET_OS)
--
#if HAVE_GETTIMEOFDAY
getClockTime = do
allocaBytes (#const sizeof(struct timeval)) $ \ p_timeval -> do
throwErrnoIfMinus1_ "getClockTime" $ gettimeofday p_timeval nullPtr
sec <- (#peek struct timeval,tv_sec) p_timeval :: IO CLong
usec <- (#peek struct timeval,tv_usec) p_timeval :: IO CLong
return (TOD (fromIntegral sec) ((fromIntegral usec) * 1000))
#elif HAVE_FTIME && !defined(cygwin32_TARGET_OS)
--
-- ftime() as implemented by cygwin (in B20.1) is
-- not right, so stay away & use time() there instead.
--
--
getClockTime = do
allocaBytes (#const sizeof(struct timeb)) $ \ p_timeb -> do
ftime p_timeb
......@@ -240,14 +248,6 @@ getClockTime = do
msec <- (#peek struct timeb,millitime) p_timeb :: IO CUShort
return (TOD (fromIntegral sec) (fromIntegral msec * 1000{-ToDo: correct???-}))
#elif defined(HAVE_GETTIMEOFDAY)
getClockTime = do
allocaBytes (#const sizeof(struct timeval)) $ \ p_timeval -> do
throwErrnoIfMinus1_ "getClockTime" $ gettimeofday p_timeval nullPtr
sec <- (#peek struct timeval,tv_sec) p_timeval :: IO CLong
usec <- (#peek struct timeval,tv_usec) p_timeval :: IO CLong
return (TOD (fromIntegral sec) ((fromIntegral usec) * 1000))
#else /* use POSIX time() */
getClockTime = do
secs <- time nullPtr -- can't fail, according to POSIX
......@@ -609,12 +609,12 @@ foreign import unsafe strftime :: Ptr CChar -> CSize -> Addr## -> Ptr CTm -> IO
foreign import unsafe mktime :: Ptr CTm -> IO CTime
foreign import unsafe time :: Ptr CTime -> IO CTime
#ifdef HAVE_GETTIMEOFDAY
#if HAVE_GETTIMEOFDAY
type CTimeVal = ()
foreign import unsafe gettimeofday :: Ptr CTimeVal -> Ptr () -> IO CInt
#endif
#if defined(_WIN32) && !defined(cygwin32_TARGET_OS)
type CTimeB
#if HAVE_FTIME
type CTimeB = ()
foreign import unsafe ftime :: Ptr CTimeB -> IO CInt
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment