X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=time.c;h=6672dca4215c3e04de75f576dabc2dfd7c95eb30;hb=10d1e8a34c0c84c3c9409bab5c14cee87b1a17f3;hp=49b941bb004b959367a1d319dae7cead37d312df;hpb=bf2430160b2704e97a3ff1774d689b4b85e94eb5;p=paraslash.git diff --git a/time.c b/time.c index 49b941bb..6672dca4 100644 --- a/time.c +++ b/time.c @@ -113,15 +113,10 @@ void tv_scale(const unsigned long mult, const struct timeval *tv, void tv_divide(const unsigned long divisor, const struct timeval *tv, struct timeval *result) { - long unsigned q = tv->tv_usec / divisor; - result->tv_sec = tv->tv_sec / divisor; - result->tv_usec = (tv->tv_sec - result->tv_sec * divisor) - * 1000 * 1000 / divisor; - if (result->tv_usec + q >= 1000 * 1000) { - result->tv_sec++; - result->tv_usec = 1000 * 1000 - result->tv_usec - q; - } else - result->tv_usec += q; + uint64_t x = ((uint64_t)tv->tv_sec * 1000 * 1000 + tv->tv_usec) / divisor; + + result->tv_sec = x / 1000 / 1000; + result->tv_usec = x % (1000 * 1000); } /**