summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucas <Coquinho@users.noreply.github.com>2020-07-28 09:15:59 -0300
committerFelipe Magno de Almeida <felipe@expertise.dev>2020-12-15 16:10:26 -0300
commit38a94040a2409a0856cee918075cf555f8c7b885 (patch)
tree239bcd2b5334370e2dcf65480580abdbdbf3b751
parent9407a5fe76962292901e0cea5ca7d3e3def289c5 (diff)
downloadefl-38a94040a2409a0856cee918075cf555f8c7b885.tar.gz
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 <felipe@expertise.dev>
-rw-r--r--header_checks/meson.build1
-rw-r--r--src/lib/evil/evil_time.c22
-rw-r--r--src/lib/evil/evil_time.h6
3 files changed, 28 insertions, 1 deletions
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 .