From: Sergey Poznyakoff Date: Sat, 7 Apr 2018 07:33:27 +0000 (+0300) Subject: Rewrite struct tm formatting X-Git-Tag: release_1_31~33 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2d00d8b32190ca7135673999b175850019746042;p=thirdparty%2Ftar.git Rewrite struct tm formatting * src/list.c (tartime): Use strftime instead of manually formatting fields of the struct tm. This should also suppress some gcc warnings. --- diff --git a/src/list.c b/src/list.c index 14388a55..2cc5d400 100644 --- a/src/list.c +++ b/src/list.c @@ -23,7 +23,7 @@ #include #include #include - +#include #include "common.h" union block *current_header; /* points to current archive header */ @@ -1049,15 +1049,11 @@ tartime (struct timespec t, bool full_time) { if (full_time) { - sprintf (buffer, "%04ld-%02d-%02d %02d:%02d:%02d", - tm->tm_year + 1900L, tm->tm_mon + 1, tm->tm_mday, - tm->tm_hour, tm->tm_min, tm->tm_sec); + strftime (buffer, sizeof buffer, "%Y-%m-%d %H:%M:%S", tm); code_ns_fraction (ns, buffer + strlen (buffer)); } else - sprintf (buffer, "%04ld-%02d-%02d %02d:%02d", - tm->tm_year + 1900L, tm->tm_mon + 1, tm->tm_mday, - tm->tm_hour, tm->tm_min); + strftime (buffer, sizeof buffer, "%Y-%m-%d %H:%M", tm); return buffer; }