Revision cd90f0c5

b/cmake/msvc/sys/time.h
1
#ifndef _MSC_VER // [
2
#error "Use this header only with Microsoft Visual C++ compilers!"
3
#endif // _MSC_VER ]
4

5
#ifndef _MSC_SYS_TIME_H_
6
#define _MSC_SYS_TIME_H_
7

8
//http://social.msdn.microsoft.com/Forums/en/vcgeneral/thread/430449b3-f6dd-4e18-84de-eebd26a8d668
9
#include < time.h >
10
#include <windows.h> //I've ommited this line.
11
#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
12
  #define DELTA_EPOCH_IN_MICROSECS  11644473600000000Ui64
13
#else
14
  #define DELTA_EPOCH_IN_MICROSECS  11644473600000000ULL
15
#endif
16

17
struct timespec {
18

19
time_t tv_sec; /* Seconds since 00:00:00 GMT, */
20

21
/* 1 January 1970 */
22

23
long tv_nsec; /* Additional nanoseconds since */
24

25
/* tv_sec */
26

27
};
28

29
struct timezone 
30
{
31
  int  tz_minuteswest; /* minutes W of Greenwich */
32
  int  tz_dsttime;     /* type of dst correction */
33
};
34
 
35
static inline int gettimeofday(struct timeval *tv, struct timezone *tz)
36
{
37
  FILETIME ft;
38
  unsigned __int64 tmpres = 0;
39
  static int tzflag;
40
 
41
  if (NULL != tv)
42
  {
43
    GetSystemTimeAsFileTime(&ft);
44
 
45
    tmpres |= ft.dwHighDateTime;
46
    tmpres <<= 32;
47
    tmpres |= ft.dwLowDateTime;
48
 
49
    /*converting file time to unix epoch*/
50
    tmpres -= DELTA_EPOCH_IN_MICROSECS; 
51
    tv->tv_sec = (long)(tmpres / 1000000UL);
52
    tv->tv_usec = (long)(tmpres % 1000000UL);
53
  }
54
 
55
  if (NULL != tz)
56
  {
57
    if (!tzflag)
58
    {
59
      _tzset();
60
      tzflag++;
61
    }
62
    tz->tz_minuteswest = _timezone / 60;
63
    tz->tz_dsttime = _daylight;
64
  }
65
 
66
  return 0;
67
}
68

69
#endif //_MSC_SYS_TIME_H_

Also available in: Unified diff