das2C
das core C utilities (v3)
Loading...
Searching...
No Matches
win_gtod.h
1/* Replacement for gettimeofday for Windows */
2
3#include <stdint.h>
4
5static int win_gettimeofday(struct timeval * tp, struct timezone * tzp)
6{
7 // Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's
8 // This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC)
9 // until 00:00:00 January 1, 1970
10 static const uint64_t EPOCH = ((uint64_t) 116444736000000000ULL);
11
12 SYSTEMTIME system_time;
13 FILETIME file_time;
14 uint64_t time;
15
16 GetSystemTime( &system_time );
17 SystemTimeToFileTime( &system_time, &file_time );
18 time = ((uint64_t)file_time.dwLowDateTime ) ;
19 time += ((uint64_t)file_time.dwHighDateTime) << 32;
20
21 tp->tv_sec = (long) ((time - EPOCH) / 10000000L);
22 tp->tv_usec = (long) (system_time.wMilliseconds * 1000);
23 return 0;
24}