Skip to content

Commit 7e99ccc

Browse files
committed
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).
1 parent 8f7adb2 commit 7e99ccc

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

wolfcrypt/src/wc_port.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2922,7 +2922,7 @@ time_t mynewt_time(time_t* timer)
29222922
#endif /* WOLFSSL_APACHE_MYNEWT */
29232923

29242924
#if defined(WOLFSSL_GMTIME)
2925-
struct tm* gmtime(const time_t* timer)
2925+
struct tm* gmtime_r(const time_t* timer, struct tm *ret)
29262926
{
29272927
#define YEAR0 1900
29282928
#define EPOCH_YEAR 1970
@@ -2936,8 +2936,6 @@ struct tm* gmtime(const time_t* timer)
29362936
{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
29372937
};
29382938

2939-
static struct tm st_time;
2940-
struct tm* ret = &st_time;
29412939
time_t secs = *timer;
29422940
unsigned long dayclock, dayno;
29432941
int year = EPOCH_YEAR;
@@ -2971,6 +2969,12 @@ struct tm* gmtime(const time_t* timer)
29712969

29722970
return ret;
29732971
}
2972+
2973+
struct tm* gmtime(const time_t* timer) {
2974+
static struct tm st_time;
2975+
return gmtime_r(timer, &st_time);
2976+
}
2977+
29742978
#endif /* WOLFSSL_GMTIME */
29752979

29762980

wolfssl/wolfcrypt/wc_port.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,11 @@ WOLFSSL_ABI WOLFSSL_API int wolfCrypt_Cleanup(void);
10631063
#define XTIME(tl) time((tl))
10641064
#endif
10651065
#endif
1066+
1067+
#if defined(WOLFSSL_GMTIME) && !defined(HAVE_GMTIME_R)
1068+
#define HAVE_GMTIME_R
1069+
#endif
1070+
10661071
#if !defined(XGMTIME) && !defined(TIME_OVERRIDES)
10671072
/* Always use gmtime_r if available. */
10681073
#if defined(HAVE_GMTIME_S)
@@ -1128,8 +1133,9 @@ WOLFSSL_ABI WOLFSSL_API int wolfCrypt_Cleanup(void);
11281133
extern struct tm* XGMTIME(const time_t* timer, struct tm* tmp);
11291134
#elif defined(WOLFSSL_GMTIME)
11301135
struct tm* gmtime(const time_t* timer);
1136+
struct tm* gmtime_r(const time_t* timer, struct tm *ret);
11311137
#endif
1132-
#endif /* NO_ASN_TIME */
1138+
#endif /* !NO_ASN_TIME */
11331139

11341140

11351141
#ifndef WOLFSSL_LEANPSK

0 commit comments

Comments
 (0)