瀏覽代碼

Add a portable tor_timercmp

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
Nick Mathewson 15 年之前
父節點
當前提交
94a99ad205
共有 1 個文件被更改,包括 7 次插入0 次删除
  1. 7 0
      src/common/compat.h

+ 7 - 0
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);