Use localtime_r instead of localtime

master
nirenjan 2021-08-03 11:25:25 -07:00
parent bdee493f03
commit 27a5eab8b7
1 changed files with 6 additions and 3 deletions

View File

@ -180,12 +180,15 @@ void pinelog_log_message(int level, const char *file, int line, const char *fmt,
#if PINELOG_SHOW_DATE #if PINELOG_SHOW_DATE
do { do {
time_t t; time_t t;
struct tm tm1;
struct tm *tmp; struct tm *tmp;
char date_string[30]; char date_string[30];
t = time(NULL); t = time(NULL);
tmp = localtime(&t); tmp = localtime_r(&t, &tm1);
strftime(date_string, sizeof(date_string), "%F %T ", tmp); if (tmp != NULL) {
fputs(date_string, output_stream); strftime(date_string, sizeof(date_string), "%F %T ", tmp);
fputs(date_string, output_stream);
}
} while (0); } while (0);
#endif #endif