From 75362a768be4a15953e4a30314ec695174049ef2 Mon Sep 17 00:00:00 2001 From: Ranjith Kumaran Date: Mon, 15 May 2000 18:30:03 +0000 Subject: [PATCH] Mon May 15 14:26:00 2000 Joel Sherrill * libc/sys/rtems/sys/time.h: Add macros for manipulating timeval structures. --- newlib/ChangeLog | 5 +++++ newlib/libc/sys/rtems/sys/time.h | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/newlib/ChangeLog b/newlib/ChangeLog index 548895597..735c47d05 100644 --- a/newlib/ChangeLog +++ b/newlib/ChangeLog @@ -1,3 +1,8 @@ +Mon May 15 14:26:00 2000 Joel Sherrill + + * libc/sys/rtems/sys/time.h: Add macros for manipulating timeval + structures. + Wed May 10 19:24:53 2000 Jim Wilson * libc/include/machine/ieeefp.h: Add ia64 support. diff --git a/newlib/libc/sys/rtems/sys/time.h b/newlib/libc/sys/rtems/sys/time.h index 596ec5730..ea3325772 100644 --- a/newlib/libc/sys/rtems/sys/time.h +++ b/newlib/libc/sys/rtems/sys/time.h @@ -65,6 +65,33 @@ int gettimeofday( struct timezone *tzp ); +/* Convenience macros for operations on timevals. + NOTE: `timercmp' does not work for >= or <=. */ +#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) +#define timerclear(tvp) ((tvp)->tv_sec = (tvp)->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)) +#define timeradd(a, b, result) \ + do { \ + (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \ + (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \ + if ((result)->tv_usec >= 1000000) \ + { \ + ++(result)->tv_sec; \ + (result)->tv_usec -= 1000000; \ + } \ + } while (0) +#define timersub(a, b, result) \ + do { \ + (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ + (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ + if ((result)->tv_usec < 0) { \ + --(result)->tv_sec; \ + (result)->tv_usec += 1000000; \ + } \ + } while (0) #ifdef __cplusplus } #endif