From 3ca06069e72a0f4b98865732c022acd7d63a1057 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Wed, 5 Jul 2017 12:54:01 +0200 Subject: lib: Fix bug and add test for time_utils --- src/lib/time_utils.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/lib/time_utils.c') diff --git a/src/lib/time_utils.c b/src/lib/time_utils.c index 97e97b09..07994af2 100644 --- a/src/lib/time_utils.c +++ b/src/lib/time_utils.c @@ -32,7 +32,7 @@ int ts_add(const struct timespec * t, const struct timespec * intv, struct timespec * res) { - long nanos = 0; + time_t nanos = 0; if (t == NULL || intv == NULL || res == NULL) return -1; @@ -44,6 +44,7 @@ int ts_add(const struct timespec * t, nanos -= BILLION; ++(res->tv_sec); } + res->tv_nsec = nanos; return 0; @@ -54,7 +55,7 @@ int ts_diff(const struct timespec * t, const struct timespec * intv, struct timespec * res) { - long nanos = 0; + time_t nanos = 0; if (t == NULL || intv == NULL || res == NULL) return -1; @@ -78,7 +79,7 @@ int tv_add(const struct timeval * t, const struct timeval * intv, struct timeval * res) { - long micros = 0; + time_t micros = 0; if (t == NULL || intv == NULL || res == NULL) return -1; @@ -88,7 +89,7 @@ int tv_add(const struct timeval * t, res->tv_sec = t->tv_sec + intv->tv_sec; while (micros >= MILLION) { micros -= MILLION; - --(res->tv_sec); + ++(res->tv_sec); } res->tv_usec = micros; @@ -100,7 +101,7 @@ int tv_diff(const struct timeval * t, const struct timeval * intv, struct timeval * res) { - long micros = 0; + time_t micros = 0; if (t == NULL || intv == NULL || res == NULL) return -1; @@ -143,7 +144,8 @@ int ts_to_tv(const struct timespec * src, } #ifdef __APPLE__ -int clock_gettime(int clock, struct timespec * t) +int clock_gettime(int clock, + struct timespec * t) { struct timeval tv; int ret = gettimeofday(&tv, NULL); -- cgit v1.2.3