-bool time_greater(struct timespec a, struct timespec b)
-{
- if (a.tv_sec > b.tv_sec)
- return true;
- else if (a.tv_sec < b.tv_sec)
- return false;
-
- return a.tv_nsec > b.tv_nsec;
-}
-
-bool time_less(struct timespec a, struct timespec b)
-{
- if (a.tv_sec < b.tv_sec)
- return true;
- else if (a.tv_sec > b.tv_sec)
- return false;
-
- return a.tv_nsec < b.tv_nsec;
-}
-
-bool time_eq(struct timespec a, struct timespec b)
-{
- return a.tv_sec == b.tv_sec && a.tv_nsec == b.tv_nsec;
-}
-
-struct timespec time_sub(struct timespec recent, struct timespec old)
-{
- struct timespec diff;
-
- diff.tv_sec = recent.tv_sec - old.tv_sec;
- if (old.tv_nsec > recent.tv_nsec) {
- diff.tv_sec--;
- diff.tv_nsec = 1000000000 + recent.tv_nsec - old.tv_nsec;
- } else
- diff.tv_nsec = recent.tv_nsec - old.tv_nsec;
-
- assert(diff.tv_sec >= 0);
- return diff;
-}
-
-struct timespec time_add(struct timespec a, struct timespec b)
-{
- struct timespec sum;
-
- sum.tv_sec = a.tv_sec + b.tv_sec;
- sum.tv_nsec = a.tv_nsec + b.tv_nsec;
- if (sum.tv_nsec >= 1000000000) {
- sum.tv_sec++;
- sum.tv_nsec -= 1000000000;
- }
- return sum;
-}
-