]> rtime.felk.cvut.cz Git - orte.git/blob - orte/include/win32/timeval.h
upgrade to new version 0.3.1
[orte.git] / orte / include / win32 / timeval.h
1 /*
2  * timeval.h    1.0 01/12/19
3  *
4  * Defines gettimeofday, timeval, etc. for Win32
5  *
6  * By Wu Yongwei, modified by Petr Smolik
7  *
8  */
9
10 #ifndef _TIMEVAL_H
11 #define _TIMEVAL_H
12
13 #ifdef _WIN32
14
15 #ifndef __PHARLAP
16   #include <winsock2.h>   //there is defined struct timeval
17 #endif
18 #include <windows.h>
19 #include <time.h>
20
21 #ifndef __GNUC__
22 #define EPOCHFILETIME (116444736000000000i64)
23 #else
24 #define EPOCHFILETIME (116444736000000000LL)
25 #endif
26
27 struct timezone {
28     int tz_minuteswest; /* minutes W of Greenwich */
29     int tz_dsttime;     /* type of dst correction */
30 };
31
32 static inline int gettimeofday(struct timeval *tv, struct timezone *tz)
33 {
34     FILETIME        ft;
35     LARGE_INTEGER   li;
36     __int64         t;
37     static int      tzflag;
38
39     if (tv)
40     {
41         GetSystemTimeAsFileTime(&ft);
42         li.LowPart  = ft.dwLowDateTime;
43         li.HighPart = ft.dwHighDateTime;
44         t  = li.QuadPart;       /* In 100-nanosecond intervals */
45         t -= EPOCHFILETIME;     /* Offset to the Epoch time */
46         t /= 10;                /* In microseconds */
47         tv->tv_sec  = (long)(t / 1000000);
48         tv->tv_usec = (long)(t % 1000000);
49     }
50
51     if (tz)
52     {
53         if (!tzflag)
54         {
55             _tzset();
56             tzflag++;
57         }
58         tz->tz_minuteswest = _timezone / 60;
59         tz->tz_dsttime = _daylight;
60     }
61
62     return 0;
63 }
64
65 #endif /* _WIN32 */
66
67 #endif /* _TIMEVAL_H */
68