parent
24b374ef03
commit
ca54303b43
@ -0,0 +1,30 @@
|
||||
#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;
|
||||
}
|
||||
|
Loading…
Reference in new issue