Skip to content

Commit

Permalink
dtls_debug: address WIndows warning for localtime
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Nov 22, 2022
1 parent 9320251 commit 6e58060
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions dtls_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,30 @@ 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;
tmp = localtime(&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
Expand Down

0 comments on commit 6e58060

Please sign in to comment.