Commit c6891c7f authored by Mikhail Karpenko's avatar Mikhail Karpenko

WIP: add time subtraction function

parent ecb78ce2
...@@ -51,3 +51,22 @@ int time_comp(struct timeval *t1, struct timeval *t2) ...@@ -51,3 +51,22 @@ int time_comp(struct timeval *t1, struct timeval *t2)
} }
return -1; return -1;
} }
/**
* Subtract one time value from another and return the difference
* @param tv1 time value to subtract from
* @param tv2 time value to be subtracted
* @return tv1 - tv2
*/
struct timeval time_sub(const struct timeval *tv1, const struct timeval *tv2)
{
struct timeval ret_val = *tv1;
ret_val.tv_sec -= 1;
ret_val.tv_usec += 1000000;
ret_val.tv_sec -= tv2->tv_sec;
ret_val.tv_usec -= tv2->tv_usec;
time_normalize(&ret_val);
return ret_val;
}
...@@ -26,5 +26,6 @@ ...@@ -26,5 +26,6 @@
void time_normalize(struct timeval *tv); void time_normalize(struct timeval *tv);
int time_comp(struct timeval *t1, struct timeval *t2); int time_comp(struct timeval *t1, struct timeval *t2);
struct timeval time_sub(const struct timeval *tv1, const struct timeval *tv2);
#endif /* _THELPER_H */ #endif /* _THELPER_H */
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