diff options
Diffstat (limited to 'src/utils.cpp')
-rw-r--r-- | src/utils.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/utils.cpp b/src/utils.cpp index 5e71b09..2c58847 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -311,6 +311,41 @@ time_t stringToEpoch(const char* theTime, const char* format) return mktime(&tmTime); } +#ifndef __TIME_IMP +#define __TIME_IMP +#if _WIN32 + +typedef struct timeval { + long tv_sec; + long tv_usec; +} timeval; + +/* + * Windows implementation of missing POSIX gettimeofday() +*/ +inline int gettimeofday(struct timeval * tp, struct timezone * tzp) +{ + // Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's + // This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC) + // until 00:00:00 January 1, 1970 + static const uint64_t EPOCH = ((uint64_t) 116444736000000000ULL); + + SYSTEMTIME system_time; + FILETIME file_time; + uint64_t time; + + GetSystemTime( &system_time ); + SystemTimeToFileTime( &system_time, &file_time ); + time = ((uint64_t)file_time.dwLowDateTime ) ; + time += ((uint64_t)file_time.dwHighDateTime) << 32; + + tp->tv_sec = (long) ((time - EPOCH) / 10000000L); + tp->tv_usec = (long) (system_time.wMilliseconds * 1000); + return 0; +} +#endif +#endif + uint64_t getTimestampNow() { // Get current time |