-#include "timespec.h"
-#include "xalloc.h"
-
-/* Subtract the `struct timespec' values X and Y by computing X - Y.
- If the difference is negative or zero, return false.
- Otherwise, return true and store the difference in DIFF.
- X and Y must have valid ts_nsec values, in the range 0 to 999999999.
- If the difference would overflow, store the maximum possible difference. */
-
-static bool
-timespec_subtract (struct timespec *diff,
- struct timespec const *x, struct timespec const *y)
-{
- time_t sec = x->tv_sec - y->tv_sec;
- long int nsec = x->tv_nsec - y->tv_nsec;
-
- if (x->tv_sec < y->tv_sec)
- return false;
-
- if (sec < 0)
- {
- /* The difference has overflowed. */
- sec = TIME_T_MAX;
- nsec = 999999999;
- }
- else if (sec == 0 && nsec <= 0)
- return false;
-
- if (nsec < 0)
- {
- sec--;
- nsec += 1000000000;
- }
-
- diff->tv_sec = sec;
- diff->tv_nsec = nsec;
- return true;
-}
-