1
/*************************************************
2
* Timestamp Functions Source File *
3
* (C) 1999-2007 The Botan Project *
4
*************************************************/
6
#include <botan/timers.h>
7
#include <botan/libstate.h>
8
#include <botan/util.h>
13
/*************************************************
14
* Timer Access Functions *
15
*************************************************/
18
return static_cast<u64bit>(std::time(0));
23
return global_state().system_clock();
26
/*************************************************
27
* Default Timer clock reading *
28
*************************************************/
29
u64bit Timer::clock() const
31
return combine_timers(std::time(0), std::clock(), CLOCKS_PER_SEC);
34
/*************************************************
35
* Combine a two time values into a single one *
36
*************************************************/
37
u64bit combine_timers(u32bit seconds, u32bit parts, u32bit parts_hz)
39
const u64bit NANOSECONDS_UNITS = 1000000000;
40
parts *= (NANOSECONDS_UNITS / parts_hz);
41
return ((seconds * NANOSECONDS_UNITS) + parts);