From 2753f93e5d9cd5fbd773540de3772d182fcced5e Mon Sep 17 00:00:00 2001 From: Stephan Bosch Date: Wed, 1 Oct 2014 00:06:19 +0300 Subject: [PATCH] lib: Added support for adding milliseconds to struct timeval time values. --- src/lib/time-util.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/lib/time-util.h b/src/lib/time-util.h index 2738a74f1a..637fb5cc3d 100644 --- a/src/lib/time-util.h +++ b/src/lib/time-util.h @@ -11,6 +11,28 @@ int timeval_diff_msecs(const struct timeval *tv1, const struct timeval *tv2); long long timeval_diff_usecs(const struct timeval *tv1, const struct timeval *tv2); +static inline void +timeval_add_msecs(struct timeval *tv, unsigned int msecs) +{ + tv->tv_sec += msecs / 1000; + tv->tv_usec += (msecs % 1000) * 1000; + if (tv->tv_usec >= 1000000) { + tv->tv_sec++; + tv->tv_usec -= 1000000; + } +} + +static inline void +timeval_sub_msecs(struct timeval *tv, unsigned int msecs) +{ + tv->tv_sec -= msecs / 1000; + tv->tv_usec -= (msecs % 1000) * 1000; + if (tv->tv_usec < 0) { + tv->tv_sec--; + tv->tv_usec += 1000000; + } +} + /* Wrapper to strftime() */ const char *t_strflocaltime(const char *fmt, time_t t) ATTR_STRFTIME(1); -- 2.47.3