Skip to content

Commit 7892056

Browse files
committed
windows: address Visual Studio warnings
1 parent 9320251 commit 7892056

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

dtls_debug.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,30 @@ static const char *loglevels[] = {
7777

7878
#ifdef HAVE_TIME_H
7979

80+
#ifndef IS_WINDOWS
81+
8082
static inline size_t
8183
print_timestamp(char *s, size_t len, time_t t) {
8284
struct tm *tmp;
8385
tmp = localtime(&t);
8486
return strftime(s, len, "%b %d %H:%M:%S", tmp);
8587
}
8688

89+
#else
90+
91+
static inline size_t
92+
print_timestamp(char *s, size_t len, time_t t) {
93+
struct tm tmp;
94+
errno_t err = localtime_s(&tmp, &t);
95+
if (err) {
96+
printf("Invalid argument to localtime_s.");
97+
exit(1);
98+
}
99+
return strftime(s, len, "%b %d %H:%M:%S", &tmp);
100+
}
101+
102+
#endif
103+
87104
#else /* alternative implementation: just print the timestamp */
88105

89106
static inline size_t

platform-specific/dtls_prng_win.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
#include "dtls_prng.h"
1616
#include "dtls_debug.h"
1717

18-
#define _CRT_RAND_S
19-
2018
#include <stdlib.h>
2119

2220
#if defined(__MINGW32__)

tinydtls.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
#if defined(_WIN32) || defined(_WIN64)
3636
#define IS_WINDOWS 1
37+
#define _CRT_RAND_S
3738
#endif
3839

3940
#ifndef CONTIKI

0 commit comments

Comments
 (0)