11#include "Python.h"
2+ #ifdef MS_WINDOWS
3+ #include <windows.h>
4+ #endif
25
3- #ifdef __APPLE__
4- #if defined(HAVE_GETTIMEOFDAY ) && defined(HAVE_FTIME )
6+ #if defined(__APPLE__ ) && defined(HAVE_GETTIMEOFDAY ) && defined(HAVE_FTIME )
57 /*
68 * _PyTime_gettimeofday falls back to ftime when getttimeofday fails because the latter
79 * might fail on some platforms. This fallback is unwanted on MacOSX because
1012 */
1113# undef HAVE_FTIME
1214#endif
13- #endif
1415
15- #ifdef HAVE_FTIME
16+ #if defined( HAVE_FTIME ) && !defined( MS_WINDOWS )
1617#include <sys/timeb.h>
17- #if !defined(MS_WINDOWS ) && !defined(PYOS_OS2 )
1818extern int ftime (struct timeb * );
19- #endif /* MS_WINDOWS */
20- #endif /* HAVE_FTIME */
19+ #endif
2120
2221void
2322_PyTime_gettimeofday (_PyTime_timeval * tp )
2423{
24+ #ifdef MS_WINDOWS
25+ FILETIME system_time ;
26+ ULARGE_INTEGER large ;
27+ ULONGLONG microseconds ;
28+
29+ GetSystemTimeAsFileTime (& system_time );
30+ large .u .LowPart = system_time .dwLowDateTime ;
31+ large .u .HighPart = system_time .dwHighDateTime ;
32+ /* 11,644,473,600,000,000: number of microseconds between
33+ the 1st january 1601 and the 1st january 1970 (369 years + 89 leap
34+ days). */
35+ microseconds = large .QuadPart / 10 - 11644473600000000 ;
36+ tp -> tv_sec = microseconds / 1000000 ;
37+ tp -> tv_usec = microseconds % 1000000 ;
38+ #else
2539 /* There are three ways to get the time:
2640 (1) gettimeofday() -- resolution in microseconds
2741 (2) ftime() -- resolution in milliseconds
@@ -30,6 +44,7 @@ _PyTime_gettimeofday(_PyTime_timeval *tp)
3044 Since on some systems (e.g. SCO ODT 3.0) gettimeofday() may
3145 fail, so we fall back on ftime() or time().
3246 Note: clock resolution does not imply clock accuracy! */
47+
3348#ifdef HAVE_GETTIMEOFDAY
3449#ifdef GETTIMEOFDAY_NO_TZ
3550 if (gettimeofday (tp ) == 0 )
@@ -39,6 +54,7 @@ _PyTime_gettimeofday(_PyTime_timeval *tp)
3954 return ;
4055#endif /* !GETTIMEOFDAY_NO_TZ */
4156#endif /* !HAVE_GETTIMEOFDAY */
57+
4258#if defined(HAVE_FTIME )
4359 {
4460 struct timeb t ;
@@ -50,7 +66,8 @@ _PyTime_gettimeofday(_PyTime_timeval *tp)
5066 tp -> tv_sec = time (NULL );
5167 tp -> tv_usec = 0 ;
5268#endif /* !HAVE_FTIME */
53- return ;
69+
70+ #endif /* MS_WINDOWS */
5471}
5572
5673void
0 commit comments