From: simonmar Date: Fri, 12 Jan 2001 16:44:13 +0000 (+0000) Subject: [project @ 2001-01-12 16:44:13 by simonmar] X-Git-Tag: Approximately_9120_patches~2926 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=58772a1b2bb4b031522c3faeef9daefb27e94723;p=ghc-hetmet.git [project @ 2001-01-12 16:44:13 by simonmar] re-order some of the conditional compilation & make it a bit more generic. --- diff --git a/ghc/lib/std/Time.hsc b/ghc/lib/std/Time.hsc index f40ed6f..86423a9 100644 --- a/ghc/lib/std/Time.hsc +++ b/ghc/lib/std/Time.hsc @@ -1,5 +1,5 @@ -- ----------------------------------------------------------------------------- --- $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