From 1bc2fbc25d69fce480a5bec31966d9d124edade5 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sun, 30 Mar 2008 17:28:31 +0000 Subject: [PATCH] Added BSDish timer*() macros. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24683 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/posix/sys/time.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/headers/posix/sys/time.h b/headers/posix/sys/time.h index 99d03514be..9e8fa67fc1 100644 --- a/headers/posix/sys/time.h +++ b/headers/posix/sys/time.h @@ -49,4 +49,28 @@ extern int utimes(const char *name, const struct timeval times[2]); } #endif +/* BSDish macros operating on timeval structs */ +#define timeradd(a, b, res) \ + do { \ + (res)->tv_sec = (a)->tv_sec + (b)->tv_sec; \ + (res)->tv_usec = (a)->tv_usec + (b)->tv_usec; \ + if ((res)->tv_usec >= 1000000) { \ + (res)->tv_usec -= 1000000; \ + (res)->tv_sec++; \ + } \ + } while (0) +#define timersub(a, b, res) \ + do { \ + (res)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ + (res)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ + if ((res)->tv_usec < 0) { \ + (res)->tv_usec += 1000000; \ + (res)->tv_sec--; \ + } \ + } while (0) +#define timerclear(a) ((a)->tv_sec = (a)->tv_usec = 0) +#define timerisset(a) ((a)->tv_sec != 0 || (a)->tv_usec != 0) +#define timercmp(a, b, cmp) ((a)->tv_sec == (b)->tv_sec \ + ? (a)->tv_usec cmp (b)->tv_usec : (a)->tv_sec cmp (b)->tv_sec) + #endif /* _SYS_TIME_H */