util: Add os_localtime

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>
This commit is contained in:
James Park 2020-11-30 00:57:55 -08:00 committed by Marge Bot
parent 531843cf2e
commit 116b6d135d

View 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.
*/