52 lines
979 B
C
52 lines
979 B
C
#include <sys/time.h>
|
|
|
|
struct timeval *
|
|
uc_tvadd(struct timeval *dst, const struct timeval *a, const struct timeval *b)
|
|
{
|
|
dst->tv_sec = a->tv_sec + b->tv_sec;
|
|
dst->tv_usec = a->tv_usec + b->tv_usec;
|
|
|
|
if (dst->tv_usec >= 1000000)
|
|
dst->tv_sec++, dst->tv_usec -= 1000000;
|
|
|
|
return dst;
|
|
}
|
|
|
|
struct timeval *
|
|
uc_tvsub(struct timeval *dst, const struct timeval *a, const struct timeval *b)
|
|
{
|
|
dst->tv_sec = a->tv_sec - b->tv_sec;
|
|
dst->tv_usec = a->tv_usec - b->tv_usec;
|
|
|
|
if (dst->tv_usec < 0)
|
|
dst->tv_sec--, dst->tv_usec += 1000000;
|
|
|
|
return dst;
|
|
}
|
|
|
|
int
|
|
uc_tvcmp(const struct timeval *a, const struct timeval *b)
|
|
{
|
|
if(a->tv_sec < b->tv_sec)
|
|
return -1;
|
|
else if(a->tv_sec > b->tv_sec)
|
|
return 1;
|
|
|
|
if (a->tv_usec < b->tv_usec)
|
|
return -1;
|
|
else if (a->tv_usec > b->tv_usec)
|
|
return 1;
|
|
|
|
return 0;
|
|
}
|
|
|
|
struct timeval *
|
|
uc_to2tv(struct timeval *dst, unsigned long ms)
|
|
{
|
|
dst->tv_sec = ms / 1000;
|
|
dst->tv_usec = ms % 1000 * 1000;
|
|
|
|
return dst;
|
|
}
|
|
|