X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fmisc.c;h=7322dd2a0f56c89cde3db3d24c14c51bb4ad1a4a;hb=3209329337c87a102fa12d7eb60a3df323ba56c1;hp=55bedd2b2c901669ff4025feadbb2fd338984831;hpb=2f800ce3fb9c38360e1b6dac70ee0d8ceae72c6a;p=chaz%2Ftar diff --git a/src/misc.c b/src/misc.c index 55bedd2..7322dd2 100644 --- a/src/misc.c +++ b/src/misc.c @@ -239,6 +239,27 @@ code_ns_fraction (int ns, char *p) } } } + +char const * +code_timespec (struct timespec t, char sbuf[TIMESPEC_STRSIZE_BOUND]) +{ + time_t s = t.tv_sec; + int ns = t.tv_nsec; + char *np; + bool negative = s < 0; + + if (negative && ns != 0) + { + s++; + ns = BILLION - ns; + } + + np = umaxtostr (negative ? - (uintmax_t) s : (uintmax_t) s, sbuf + 1); + if (negative) + *--np = '-'; + code_ns_fraction (ns, sbuf + UINTMAX_STRSIZE_BOUND); + return np; +} /* File handling. */