OpcUaCanOpen
CANopen OPC-UA server
gettimeofday.h
Go to the documentation of this file.
1 #ifdef WIN32
2 #include "Winsock2.h"
3 #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
4  #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
5 #else
6  #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
7 #endif
8 
9 struct timezone
10 {
11  int tz_minuteswest; // minutes W of Greenwich
12  int tz_dsttime; // type of dst correction
13 };
14 
15 int gettimeofday(struct timeval *tv, struct timezone *tz = NULL)
16 {
17  FILETIME ft;
18  unsigned __int64 tmpres = 0;
19  static int tzflag;
20 
21  if (NULL != tv)
22  {
23  GetSystemTimeAsFileTime(&ft);
24 
25  tmpres |= ft.dwHighDateTime;
26  tmpres <<= 32;
27  tmpres |= ft.dwLowDateTime;
28 
29  /*converting file time to unix epoch*/
30  tmpres -= DELTA_EPOCH_IN_MICROSECS;
31  tmpres /= 10; /*convert into microseconds*/
32  tv->tv_sec = (long)(tmpres / 1000000UL);
33  tv->tv_usec = (long)(tmpres % 1000000UL);
34  }
35 
36  if (NULL != tz)
37  {
38  if (!tzflag)
39  {
40  _tzset();
41  tzflag++;
42  }
43  tz->tz_minuteswest = _timezone / 60;
44  tz->tz_dsttime = _daylight;
45  }
46 
47  return 0;
48 }
49 
50 #endif