summaryrefslogtreecommitdiff
path: root/src/common/compat.h
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2010-10-15 12:32:19 -0400
committerNick Mathewson <nickm@torproject.org>2010-10-15 12:35:05 -0400
commit94a99ad205665bc387831de37566b9cb16d40397 (patch)
tree78d192032380fac7da9485dbed07ec1e78f27bf7 /src/common/compat.h
parent9516c1efdb723bba64dc9dfcc71aa64a48079fb3 (diff)
downloadtor-94a99ad205665bc387831de37566b9cb16d40397.tar.gz
tor-94a99ad205665bc387831de37566b9cb16d40397.zip
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
Diffstat (limited to 'src/common/compat.h')
-rw-r--r--src/common/compat.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/common/compat.h b/src/common/compat.h
index 5b6cfc40b5..2471e6b830 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);