X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=src%2Fmisc.c;h=55bedd2b2c901669ff4025feadbb2fd338984831;hb=f319c5575b7b98776a778e00b009f17e9814a71c;hp=2ba52a38ae58fd935de74e9c13662184a2a52c90;hpb=5c35fdb275b519373e6eb34621d956d09a52bf31;p=chaz%2Ftar diff --git a/src/misc.c b/src/misc.c index 2ba52a3..55bedd2 100644 --- a/src/misc.c +++ b/src/misc.c @@ -206,6 +206,40 @@ unquote_string (char *string) return result; } +/* 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; + } + } +} + /* File handling. */ /* Saved names in case backup needs to be undone. */