From: Stephan Bosch Date: Tue, 30 Sep 2014 21:06:19 +0000 (+0300) Subject: lib: Added support for adding milliseconds to struct timeval time values. X-Git-Tag: 2.2.14.rc1~16 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2753f93e5d9cd5fbd773540de3772d182fcced5e;p=thirdparty%2Fdovecot%2Fcore.git lib: Added support for adding milliseconds to struct timeval time values. --- 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);