Skip to content

Commit 6e58060

Browse files
committed
dtls_debug: address WIndows warning for localtime
1 parent 9320251 commit 6e58060

1 file changed

Lines changed: 17 additions & 0 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

0 commit comments

Comments
 (0)