Merge pull request #205 from shmuelnatan/master

change localtime to localtime_r which is a thread-safe function
This commit is contained in:
Olof Hagsand 2021-04-20 10:31:22 +02:00 committed by GitHub
commit e9b07cebab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -171,13 +171,13 @@ static int
flogtime(FILE *f) flogtime(FILE *f)
{ {
struct timeval tv; struct timeval tv;
struct tm *tm; struct tm tm;
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
tm = localtime((time_t*)&tv.tv_sec); localtime_r((time_t*)&tv.tv_sec, &tm);
fprintf(f, "%s %2d %02d:%02d:%02d: ", fprintf(f, "%s %2d %02d:%02d:%02d: ",
mon2name(tm->tm_mon), tm->tm_mday, mon2name(tm.tm_mon), tm.tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec); tm.tm_hour, tm.tm_min, tm.tm_sec);
return 0; return 0;
} }