Commit 7e04f06d authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Make timeval_minus_msec work with unsigned values.

parent 2b208fd0
......@@ -82,17 +82,24 @@ timeval_minus(struct timeval *d,
}
}
int
unsigned
timeval_minus_msec(const struct timeval *s1, const struct timeval *s2)
{
/* Avoid overflow. This may happen if the clock is changed */
if(s1->tv_sec < s2->tv_sec)
return 0;
/* Avoid overflow. */
if(s1->tv_sec - s2->tv_sec > 2000000)
return 2000000000;
else if(s1->tv_sec - s2->tv_sec < -2000000)
return -2000000000;
return (s1->tv_sec - s2->tv_sec) * 1000 +
(s1->tv_usec - s2->tv_usec) / 1000;
if(s1->tv_sec > s2->tv_sec)
return (unsigned)(s1->tv_sec - s2->tv_sec) * 1000u +
(unsigned)(s1->tv_usec - s2->tv_usec) / 1000u;
if(s1->tv_usec <= s2->tv_usec)
return 0;
return (unsigned)(s1->tv_usec - s2->tv_usec) / 1000u;
}
void
......
......@@ -46,7 +46,7 @@ unsigned short seqno_plus(unsigned short s, int plus)
unsigned roughly(unsigned value);
void timeval_minus(struct timeval *d,
const struct timeval *s1, const struct timeval *s2);
int timeval_minus_msec(const struct timeval *s1, const struct timeval *s2)
unsigned timeval_minus_msec(const struct timeval *s1, const struct timeval *s2)
ATTRIBUTE ((pure));
void timeval_plus_msec(struct timeval *d,
const struct timeval *s, int msecs);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment