macros.h (1214B)
1 #ifndef _MACROS_H_ 2 #define _MACROS_H_ 3 4 /* stolen from OpenBSD */ 5 /* Note: some code calls these macros with the same first and last 6 argument, so it is important that that doesn't cause bad behavior. */ 7 #define ltk_timespecadd(tsp, usp, vsp) \ 8 do { \ 9 (vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec; \ 10 (vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec; \ 11 if ((vsp)->tv_nsec >= 1000000000L) { \ 12 (vsp)->tv_sec++; \ 13 (vsp)->tv_nsec -= 1000000000L; \ 14 } \ 15 } while (0) 16 17 #define ltk_timespecsub(tsp, usp, vsp) \ 18 do { \ 19 (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \ 20 (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \ 21 if ((vsp)->tv_nsec < 0) { \ 22 (vsp)->tv_sec--; \ 23 (vsp)->tv_nsec += 1000000000L; \ 24 } \ 25 } while (0) 26 27 #endif