~ubuntu-branches/debian/sid/botan/sid

« back to all changes in this revision

Viewing changes to src/timers.cpp

  • Committer: Package Import Robot
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2018-03-01 22:23:25 UTC
  • mfrom: (1.2.2)
  • Revision ID: package-import@ubuntu.com-20180301222325-7p7vc45gu3hta34d
Tags: 2.4.0-2
* Don't remove .doctrees from the manual if it doesn't exist.
* Don't specify parallel to debhelper.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*************************************************
2
 
* Timestamp Functions Source File                *
3
 
* (C) 1999-2007 The Botan Project                *
4
 
*************************************************/
5
 
 
6
 
#include <botan/timers.h>
7
 
#include <botan/libstate.h>
8
 
#include <botan/util.h>
9
 
#include <ctime>
10
 
 
11
 
namespace Botan {
12
 
 
13
 
/*************************************************
14
 
* Timer Access Functions                         *
15
 
*************************************************/
16
 
u64bit system_time()
17
 
   {
18
 
   return static_cast<u64bit>(std::time(0));
19
 
   }
20
 
 
21
 
u64bit system_clock()
22
 
   {
23
 
   return global_state().system_clock();
24
 
   }
25
 
 
26
 
/*************************************************
27
 
* Default Timer clock reading                    *
28
 
*************************************************/
29
 
u64bit Timer::clock() const
30
 
   {
31
 
   return combine_timers(std::time(0), std::clock(), CLOCKS_PER_SEC);
32
 
   }
33
 
 
34
 
/*************************************************
35
 
* Combine a two time values into a single one    *
36
 
*************************************************/
37
 
u64bit combine_timers(u32bit seconds, u32bit parts, u32bit parts_hz)
38
 
   {
39
 
   const u64bit NANOSECONDS_UNITS = 1000000000;
40
 
   parts *= (NANOSECONDS_UNITS / parts_hz);
41
 
   return ((seconds * NANOSECONDS_UNITS) + parts);
42
 
   }
43
 
 
44
 
}