-
Notifications
You must be signed in to change notification settings - Fork 0
/
gettimeofday.c
28 lines (23 loc) · 884 Bytes
/
gettimeofday.c
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
#ifdef _MSC_VER
#include <stdint.h>
#include <winsock2.h>
// https://stackoverflow.com/a/26085827/16079666
int gettimeofday(struct timeval *tp, struct timezone *tzp)
{
// Note: some broken versions only have 8 trailing zero's, the correct
// epoch has 9 trailing zero's This magic number is the number of 100
// nanosecond intervals since January 1, 1601 (UTC) until 00:00:00 January
// 1, 1970
static const uint64_t EPOCH = ((uint64_t) 116444736000000000ULL);
SYSTEMTIME system_time;
FILETIME file_time;
uint64_t time;
GetSystemTime(&system_time);
SystemTimeToFileTime(&system_time, &file_time);
time = ((uint64_t) file_time.dwLowDateTime);
time += ((uint64_t) file_time.dwHighDateTime) << 32;
tp->tv_sec = (long)((time - EPOCH) / 10000000L);
tp->tv_usec = (long)(system_time.wMilliseconds * 1000);
return 0;
}
#endif