Browse Source

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.
Sergey Poznyakoff 7 năm trước cách đây
mục cha
commit
2d00d8b321
1 tập tin đã thay đổi với 3 bổ sung7 xóa
  1. 3 7
      src/list.c

+ 3 - 7
src/list.c

@@ -23,7 +23,7 @@
 #include <system.h>
 #include <system.h>
 #include <inttostr.h>
 #include <inttostr.h>
 #include <quotearg.h>
 #include <quotearg.h>
-
+#include <time.h>
 #include "common.h"
 #include "common.h"
 
 
 union block *current_header;	/* points to current archive header */
 union block *current_header;	/* points to current archive header */
@@ -1049,15 +1049,11 @@ tartime (struct timespec t, bool full_time)
     {
     {
       if (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));
 	  code_ns_fraction (ns, buffer + strlen (buffer));
 	}
 	}
       else
       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;
       return buffer;
     }
     }