X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;ds=sidebyside;f=time.c;h=6672dca4215c3e04de75f576dabc2dfd7c95eb30;hb=refs%2Fheads%2Fv0.2;hp=34e3de9523cb91a6c4142cf36ec6d540d21d7fe6;hpb=a8a78f935dcefa8a7fcda8dae80bca64fe39d632;p=paraslash.git diff --git a/time.c b/time.c index 34e3de95..6672dca4 100644 --- a/time.c +++ b/time.c @@ -106,21 +106,17 @@ void tv_scale(const unsigned long mult, const struct timeval *tv, /** * compute fraction of given struct timeval * - * \param div the integer value to divide by + * \param divisor the integer value to divide by * \param tv the timevalue to divide * \param result holds (1 / mult) * tv upon return */ -void tv_divide(const unsigned long div, const struct timeval *tv, +void tv_divide(const unsigned long divisor, const struct timeval *tv, struct timeval *result) { - long unsigned q = tv->tv_usec / div; - result->tv_sec = tv->tv_sec / div; - result->tv_usec = (tv->tv_sec - result->tv_sec * div) * 1000 * 1000 / div; - 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); } /**