/*
- * Copyright (C) 2005-2007 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2005-2008 Andre Noll <maan@systemlinux.org>
*
* Licensed under the GPL v2. For licencing details see COPYING.
*/
* If \a diff is not \p NULL, it contains the absolute value |\a b - \a a| on
* return.
*
- * \return If \a b < \a, this function returns -1, otherwise it returns 1.
+ * \return If \a b < \a a, this function returns -1, otherwise it returns 1.
*/
int tv_diff(const struct timeval *b, const struct timeval *a, struct timeval *diff)
{
*
* \param a First addend.
* \param b Second addend.
- *
- * \param \a Sum contains the sum \a + \a b on return.
+ * \param sum Contains the sum \a + \a b on return.
*/
void tv_add(const struct timeval *a, const struct timeval *b,
struct timeval *sum)
void tv_divide(const unsigned long divisor, const struct timeval *tv,
struct timeval *result)
{
- long unsigned q;
+ uint64_t x = ((uint64_t)tv->tv_sec * 1000 * 1000 + tv->tv_usec) / divisor;
- 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;
+ result->tv_sec = x / 1000 / 1000;
+ result->tv_usec = x % (1000 * 1000);
}
/**