From bb4bbb53342d66217edfd1ab165fa1a338df4366 Mon Sep 17 00:00:00 2001 From: rob Date: Sat, 10 Nov 2007 21:31:52 +0000 Subject: [PATCH] convenience macros for working with timevals. stolen from freebsd git-svn-id: https://svn.aros.org:8080/svn/aros/trunk/AROS@27177 fb15a70f-31f2-0310-bbcc-cdcc74a49acc --- compiler/clib/include/sys/time.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/compiler/clib/include/sys/time.h b/compiler/clib/include/sys/time.h index 9473de0f6..f64eb6800 100644 --- a/compiler/clib/include/sys/time.h +++ b/compiler/clib/include/sys/time.h @@ -49,6 +49,31 @@ struct timezone #define DST_TUR 9 /* Turkish style. */ #define DST_AUSTALT 10 /* Alternate Australian style. */ +/* Convenience macros for working with timevals */ +#define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0) +#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) +#define timercmp(tvp, uvp, cmp) \ + (((tvp)->tv_sec == (uvp)->tv_sec) ? \ + ((tvp)->tv_usec cmp (uvp)->tv_usec) : \ + ((tvp)->tv_sec cmp (uvp)->tv_sec)) +#define timeradd(tvp, uvp, vvp) \ + do { \ + (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \ + (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \ + if ((vvp)->tv_usec >= 1000000) { \ + (vvp)->tv_sec++; \ + (vvp)->tv_usec -= 1000000; \ + } \ + } while (0) +#define timersub(tvp, uvp, vvp) \ + do { \ + (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ + (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \ + if ((vvp)->tv_usec < 0) { \ + (vvp)->tv_sec--; \ + (vvp)->tv_usec += 1000000; \ + } \ + } while (0) __BEGIN_DECLS -- 2.11.4.GIT