summaryrefslogtreecommitdiff
path: root/lib/util/time.c
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2010-09-14 14:53:17 -0700
committerJeremy Allison <jra@samba.org>2010-09-14 14:53:17 -0700
commit0b270f014f67b8ff49b70fb41b2cceac121f337e (patch)
treec9641065c49bd40a017f58020aacf8e28fb0d6e6 /lib/util/time.c
parent55b315094ef8a8ed691f9717c28cab301e17ef25 (diff)
downloadsamba-0b270f014f67b8ff49b70fb41b2cceac121f337e.tar.gz
samba-0b270f014f67b8ff49b70fb41b2cceac121f337e.tar.bz2
samba-0b270f014f67b8ff49b70fb41b2cceac121f337e.zip
Ensure incoming timespec values correctly wrap at nsecs.
Jeremy.
Diffstat (limited to 'lib/util/time.c')
-rw-r--r--lib/util/time.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/util/time.c b/lib/util/time.c
index ed3b4f8e30..6fbeb9749a 100644
--- a/lib/util/time.c
+++ b/lib/util/time.c
@@ -91,8 +91,15 @@ _PUBLIC_ time_t time_mono(time_t *t)
time_t convert_timespec_to_time_t(struct timespec ts)
{
+ /* Ensure tv_nsec is less than 1sec. */
+ while (ts.tv_nsec > 1000000000) {
+ ts.tv_sec += 1;
+ ts.tv_nsec -= 1000000000;
+ }
+
/* 1 ns == 1,000,000,000 - one thousand millionths of a second.
increment if it's greater than 500 millionth of a second. */
+
if (ts.tv_nsec > 500000000) {
return ts.tv_sec + 1;
}