Commit f0a7bc05 authored by Steve Lhomme's avatar Steve Lhomme

compat: provide a win32 specific version of timespec_get

On mingw64 clock_gettime() is defined in winpthread which we don't want to use.

This implementation is based on the winpthread internal processing.
parent b19a4150
......@@ -22,6 +22,28 @@
# include <config.h>
#endif
#ifdef _WIN32
#include <windows.h>
int timespec_get(struct timespec *ts, int base)
{
FILETIME ft;
ULARGE_INTEGER s;
ULONGLONG t;
if (base != TIME_UTC)
return 0;
GetSystemTimeAsFileTime(&ft);
s.LowPart = ft.dwLowDateTime;
s.HighPart = ft.dwHighDateTime;
t = s.QuadPart - 116444736000000000ULL;
ts->tv_sec = t / 10000000;
ts->tv_nsec = ((int) (t % 10000000)) * 100;
return base;
}
#else /* !_WIN32 */
#include <time.h>
#include <unistd.h> /* _POSIX_TIMERS */
#ifndef _POSIX_TIMERS
......@@ -58,3 +80,4 @@ int timespec_get(struct timespec *ts, int base)
}
return base;
}
#endif /* !_WIN32 */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment