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.

(cherry picked from commit f0a7bc050f)
Signed-off-by: Steve Lhomme <robux4@ycbcr.xyz>
This commit is contained in:
Steve Lhomme 2018-05-15 14:35:52 +02:00
parent b5dd37dd22
commit 416ba0eca6
1 changed files with 23 additions and 0 deletions

View File

@ -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 */