[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [hivex][PATCH] Increase filetime printing resolution to sub-second




Signed-off-by: Alex Nelson <ajnelson cs ucsc edu>
---
 xml/hivexml.c |   20 +++++++++++++++++---
 1 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/xml/hivexml.c b/xml/hivexml.c
index 5030c24..98b90c5 100644
--- a/xml/hivexml.c
+++ b/xml/hivexml.c
@@ -185,6 +185,8 @@ filetime_to_8601 (int64_t windows_ticks)
   char *ret;
   time_t t;
   struct tm *tm;
+  int64_t sub_seconds;
+  size_t ftd;  /* # chars formatted so far. */
 
   if (windows_ticks == 0LL)
     return NULL;
@@ -194,16 +196,28 @@ filetime_to_8601 (int64_t windows_ticks)
   if (tm == NULL)
     return NULL;
 
-  ret = malloc (TIMESTAMP_BUF_LEN);
+  sub_seconds = windows_ticks % WINDOWS_TICK;
+  /* Trim trailing zeroes from fractional part. */
+  while (sub_seconds % 10 == 0 && sub_seconds > 0) {
+    sub_seconds /= 10;
+  }
+
+  ret = calloc (TIMESTAMP_BUF_LEN, sizeof (char));
   if (ret == NULL) {
-    perror ("malloc");
+    perror ("calloc");
     exit (EXIT_FAILURE);
   }
 
-  if (strftime (ret, TIMESTAMP_BUF_LEN, "%FT%TZ", tm) == 0) {
+  if (strftime (ret, TIMESTAMP_BUF_LEN, "%FT%T", tm) == 0) {
     perror ("strftime");
     exit (EXIT_FAILURE);
   }
+  ftd = strlen (ret);
+
+  if (snprintf (ret + ftd, TIMESTAMP_BUF_LEN - ftd, ".%" PRIi64 "Z", sub_seconds) == 0) {
+    perror ("snprintf");
+    exit (EXIT_FAILURE);
+  }
 
   return ret;
 }
-- 
1.7.6.4




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]