From 814d54c676d5827f6ea37c1cd2d6e846d080c13c Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bonicoli Date: Wed, 12 Dec 2018 03:02:21 +0100 Subject: [PATCH] use strftime instead of snprintf wherever possible --- src/log.c | 8 ++++---- src/util.c | 8 ++------ 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/log.c b/src/log.c index bed836d..9fbe526 100644 --- a/src/log.c +++ b/src/log.c @@ -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); diff --git a/src/util.c b/src/util.c index 553b746..43450b3 100644 --- a/src/util.c +++ b/src/util.c @@ -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; }