log: use localtime_r instead of localtime

localtime_r does not have the side-effect of behaving like it called tzset(),
in particular it will save one stat(/etc/localtime) syscall. This is not a big
deal, but it makes the strace output cleaner and thus more useful :).
next
Michael Stapelberg 2011-10-18 18:32:47 +01:00
parent 744def377a
commit f09d9a4c37
1 changed files with 3 additions and 2 deletions

View File

@ -87,12 +87,13 @@ void add_loglevel(const char *level) {
*
*/
void vlog(char *fmt, va_list args) {
char timebuf[64];
static char timebuf[64];
static struct tm result;
/* Get current time */
time_t t = time(NULL);
/* Convert time to local time (determined by the locale) */
struct tm *tmp = localtime(&t);
struct tm *tmp = localtime_r(&t, &result);
/* Generate time prefix */
strftime(timebuf, sizeof(timebuf), "%x %X - ", tmp);
#ifdef DEBUG_TIMING