From 56e72337b01216dc7cba418f040a5cc928e5fc6f Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 1 Jun 2011 11:21:15 +0930 Subject: lib/util/time.c: timeval_current_ofs_msec Several places want "milliseconds from current time", and several were simply doing "msec * 1000" which can (and does in one place) result in a usec value over 1 a million. Using a helper to do this is safer and more readable. Signed-off-by: Rusty Russell --- lib/util/time.c | 9 +++++++++ lib/util/time.h | 5 +++++ 2 files changed, 14 insertions(+) (limited to 'lib/util') diff --git a/lib/util/time.c b/lib/util/time.c index 4843fc9697..de1553aff8 100644 --- a/lib/util/time.c +++ b/lib/util/time.c @@ -579,6 +579,15 @@ _PUBLIC_ struct timeval timeval_current_ofs(uint32_t secs, uint32_t usecs) return timeval_add(&tv, secs, usecs); } +/** + return a timeval milliseconds into the future +*/ +_PUBLIC_ struct timeval timeval_current_ofs_msec(uint32_t msecs) +{ + struct timeval tv = timeval_current(); + return timeval_add(&tv, msecs / 1000, (msecs % 1000) * 1000); +} + /** compare two timeval structures. Return -1 if tv1 < tv2 diff --git a/lib/util/time.h b/lib/util/time.h index 3a406340f4..4e4f72f71f 100644 --- a/lib/util/time.h +++ b/lib/util/time.h @@ -212,6 +212,11 @@ struct timeval timeval_sum(const struct timeval *tv1, */ _PUBLIC_ struct timeval timeval_current_ofs(uint32_t secs, uint32_t usecs); +/** + return a timeval milliseconds into the future +*/ +_PUBLIC_ struct timeval timeval_current_ofs_msec(uint32_t msecs); + /** compare two timeval structures. Return -1 if tv1 < tv2 -- cgit