SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
windows_time.h
Go to the documentation of this file.
1 #if (defined _WIN32_) || (defined _MSC_VER)
2 
3 /*
4  * missing gettimeofday implementation
5  * for windows; based on postgresql
6  */
7 
8 #ifndef CUSTOM_WINDOWS_TIME_H_
9 #define CUSTOM_WINDOWS_TIME_H_
10 
11 #define _WINSOCKAPI_ // stops windows.h including winsock.h; timeval redefine
12 #include <Windows.h>
13 #include <stdint.h> // portable: uint64_t MSVC: __int64
14 
15 // MSVC defines this in winsock2.h!?
16 typedef struct timeval {
17  long tv_sec;
18  long tv_usec;
19 } timeval;
20 
21 int gettimeofday(struct timeval * tp, struct timezone * tzp)
22 {
23  // Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's
24  // This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC)
25  // until 00:00:00 January 1, 1970
26  static const uint64_t EPOCH = ((uint64_t) 116444736000000000ULL);
27 
28  SYSTEMTIME system_time;
29  FILETIME file_time;
30  uint64_t time;
31 
32  GetSystemTime( &system_time );
33  SystemTimeToFileTime( &system_time, &file_time );
34  time = ((uint64_t)file_time.dwLowDateTime ) ;
35  time += ((uint64_t)file_time.dwHighDateTime) << 32;
36 
37  tp->tv_sec = (long) ((time - EPOCH) / 10000000L);
38  tp->tv_usec = (long) (system_time.wMilliseconds * 1000);
39  return 0;
40 }
41 
42 
43 #endif // CUSTOM_WINDOWS_TIME_H_
44 #endif // _WIN32_
unsigned __int64 uint64_t
Definition: rtptypes_win.h:48