summaryrefslogtreecommitdiff
path: root/src/lib/time_utils.c
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@ugent.be>2017-07-09 10:35:34 +0000
committerSander Vrijders <sander.vrijders@ugent.be>2017-07-09 10:35:34 +0000
commit2a395ba451601edb746cfdec1e3d8f260795c765 (patch)
tree2a9c320acb016c9257d96328a07d7b8f00be0190 /src/lib/time_utils.c
parent640d8227c9120c12838d68c3985db26ffa19b74b (diff)
parent3ca06069e72a0f4b98865732c022acd7d63a1057 (diff)
downloadouroboros-2a395ba451601edb746cfdec1e3d8f260795c765.tar.gz
ouroboros-2a395ba451601edb746cfdec1e3d8f260795c765.zip
Merged in dstaesse/ouroboros/be-time (pull request #522)
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);