ttyrpld-2.15/user/replay.c:
#define MICROSECOND 1000000
static void tv_delta(const struct timeval *past, const struct timeval *now,
struct timeval *dest) {
/* Calculates the time difference between "past" and "now" and stores the
result in "dest". All parameters in µs. */
unsigned long sec = now->tv_sec - past->tv_sec;
long acc = now->tv_usec - past->tv_usec;
if(acc < 0) {
// past: 1.5, now: 2.0, sec = 2 - 1 = 1, acc = 0 - 500000 = -500000;
dest->tv_sec = --sec;
dest->tv_usec = MICROSECOND + acc;
} else {
dest->tv_sec = sec;
dest->tv_usec = acc;
}
return;
}