RTEMS time.h additions
Eric Norum
eric@cls.usask.ca
Thu Apr 27 11:58:00 GMT 2000
Joel Sherrill (joel@oarcorp.com) asked me to forward this to you.
Attached is a patch to rtems/sys/time.h in newlib. It just adds some
convenience macros for manipulating timeval structures. These macros
are now a standard part of FreeBSD so I'd like to have them part of
newlib, too.
--
Eric Norum eric@cls.usask.ca
Canadian Light Source Phone: (306) 966-6308
University of Saskatchewan FAX: (306) 966-6058
Saskatoon, Canada.
diff -ur /tmp/rttools/newlib-1.8.2/newlib/libc/sys/rtems/sys/time.h newlib-1.8.2/newlib/libc/sys/rtems/sys/time.h
--- /tmp/rttools/newlib-1.8.2/newlib/libc/sys/rtems/sys/time.h Thu Nov 18 16:34:26 1999
+++ newlib-1.8.2/newlib/libc/sys/rtems/sys/time.h Sun Apr 23 12:08:59 2000
@@ -65,6 +65,33 @@
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
More information about the Newlib
mailing list