From 7257d900d1dc33285570e4bbcea3f3418e86550b Mon Sep 17 00:00:00 2001 From: Lucas Cavalcante de Sousa Date: Fri, 20 Mar 2020 13:26:11 -0300 Subject: [PATCH] Windows: sys/time.h: Now implementation is separeted from declaration as should be. - `src/lib/evil/unposix/sys/time.c` was add to `src/lib/evil/meson.build`; - .c and .h were separeted; - Faulty timezone structure implemented Test plan: - Ninja with `-k0` flag compiles as much as with `src/lib/evil/unposix/sys/time.c` as with the stub and there is no aditional error. --- src/lib/evil/meson.build | 1 + src/lib/evil/unposix/sys/time.c | 28 ++++++++++++++++++++++++++++ src/lib/evil/unposix/sys/time.h | 31 +++++++------------------------ 3 files changed, 36 insertions(+), 24 deletions(-) create mode 100644 src/lib/evil/unposix/sys/time.c diff --git a/src/lib/evil/meson.build b/src/lib/evil/meson.build index 1d1c9f1ef3..6aeedf5bfa 100644 --- a/src/lib/evil/meson.build +++ b/src/lib/evil/meson.build @@ -16,6 +16,7 @@ if target_machine.system() == 'windows' 'evil_util.c', 'evil_private.h', 'pcre/regex.h', + 'unposix/sys/time.c', ] psapi = cc.find_library('psapi') diff --git a/src/lib/evil/unposix/sys/time.c b/src/lib/evil/unposix/sys/time.c new file mode 100644 index 0000000000..d09e68dcb1 --- /dev/null +++ b/src/lib/evil/unposix/sys/time.c @@ -0,0 +1,28 @@ +#include + +int gettimeofday(struct timeval * tp, struct timezone * tzp) +{ + // This number is the number of 100 nanosecond intervals since 00:00:00 + // 01/01/1601 (UTC) (Windows way) until 00:00:00 01/01/1970 (POSIX way) + 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; +} + +struct tm *localtime_r(const time_t * time, struct tm * result) +{ + localtime_s(result, time); + return result; +} + diff --git a/src/lib/evil/unposix/sys/time.h b/src/lib/evil/unposix/sys/time.h index 65c83f62bd..5f9e2f3e5e 100644 --- a/src/lib/evil/unposix/sys/time.h +++ b/src/lib/evil/unposix/sys/time.h @@ -10,34 +10,17 @@ typedef unsigned short u_short; +struct timezone { + int tz_minuteswest; /* minutes west of Greenwich */ + int tz_dsttime; /* type of DST correction */ +}; + typedef long suseconds_t; typedef struct timeval timeval; -inline int gettimeofday(struct timeval * tp, struct timezone * tzp) -{ - // This number is the number of 100 nanosecond intervals since 00:00:00 - // 01/01/1601 (UTC) (Windows way) until 00:00:00 01/01/1970 (POSIX way) - static const uint64_t EPOCH = ((uint64_t) 116444736000000000ULL); +int gettimeofday(struct timeval * tp, struct timezone * tzp); - 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; -} - -inline struct tm *localtime_r(const time_t * time, struct tm * result) -{ - localtime_s(result, time); - return result; -} +struct tm *localtime_r(const time_t * time, struct tm * result); #endif