From 38a94040a2409a0856cee918075cf555f8c7b885 Mon Sep 17 00:00:00 2001 From: Lucas Date: Tue, 28 Jul 2020 09:15:59 -0300 Subject: evil: Implement evil_localtime_r using localtime Implements `evil_localtime_r` using win32 [localtime function](https://docs.microsoft.com/pt-br/cpp/c-runtime-library/reference/localtime-localtime32-localtime64?view=vs-2019). If `HAVE_lOCALTIME_R` is not defined, define `localtime_r` as `evil_localtime_r` Co-authored-by: Felipe Magno de Almeida --- header_checks/meson.build | 1 + src/lib/evil/evil_time.c | 22 +++++++++++++++++++++- src/lib/evil/evil_time.h | 6 ++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/header_checks/meson.build b/header_checks/meson.build index c71fdbf216..a2a0e097eb 100644 --- a/header_checks/meson.build +++ b/header_checks/meson.build @@ -88,6 +88,7 @@ function_checks = [ ['getxattr', ['sys/types.h', 'sys/xattr.h']], ['iconv', ['iconv.h']], ['listxattr', ['sys/types.h', 'sys/xattr.h']], + ['localtime_r', ['time.h']], ['malloc_info', ['malloc.h']], ['malloc_usable_size', ['malloc.h']], ['mkdirat', ['sys/stat.h']], diff --git a/src/lib/evil/evil_time.c b/src/lib/evil/evil_time.c index 2262fc1a7b..868d8c0aae 100644 --- a/src/lib/evil/evil_time.c +++ b/src/lib/evil/evil_time.c @@ -61,6 +61,19 @@ int evil_gettimeofday(struct timeval *tv, struct timezone *tz) return res; } +EVIL_API struct tm * +evil_localtime_r(const time_t * time, struct tm * result) +{ + struct tm* _result = localtime(time); + + if (_result) + { + *result = *_result; + return result; + } + return NULL; +} + /* * strptime * based on http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/time/strptime.c?rev=HEAD @@ -468,8 +481,15 @@ strptime(const char *buf, const char *fmt, struct tm *tm) } else { + TIME_ZONE_INFORMATION zone_info; + GetTimeZoneInformation(&zone_info); + const char timezone_table[3] = { + zone_info.StandardName, + zone_info.DaylightName, + NULL, + }; ep = find_string(bp, &i, - (const char * const *)tzname, + (const char * const *)timezone_table, NULL, 2); if (ep != NULL) { diff --git a/src/lib/evil/evil_time.h b/src/lib/evil/evil_time.h index 591900df4f..16fdfc0059 100644 --- a/src/lib/evil/evil_time.h +++ b/src/lib/evil/evil_time.h @@ -43,6 +43,12 @@ EVIL_API int evil_gettimeofday(struct timeval *tv, struct timezone *tz); # define HAVE_GETTIMEOFDAY 1 #endif +EVIL_API struct tm *evil_localtime_r(const time_t * time, struct tm * result); + +#ifndef HAVE_LOCALTIME_R +# define HAVE_LOCALTIME_R +# define localtime_r evil_localtime_r +#endif /** * @brief Convert a string representation of time to a time tm structure . -- cgit v1.2.1