[or-cvs] [tor/master 1/2] Add a portable tor_timercmp

nickm at torproject.org nickm at torproject.org
Fri Oct 15 16:34:32 UTC 2010


Author: Nick Mathewson <nickm at torproject.org>
Date: Fri, 15 Oct 2010 12:32:19 -0400
Subject: Add a portable tor_timercmp
Commit: 94a99ad205665bc387831de37566b9cb16d40397

We can't use the platform timercmp, because
  1) some platforms don't have them
  2) some that do have them only support certain relational operators
---
 src/common/compat.h |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/src/common/compat.h b/src/common/compat.h
index 5b6cfc4..2471e6b 100644
--- a/src/common/compat.h
+++ b/src/common/compat.h
@@ -332,6 +332,13 @@ struct tm *tor_localtime_r(const time_t *timep, struct tm *result);
 struct tm *tor_gmtime_r(const time_t *timep, struct tm *result);
 #endif
 
+/** Return true iff the tvp is related to uvp according to the relational
+ * operator cmp.  Recognized values for cmp are ==, <=, <, >=, and >. */
+#define tor_timercmp(tvp, uvp, cmp)                                     \
+  (((tvp)->tv_sec == (uvp)->tv_sec) ?                                   \
+   ((tvp)->tv_usec cmp  (uvp)->tv_usec) :                               \
+   ((tvp)->tv_sec cmp  (uvp)->tv_sec))
+
 /* ===== File compatibility */
 int replace_file(const char *from, const char *to);
 int touch_file(const char *fname);
-- 
1.7.1




More information about the tor-commits mailing list