File tree Expand file tree Collapse file tree 1 file changed +16
-4
lines changed
Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change 1313#include <time.h>
1414#include "time/timex.h"
1515
16- // Some older systems do not support timespec_get() from time.h
17- #if !defined(__STDC_VERSION__ ) || __STDC_VERSION__ < 201112L || \
16+ // Some platforms do not support timespec_get() from time.h.
17+ #if defined(_WIN32 )
18+ #include <sys/timeb.h>
19+ #elif !defined(__STDC_VERSION__ ) || __STDC_VERSION__ < 201112L || \
1820 (!defined(TIME_UTC ) && (!defined(_POSIX_TIMERS ) || _POSIX_TIMERS <= 0 ))
1921#include <sys/time.h>
2022#endif
@@ -255,11 +257,21 @@ static Duration time_div(Time t, Duration d) {
255257// timespec_now returns the current time with nanosecond precision.
256258static struct timespec timespec_now (void ) {
257259 struct timespec ts ;
258- #if defined(__STDC_VERSION__ ) && __STDC_VERSION__ >= 201112L && defined(TIME_UTC )
259- timespec_get (& ts , TIME_UTC );
260+ #if defined(_WIN32 )
261+ // Windows.
262+ struct __timeb64 tb ;
263+ _ftime64 (& tb );
264+ ts .tv_sec = (time_t )tb .time ;
265+ ts .tv_nsec = tb .millitm * 1000000 ;
260266#elif defined(_POSIX_TIMERS ) && (_POSIX_TIMERS > 0 )
267+ // POSIX.
261268 clock_gettime (CLOCK_REALTIME , & ts );
269+ #elif defined(__STDC_VERSION__ ) && __STDC_VERSION__ >= 201112L && defined(TIME_UTC ) && \
270+ !defined(__ANDROID__ )
271+ // C11.
272+ timespec_get (& ts , TIME_UTC );
262273#else
274+ // Fallback for older systems.
263275 struct timeval tv ;
264276 gettimeofday (& tv , NULL );
265277 ts .tv_sec = tv .tv_sec ;
You can’t perform that action at this time.
0 commit comments