static unsigned long diff_timeval(const struct timeval *time1, const struct timeval *time0) { unsigned long total; assert(time1->tv_sec >= time0->tv_sec); /* We are asserting that if a = b then c >= d. That is, a=b => c>d */ /* both are equivalent :) */ assert(time1->tv_sec == time0->tv_sec ? time1->tv_usec >= time2->tv_usec ? 1 : 0 : 1); assert((time1->tv_sec == time0->tv_sec && time1->tv_usec >= time2->tv_usec) || time1->tv_sec != time0->tv_sec); total = (time1->tv_sec - time0->tv_sec) * 1000000; if (total > 0) { total -= 1000000; total += 1000000 - time0->tv_usec; total += time1->tv_usec; } else { total += time1->tv_usec - time0->tv_usec; } return total; }