From 278a51979a269762a4c570d130aaea62bad97a2c Mon Sep 17 00:00:00 2001 From: Greg Tucker Date: Tue, 30 May 2017 13:46:34 -0700 Subject: [PATCH] Fix test helper for windows and gcc7 issues Change-Id: Idb61d32d928536918dd243df825060c1b5bc484d Signed-off-by: Greg Tucker --- include/test.h | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/include/test.h b/include/test.h index ed41a05..a124329 100644 --- a/include/test.h +++ b/include/test.h @@ -36,25 +36,34 @@ extern "C" { // Use sys/time.h functions for time #if defined (__unix__) || (__APPLE__) || (__MINGW32__) -#include +# include #endif +#ifdef _MSC_VER +# define inline __inline +# include +# include +#endif + +#include +#include + struct perf{ struct timeval tv; }; #if defined (__unix__) || (__APPLE__) || (__MINGW32__) -inline int perf_start(struct perf *p) +static inline int perf_start(struct perf *p) { return gettimeofday(&(p->tv), 0); } -inline int perf_stop(struct perf *p) +static inline int perf_stop(struct perf *p) { return gettimeofday(&(p->tv), 0); } -inline void perf_print(struct perf stop, struct perf start, long long dsize) +static inline void perf_print(struct perf stop, struct perf start, long long dsize) { long long secs = stop.tv.tv_sec - start.tv.tv_sec; long long usecs = secs * 1000000 + stop.tv.tv_usec - start.tv.tv_usec; @@ -75,13 +84,17 @@ inline void perf_print(struct perf stop, struct perf start, long long dsize) } #endif -inline uint64_t get_filesize(FILE *fp) +static inline uint64_t get_filesize(FILE *fp) { uint64_t file_size; fpos_t pos, pos_curr; fgetpos(fp, &pos_curr); /* Save current position */ +#if defined(_WIN32) || defined(_WIN64) + _fseeki64(fp, 0, SEEK_END); +#else fseeko(fp, 0, SEEK_END); +#endif fgetpos(fp, &pos); file_size = *(uint64_t *)&pos; fsetpos(fp, &pos_curr); /* Restore position */