diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2018-04-07 10:33:27 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2018-04-07 10:33:27 +0300 |
commit | 2d00d8b32190ca7135673999b175850019746042 (patch) | |
tree | 3c771ed0c2b179bd954c2ce2d5836a23ad292f3b | |
parent | e8c3f4860d6b821f9e1df322821df2895596ac22 (diff) | |
download | tar-2d00d8b32190ca7135673999b175850019746042.tar.gz |
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.
-rw-r--r-- | src/list.c | 10 |
1 files changed, 3 insertions, 7 deletions
@@ -23,7 +23,7 @@ #include <system.h> #include <inttostr.h> #include <quotearg.h> - +#include <time.h> #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; } |