From 116b6d135dad7f45d018a2d715a614b35143f385 Mon Sep 17 00:00:00 2001 From: James Park Date: Mon, 30 Nov 2020 00:57:55 -0800 Subject: [PATCH] util: Add os_localtime MSVC does not have localtime_r, so add abstraction. Reviewed-by: Samuel Pitoiset Reviewed-by: Erik Faye-Lund Part-of: --- src/util/os_time.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/util/os_time.h b/src/util/os_time.h index 049ab11..c681d6e 100644 --- a/src/util/os_time.h +++ b/src/util/os_time.h @@ -37,6 +37,7 @@ #include #include +#include #ifdef __cplusplus extern "C" { @@ -62,6 +63,17 @@ os_time_get(void) } +static inline struct tm * +os_localtime(const time_t *timer, struct tm *buf) +{ +#ifdef _WIN32 + return localtime_s(buf, timer) ? NULL : buf; +#else + return localtime_r(timer, buf); +#endif +} + + /* * Sleep. */ -- 2.7.4