Fix test helper for windows and gcc7 issues

Change-Id: Idb61d32d928536918dd243df825060c1b5bc484d
Signed-off-by: Greg Tucker <greg.b.tucker@intel.com>
This commit is contained in:
Greg Tucker 2017-05-30 13:46:34 -07:00 committed by Xiaodong Liu
parent a8966b6709
commit 278a51979a
1 changed files with 18 additions and 5 deletions

View File

@ -36,25 +36,34 @@ extern "C" {
// Use sys/time.h functions for time
#if defined (__unix__) || (__APPLE__) || (__MINGW32__)
#include <sys/time.h>
# include <sys/time.h>
#endif
#ifdef _MSC_VER
# define inline __inline
# include <time.h>
# include <Windows.h>
#endif
#include <stdio.h>
#include <stdint.h>
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 */