aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/time.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-03-03 17:26:57 +0000
committerlloyd <[email protected]>2010-03-03 17:26:57 +0000
commit6cf657ac72a8ace3ccf88d12a32e6507a164ba11 (patch)
tree09ce9fd3467eb009f826119ef16f545801b2b3db /src/utils/time.cpp
parent04a40219dfc444184ff5650a89e740e90b0dfb4d (diff)
Use static_cast if using std::time-based get_nanoseconds_clock to make
it obvious that truncation is occuring. Something to deal with in 2038 I guess, though get_nanoseconds_clock is already an unknown/unspecified epoch (since the Windows timer uses 1/1/1601 as the epoch)
Diffstat (limited to 'src/utils/time.cpp')
-rw-r--r--src/utils/time.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/utils/time.cpp b/src/utils/time.cpp
index fe4521706..0dbbd5e9c 100644
--- a/src/utils/time.cpp
+++ b/src/utils/time.cpp
@@ -1,6 +1,6 @@
/**
* Time Functions
-* (C) 1999-2009 Jack Lloyd
+* (C) 1999-2010 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
@@ -93,11 +93,13 @@ calendar_point calendar_value(u64bit a_time_t)
u64bit get_nanoseconds_clock()
{
#if defined(BOTAN_TARGET_OS_HAS_CLOCK_GETTIME)
+
struct ::timespec tv;
::clock_gettime(CLOCK_REALTIME, &tv);
return combine_timers(tv.tv_sec, tv.tv_nsec, 1000000000);
#elif defined(BOTAN_TARGET_OS_HAS_GETTIMEOFDAY)
+
struct ::timeval tv;
::gettimeofday(&tv, 0);
return combine_timers(tv.tv_sec, tv.tv_usec, 1000000);
@@ -113,7 +115,9 @@ u64bit get_nanoseconds_clock()
return (tstamp * 100); // Scale to 1 nanosecond units
#else
- return combine_timers(std::time(0), std::clock(), CLOCKS_PER_SEC);
+
+ return combine_timers(static_cast<u32bit>(std::time(0)),
+ std::clock(), CLOCKS_PER_SEC);
#endif
}