summaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
authorDan McGee <dpmcgee@gmail.com>2011-11-21 00:10:16 -0600
committerDan McGee <dpmcgee@gmail.com>2011-11-21 00:10:16 -0600
commit7c2808a72206fa5efff26d82e2bbd0457f3bfbbd (patch)
treecbf943167782efc06dbe2f61e3c7e1c0aa6d1262 /util.c
parent1de53f23da464e3bef10206d0bcbbfdd156b8e31 (diff)
downloadonkyocontrol-7c2808a72206fa5efff26d82e2bbd0457f3bfbbd.tar.gz
onkyocontrol-7c2808a72206fa5efff26d82e2bbd0457f3bfbbd.zip
Fix some faulty timeval related math and comparisons
Add a timeval_positive helper function that doesn't get confused when tv_usec is set to 0 (regardless of the value of tv_sec). Use it wherever possible, and also attempt to reason through our other time value comparison points to ensure all values are being handled correctly, especially those that result in a zero in a field or a zero difference. Signed-off-by: Dan McGee <dpmcgee@gmail.com>
Diffstat (limited to 'util.c')
-rw-r--r--util.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/util.c b/util.c
index b571d32..0e16b5f 100644
--- a/util.c
+++ b/util.c
@@ -116,4 +116,14 @@ struct timeval timeval_min(struct timeval *restrict a,
return a->tv_usec < b->tv_usec ? *a : *b;
}
+int timeval_positive(struct timeval *tv)
+{
+ if(tv->tv_sec > 0)
+ return 1;
+ if(tv->tv_sec == 0 && tv->tv_usec > 0)
+ return 1;
+
+ return 0;
+}
+
/* vim: set ts=4 sw=4 noet: */