diff options
author | Dan McGee <dpmcgee@gmail.com> | 2011-11-21 00:10:16 -0600 |
---|---|---|
committer | Dan McGee <dpmcgee@gmail.com> | 2011-11-21 00:10:16 -0600 |
commit | 7c2808a72206fa5efff26d82e2bbd0457f3bfbbd (patch) | |
tree | cbf943167782efc06dbe2f61e3c7e1c0aa6d1262 /util.c | |
parent | 1de53f23da464e3bef10206d0bcbbfdd156b8e31 (diff) | |
download | onkyocontrol-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.c | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -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: */ |