Skip to content

Commit

Permalink
Fix time showing up incorrectly in logs
Browse files Browse the repository at this point in the history
  • Loading branch information
cathery committed Dec 11, 2019
1 parent 1985319 commit 1ceffd7
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions source/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1ceffd7

Please sign in to comment.