-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__msvc_gettimeofday.h
65 lines (50 loc) · 1.4 KB
/
__msvc_gettimeofday.h
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
55
56
57
58
59
60
61
62
63
64
65
#ifndef ___MSVC_GETTIMEOFDAY_H__
#define ___MSVC_GETTIMEOFDAY_H__
#include <time.h>
#include <windows.h>
#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
#else
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
#endif
//WinRT não possui essa struct na windows.h
#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
struct timeval {
long tv_sec; /* seconds */
long tv_usec; /* and microseconds */
};
#endif
struct timezone_s
{
int tz_minuteswest; /* minutes W of Greenwich */
int tz_dsttime; /* type of dst correction */
};
typedef struct timezone_s timezone_t;
static int gettimeofday(struct timeval *tv, timezone_t *tz)
{
FILETIME ft;
unsigned __int64 tmpres = 0;
if (NULL != tv)
{
GetSystemTimeAsFileTime(&ft);
tmpres |= ft.dwHighDateTime;
tmpres <<= 32;
tmpres |= ft.dwLowDateTime;
tmpres /= 10; /*convert into microseconds*/
/*converting file time to unix epoch*/
tmpres -= DELTA_EPOCH_IN_MICROSECS;
tv->tv_sec = (long)(tmpres / 1000000UL);
tv->tv_usec = (long)(tmpres % 1000000UL);
}
if (NULL != tz)
{
long tzSec;
int daylight;
if(!_get_timezone(&tzSec))
tz->tz_minuteswest = tzSec / 60;
if(!_get_daylight(&daylight))
tz->tz_dsttime = daylight;
}
return 0;
}
#endif