X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fmisc.c;h=55bedd2b2c901669ff4025feadbb2fd338984831;hb=d659cbaccdc1f3279c49107cf15f15a639738529;hp=2ba52a38ae58fd935de74e9c13662184a2a52c90;hpb=f6445e4ed68362950e8c83b60eed09871982fbe1;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. */