util: Add os_localtime
authorJames Park <jpark37@lagfreegames.com>
Mon, 30 Nov 2020 08:57:55 +0000 (00:57 -0800)
committerMarge Bot <eric+marge@anholt.net>
Tue, 1 Dec 2020 07:11:44 +0000 (07:11 +0000)
MSVC does not have localtime_r, so add abstraction.

Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7829>

src/util/os_time.h

index 049ab11..c681d6e 100644 (file)
@@ -37,6 +37,7 @@
 
 #include <stdbool.h>
 #include <stdint.h>
+#include <time.h>
 
 #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.
  */