]> Dogcows Code - chaz/tar/blobdiff - src/misc.c
Carefully crafted invalid headers can cause buffer overrun.
[chaz/tar] / src / misc.c
index 2ba52a38ae58fd935de74e9c13662184a2a52c90..55bedd2b2c901669ff4025feadbb2fd338984831 100644 (file)
@@ -206,6 +206,40 @@ unquote_string (char *string)
   return result;
 }
 \f
+/* Handling numbers.  */
+
+/* Output fraction and trailing digits appropriate for a nanoseconds
+   count equal to NS, but don't output unnecessary '.' or trailing
+   zeros.  */
+
+void
+code_ns_fraction (int ns, char *p)
+{
+  if (ns == 0)
+    *p = '\0';
+  else
+    {
+      int i = 9;
+      *p++ = '.';
+
+      while (ns % 10 == 0)
+       {
+         ns /= 10;
+         i--;
+       }
+
+      p[i] = '\0';
+
+      for (;;)
+       {
+         p[--i] = '0' + ns % 10;
+         if (i == 0)
+           break;
+         ns /= 10;
+       }
+    }
+}
+\f
 /* File handling.  */
 
 /* Saved names in case backup needs to be undone.  */
This page took 0.022048 seconds and 4 git commands to generate.