From 1ceffd7e106c5a885c7788a83e3e1f95e15863ab Mon Sep 17 00:00:00 2001 From: cathery Date: Wed, 11 Dec 2019 05:59:04 +0300 Subject: [PATCH] Fix time showing up incorrectly in logs --- source/log.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/log.c b/source/log.c index a13b3a2..b995d0e 100644 --- a/source/log.c +++ b/source/log.c @@ -21,12 +21,13 @@ void WriteToLog(const char *fmt, ...) #else time_t unixTime = time(NULL); - struct tm *tStruct = localtime((const time_t *)&unixTime); + struct tm tStruct; + localtime_r(&unixTime, &tStruct); FILE *fp = fopen(CONFIG_PATH "log.txt", "a"); //Print time - fprintf(fp, "%04i-%02i-%02i %02i:%02i:%02i: ", (tStruct->tm_year + 1900), tStruct->tm_mon, tStruct->tm_mday, tStruct->tm_hour, tStruct->tm_min, tStruct->tm_sec); + fprintf(fp, "%04i-%02i-%02i %02i:%02i:%02i: ", (tStruct.tm_year + 1900), tStruct.tm_mon, tStruct.tm_mday, tStruct.tm_hour, tStruct.tm_min, tStruct.tm_sec); //Print the actual text va_list va;