From 6e5806017b5532c5447c527be7b09e4e7058af84 Mon Sep 17 00:00:00 2001 From: Jan Romann Date: Tue, 22 Nov 2022 18:31:15 +0100 Subject: [PATCH] dtls_debug: address WIndows warning for localtime --- dtls_debug.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/dtls_debug.c b/dtls_debug.c index 5f88e6c1..4f93e606 100644 --- a/dtls_debug.c +++ b/dtls_debug.c @@ -77,6 +77,8 @@ static const char *loglevels[] = { #ifdef HAVE_TIME_H +#ifndef IS_WINDOWS + static inline size_t print_timestamp(char *s, size_t len, time_t t) { struct tm *tmp; @@ -84,6 +86,21 @@ print_timestamp(char *s, size_t len, time_t t) { return strftime(s, len, "%b %d %H:%M:%S", tmp); } +#else + +static inline size_t +print_timestamp(char *s, size_t len, time_t t) { + struct tm tmp; + errno_t err = localtime_s(&tmp, &t); + if (err) { + printf("Invalid argument to localtime_s."); + exit(1); + } + return strftime(s, len, "%b %d %H:%M:%S", &tmp); +} + +#endif + #else /* alternative implementation: just print the timestamp */ static inline size_t