From: Adrian Perez de Castro Date: Mon, 5 Aug 2019 13:57:45 +0000 (+0300) Subject: MSVC: Provide an implementation of gettimeofday() X-Git-Tag: xkbcommon-0.10.0~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9e3045c7f50a4666b9938366aec7cb9a938794e9;p=platform%2Fupstream%2Flibxkbcommon.git MSVC: Provide an implementation of gettimeofday() --- diff --git a/bench/bench.c b/bench/bench.c index 2c5f23d..c28ac65 100644 --- a/bench/bench.c +++ b/bench/bench.c @@ -26,9 +26,39 @@ #include #include -#include #include "bench.h" +#include "../src/utils.h" + +#ifndef _MSC_VER +#include +#else +#include +#include + +struct timeval { + long tv_sec, tv_usec; +}; + +static int +gettimeofday(struct timeval *tv, void *unused) +{ + static const uint64_t EPOCH = ((uint64_t) 116444736000000000ULL); + + SYSTEMTIME system_time; + FILETIME file_time; + uint64_t t; + + GetSystemTime(&system_time); + SystemTimeToFileTime(&system_time, &file_time); + t = (uint64_t) file_time.dwLowDateTime; + t += ((uint64_t) file_time.dwHighDateTime) << 32; + + tv->tv_sec = (long) ((t - EPOCH) / 10000000L); + tv->tv_usec = (long) (system_time.wMilliseconds * 1000); + return 0; +} +#endif void bench_start(struct bench *bench)