options/posix: Add some time related macros
@@ -22,13 +22,25 @@ void timeradd(struct timeval *a, struct timeval *b, struct timeval *res);
void timersub(struct timeval *a, struct timeval *b, struct timeval *res);
void timerclear(struct timeval *tvp);
int timerisset(struct timeval *tvp);
-//TODO: implement timercmp as a macro
-//int timercmp(struct timeval *a, struct timeval *b, CMP);
+
+// timercmp taken from musl
+#define timercmp(s,t,op) ((s)->tv_sec == (t)->tv_sec ? \
+ (s)->tv_usec op (t)->tv_usec : (s)->tv_sec op (t)->tv_sec)
int getitimer(int which, struct itimerval *curr_value);
int setitimer(int which, const struct itimerval *new_value,
struct itimerval *old_value);
+// The following 2 macros are taken from musl
+#define TIMEVAL_TO_TIMESPEC(tv, ts) ( \
+ (ts)->tv_sec = (tv)->tv_sec, \
+ (ts)->tv_nsec = (tv)->tv_usec * 1000, \
+ (void)0 )
+#define TIMESPEC_TO_TIMEVAL(tv, ts) ( \
+ (tv)->tv_sec = (ts)->tv_sec, \
+ (tv)->tv_usec = (ts)->tv_nsec / 1000, \
+ (void)0 )
+
#ifdef __cplusplus
}
#endif
