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 diff --git a/platform-specific/dtls_prng_win.c b/platform-specific/dtls_prng_win.c index 8bd96002..a71633b2 100644 --- a/platform-specific/dtls_prng_win.c +++ b/platform-specific/dtls_prng_win.c @@ -15,8 +15,6 @@ #include "dtls_prng.h" #include "dtls_debug.h" -#define _CRT_RAND_S - #include #if defined(__MINGW32__) diff --git a/tinydtls.h b/tinydtls.h index 57cb39b2..c626b65e 100644 --- a/tinydtls.h +++ b/tinydtls.h @@ -34,6 +34,7 @@ #if defined(_WIN32) || defined(_WIN64) #define IS_WINDOWS 1 +#define _CRT_RAND_S #endif #ifndef CONTIKI