]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Added support for adding milliseconds to struct timeval time values.
authorStephan Bosch <stephan@rename-it.nl>
Tue, 30 Sep 2014 21:06:19 +0000 (00:06 +0300)
committerStephan Bosch <stephan@rename-it.nl>
Tue, 30 Sep 2014 21:06:19 +0000 (00:06 +0300)
src/lib/time-util.h

index 2738a74f1a4a1dbeb924cc9c866cbd46b7f1689f..637fb5cc3dcf27b8314a9ebf648865fec47d3635 100644 (file)
@@ -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);