diff options
Diffstat (limited to 'src/systemtime.c')
-rw-r--r-- | src/systemtime.c | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/src/systemtime.c b/src/systemtime.c index c440c36..2675fea 100644 --- a/src/systemtime.c +++ b/src/systemtime.c @@ -23,32 +23,29 @@ int systemtime_get_time(double *t) { -#if defined(_WIN32) /* Windows */ +#if defined(WINDOWS) /* Windows */ FILETIME now; ULARGE_INTEGER i; GetSystemTimeAsFileTime(&now); i.LowPart = now.dwLowDateTime; i.HighPart = now.dwHighDateTime; - /* FILETIME is tenths of microseconds since 1601-01-01 UTC */ *t = (i.QuadPart / 10000000.0) - 11644473600.0; + #elif defined(_POSIX_TIMERS) /* POSIX timers */ struct timespec now; - int r = clock_gettime(CLOCK_REALTIME, &now); - if (r < 0) { + if (clock_gettime(CLOCK_REALTIME, &now)) { perror("clock_gettime"); return -1; } - *t = now.tv_sec + (now.tv_nsec / 1000000000.0); + #else /* other platforms */ struct timeval now; - int r = gettimeofday(&now, NULL); - if (r < 0) { + if (gettimeofday(&now, NULL)) { perror("gettimeofday"); return -1; } - *t = now.tv_sec + (now.tv_usec / 1000000.0); #endif @@ -59,12 +56,12 @@ systemtime_get_time(double *t) void systemtime_msleep(unsigned int msecs) { -#ifndef _WIN32 +#ifdef WINDOWS + Sleep(msecs); +#else struct timespec sleep; - sleep.tv_sec = msecs / 1000; - sleep.tv_nsec = (msecs % 1000)*1000000; + sleep.tv_sec = (time_t)(msecs / 1000U); + sleep.tv_nsec = (long)(msecs % 1000U) * 1000000L; nanosleep(&sleep, NULL); -#else - Sleep(msecs); #endif } |