From 7e99ccc782fdd58192ab8d0b482786406603e987 Mon Sep 17 00:00:00 2001 From: Daniel Pouzzner Date: Tue, 14 Nov 2023 17:37:12 -0600 Subject: [PATCH] wolfcrypt/src/wc_port.c, wolfssl/wolfcrypt/wc_port.h: refactor WOLFSSL_GMTIME gmtime() into gmtime_r(), and always define HAVE_GMTIME_R when defined(WOLFSSL_GMTIME). --- wolfcrypt/src/wc_port.c | 10 +++++++--- wolfssl/wolfcrypt/wc_port.h | 8 +++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/wolfcrypt/src/wc_port.c b/wolfcrypt/src/wc_port.c index 28ae8ab09..62b1b3811 100644 --- a/wolfcrypt/src/wc_port.c +++ b/wolfcrypt/src/wc_port.c @@ -2922,7 +2922,7 @@ time_t mynewt_time(time_t* timer) #endif /* WOLFSSL_APACHE_MYNEWT */ #if defined(WOLFSSL_GMTIME) -struct tm* gmtime(const time_t* timer) +struct tm* gmtime_r(const time_t* timer, struct tm *ret) { #define YEAR0 1900 #define EPOCH_YEAR 1970 @@ -2936,8 +2936,6 @@ struct tm* gmtime(const time_t* timer) {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} }; - static struct tm st_time; - struct tm* ret = &st_time; time_t secs = *timer; unsigned long dayclock, dayno; int year = EPOCH_YEAR; @@ -2971,6 +2969,12 @@ struct tm* gmtime(const time_t* timer) return ret; } + +struct tm* gmtime(const time_t* timer) { + static struct tm st_time; + return gmtime_r(timer, &st_time); +} + #endif /* WOLFSSL_GMTIME */ diff --git a/wolfssl/wolfcrypt/wc_port.h b/wolfssl/wolfcrypt/wc_port.h index 2cd79590e..88affc73a 100644 --- a/wolfssl/wolfcrypt/wc_port.h +++ b/wolfssl/wolfcrypt/wc_port.h @@ -1063,6 +1063,11 @@ WOLFSSL_ABI WOLFSSL_API int wolfCrypt_Cleanup(void); #define XTIME(tl) time((tl)) #endif #endif + +#if defined(WOLFSSL_GMTIME) && !defined(HAVE_GMTIME_R) + #define HAVE_GMTIME_R +#endif + #if !defined(XGMTIME) && !defined(TIME_OVERRIDES) /* Always use gmtime_r if available. */ #if defined(HAVE_GMTIME_S) @@ -1128,8 +1133,9 @@ WOLFSSL_ABI WOLFSSL_API int wolfCrypt_Cleanup(void); extern struct tm* XGMTIME(const time_t* timer, struct tm* tmp); #elif defined(WOLFSSL_GMTIME) struct tm* gmtime(const time_t* timer); + struct tm* gmtime_r(const time_t* timer, struct tm *ret); #endif -#endif /* NO_ASN_TIME */ +#endif /* !NO_ASN_TIME */ #ifndef WOLFSSL_LEANPSK