blob: 1ddcffd4f1d87700b3d65480e6b2e9a47c5e0608 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
// --------------------------------------------------------------------------
//
// File
// Name: BoxTime.cpp
// Purpose: Time for the box
// Created: 2003/10/08
//
// --------------------------------------------------------------------------
#include "Box.h"
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#ifdef HAVE_TIME_H
#include <time.h>
#endif
#include <errno.h>
#include <string.h>
#include "BoxTime.h"
#include "MemLeakFindOn.h"
// --------------------------------------------------------------------------
//
// Function
// Name: GetCurrentBoxTime()
// Purpose: Returns the current time as a box time.
// (1 sec precision, or better if supported by system)
// Created: 2003/10/08
//
// --------------------------------------------------------------------------
box_time_t GetCurrentBoxTime()
{
#ifdef HAVE_GETTIMEOFDAY
struct timeval tv;
if (gettimeofday(&tv, NULL) != 0)
{
BOX_ERROR("Failed to gettimeofday(), dropping "
"precision: " << strerror(errno));
}
else
{
box_time_t timeNow = (tv.tv_sec * MICRO_SEC_IN_SEC_LL)
+ tv.tv_usec;
return timeNow;
}
#endif
return SecondsToBoxTime(time(0));
}
|