Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.57 KB | None | 0 0
  1. /* Return negative, zero, positive if A < B, A == B, A > B, respectively.
  2.    Assume the nanosecond components are in range, or close to it.  */
  3. static inline int
  4. timespec_cmp (struct timespec a, struct timespec b)
  5. {
  6. int diffadd = a.tv_sec + b.tv_sec;
  7. int diffsub = a.tv_sec - b.tv_sec;
  8. if( ((diffsub > 0) && (diffadd > 0)) || ((diffsub < 0) && (diffadd < 0)) ){
  9. return 1;
  10. }
  11. else if( ((diffsub > 0) && (diffadd < 0)) || ((diffsub < 0) && (diffadd > 0)) ){
  12. return -1;
  13. }
  14. return 0;
  15.   //int diff = a.tv_sec - b.tv_sec;
  16.   //return diff ? diff : a.tv_nsec - b.tv_nsec;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement