You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
583 B
C
31 lines
583 B
C
#include "timeval.h"
|
|
#include <sys/time.h>
|
|
|
|
void timeval_add( struct timeval* t1, struct timeval* t2, struct timeval* res )
|
|
{
|
|
res->tv_sec = t1->tv_sec + t2->tv_sec;
|
|
res->tv_usec = t1->tv_usec + t2->tv_usec;
|
|
while( res->tv_usec > 1000000 ) {
|
|
res->tv_usec -= 1000000;
|
|
res->tv_sec += 1;
|
|
}
|
|
}
|
|
|
|
int timeval_compare( struct timeval* t1, struct timeval* t2 )
|
|
{
|
|
if( t1->tv_sec < t2->tv_sec ) {
|
|
return -1;
|
|
} else if( t1->tv_sec > t2->tv_sec ) {
|
|
return 1;
|
|
}
|
|
|
|
if( t1->tv_usec < t2->tv_usec ) {
|
|
return -1;
|
|
} else if( t1->tv_usec > t2->tv_usec ) {
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|