Browse Source

Handy TIMEVAL_USECS macro

Luke Dashjr 13 years ago
parent
commit
0eceebfca3
1 changed files with 8 additions and 4 deletions
  1. 8 4
      util.h

+ 8 - 4
util.h

@@ -96,11 +96,15 @@ void set_maxfd(int *p_maxfd, int fd)
 }
 
 
+#define TIMEVAL_USECS(usecs)  (  \
+	(struct timeval){  \
+		.tv_sec = (usecs) / 1000000,  \
+		.tv_usec = (usecs) % 1000000,  \
+	}  \
+)
+
 #define timer_set_delay(tvp_timer, tvp_now, usecs)  do {  \
-	struct timeval tv_add = {  \
-		.tv_sec = usecs / 1000000,  \
-		.tv_usec = usecs % 1000000,  \
-	};  \
+	struct timeval tv_add = TIMEVAL_USECS(usecs);  \
 	timeradd(&tv_add, tvp_now, tvp_timer);  \
 } while(0)