panthema / 2009 / cryptote / cryptote-0.5.390 / libenctain / botan-1.6 / src / timers.cpp (Download File)
/*************************************************
* Timestamp Functions Source File                *
* (C) 1999-2007 The Botan Project                *
*************************************************/

#include "botan-1.6/include/timers.h"
#include "botan-1.6/include/libstate.h"
#include "botan-1.6/include/util.h"
#include <ctime>

namespace Enctain {
namespace Botan {

/*************************************************
* Timer Access Functions                         *
*************************************************/
u64bit system_time()
   {
   return static_cast<u64bit>(std::time(0));
   }

u64bit system_clock()
   {
   return global_state().system_clock();
   }

/*************************************************
* Default Timer clock reading                    *
*************************************************/
u64bit Timer::clock() const
   {
   return combine_timers(std::time(0), std::clock(), CLOCKS_PER_SEC);
   }

/*************************************************
* Combine a two time values into a single one    *
*************************************************/
u64bit combine_timers(u32bit seconds, u32bit parts, u32bit parts_hz)
   {
   const u64bit NANOSECONDS_UNITS = 1000000000;
   parts *= (NANOSECONDS_UNITS / parts_hz);
   return ((seconds * NANOSECONDS_UNITS) + parts);
   }

}
}