summaryrefslogtreecommitdiff
path: root/src/lib/time_utils.c
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@ugent.be>2017-07-05 12:54:01 +0200
committerdimitri staessens <dimitri.staessens@ugent.be>2017-07-05 12:54:01 +0200
commit3ca06069e72a0f4b98865732c022acd7d63a1057 (patch)
tree2a9c320acb016c9257d96328a07d7b8f00be0190 /src/lib/time_utils.c
parentfb36128c20efd34067bbcee4f78289671dcd9bd1 (diff)
downloadouroboros-3ca06069e72a0f4b98865732c022acd7d63a1057.tar.gz
ouroboros-3ca06069e72a0f4b98865732c022acd7d63a1057.zip
lib: Fix bug and add test for time_utils
Diffstat (limited to 'src/lib/time_utils.c')
-rw-r--r--src/lib/time_utils.c14
1 files changed, 8 insertions, 6 deletions
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);