1
0
forked from bip/bip

use strftime instead of snprintf wherever possible

This commit is contained in:
Pierre-Louis Bonicoli 2018-12-12 03:02:21 +01:00
parent a86b73ab03
commit 814d54c676
Signed by untrusted user: pilou
GPG Key ID: ADC2651DDACD3538
2 changed files with 6 additions and 10 deletions

View File

@ -144,10 +144,10 @@ char *log_build_filename(log_t *logdata, const char *destination)
time(&s);
now = localtime(&s);
snprintf(year, 5, "%04d", now->tm_year + 1900);
snprintf(day, 3, "%02d", now->tm_mday);
snprintf(month, 3, "%02d", now->tm_mon + 1);
snprintf(hour, 3, "%02d", now->tm_hour);
strftime(year, 5, "%Y", now);
strftime(day, 3, "%d", now);
strftime(month, 3, "%m", now);
strftime(hour, 3, "%H", now);
snprintf(logfile, MAX_PATH_LEN, "%s/%s", conf_log_root,
conf_log_format);
replace_var(logfile, "%u", logdata->user->name, MAX_PATH_LEN);

View File

@ -122,9 +122,7 @@ char *timestamp(void)
time(&tv);
tm = localtime(&tv);
snprintf(ts, 20, "%02d-%02d-%04d %02d:%02d:%02d", tm->tm_mday,
tm->tm_mon + 1, tm->tm_year + 1900, tm->tm_hour,
tm->tm_min, tm->tm_sec);
strftime(ts, 20, "%d-%m-%Y %H:%M:%S", tm);
return ts;
}
@ -137,9 +135,7 @@ char *hrtime(time_t s)
return "never";
tm = localtime(&s);
snprintf(ts, 20, "%02d-%02d-%04d %02d:%02d:%02d", tm->tm_mday,
tm->tm_mon + 1, tm->tm_year + 1900, tm->tm_hour,
tm->tm_min, tm->tm_sec);
strftime(ts, 20, "%d-%m-%Y %H:%M:%S", tm);
return ts;
}