]> git.ipfire.org Git - thirdparty/tar.git/commitdiff
maint: higher-precision checkpoint timestamps
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 24 Jul 2024 16:45:46 +0000 (09:45 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 24 Jul 2024 17:04:16 +0000 (10:04 -0700)
* src/checkpoint.c (format_checkpoint_string):
Use current_timespec to get nanosecond resolution.
This also frees us from the necessity of including <sys/time.h>
to use gettimeofday, which is removed in POSIX.1-2024.

src/checkpoint.c

index ca9534f9cae563ff3d0d32cc62363f1e31028ab8..f1710bb533ab47dd38e49b15c95ceff0dcb5008c 100644 (file)
@@ -103,7 +103,7 @@ checkpoint_compile_action (const char *str)
       sigemptyset (&sigs);
       checkpoint_state = CHKP_COMPILE;
     }
-  
+
   if (strcmp (str, ".") == 0 || strcmp (str, "dot") == 0)
     alloc_action (cop_dot);
   else if (strcmp (str, "bell") == 0)
@@ -326,13 +326,11 @@ format_checkpoint_string (FILE *fp, size_t len,
 
            case 't':
              {
-               struct timeval tv;
-               struct tm *tm;
+               struct timespec ts = current_timespec ();
                const char *fmt = arg ? arg : "%c";
-
-               gettimeofday (&tv, NULL);
-               tm = localtime (&tv.tv_sec);
-               len += fprintftime (fp, fmt, tm, 0, tv.tv_usec * 1000);
+               struct tm *tm = localtime (&ts.tv_sec);
+               len += (tm ? fprintftime (fp, fmt, tm, 0, ts.tv_nsec)
+                       : fprintf (fp, "????""-??""-?? ??:??:??"));
              }
              break;