From c8373f1649c6be010729122025f78f2c62edccb5 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Fri, 16 Sep 2016 10:01:37 +0200 Subject: [PATCH] util: add UTI_IsZeroTimespec() --- ntp_core.c | 4 ++-- refclock_pps.c | 2 +- util.c | 8 ++++++++ util.h | 3 +++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/ntp_core.c b/ntp_core.c index c61d4a6..c8e01c9 100644 --- a/ntp_core.c +++ b/ntp_core.c @@ -1770,9 +1770,9 @@ NCR_SlewTimes(NCR_Instance inst, struct timespec *when, double dfreq, double dof { double delta; - if (inst->local_rx.tv_sec || inst->local_rx.tv_nsec) + if (!UTI_IsZeroTimespec(&inst->local_rx)) UTI_AdjustTimespec(&inst->local_rx, when, &inst->local_rx, &delta, dfreq, doffset); - if (inst->local_tx.tv_sec || inst->local_tx.tv_nsec) + if (!UTI_IsZeroTimespec(&inst->local_tx)) UTI_AdjustTimespec(&inst->local_tx, when, &inst->local_tx, &delta, dfreq, doffset); } diff --git a/refclock_pps.c b/refclock_pps.c index 1005ade..e06d8db 100644 --- a/refclock_pps.c +++ b/refclock_pps.c @@ -145,7 +145,7 @@ static int pps_poll(RCL_Instance instance) ts = pps_info.clear_timestamp; } - if (seq == pps->last_seq || (ts.tv_sec == 0 && ts.tv_nsec == 0)) { + if (seq == pps->last_seq || UTI_IsZeroTimespec(&ts)) { DEBUG_LOG(LOGF_Refclock, "PPS sample ignored seq=%lu ts=%lu.%09lu", seq, ts.tv_sec, ts.tv_nsec); return 0; diff --git a/util.c b/util.c index d380038..a054b79 100644 --- a/util.c +++ b/util.c @@ -47,6 +47,14 @@ UTI_ZeroTimespec(struct timespec *ts) /* ================================================== */ +int +UTI_IsZeroTimespec(struct timespec *ts) +{ + return !ts->tv_sec && !ts->tv_nsec; +} + +/* ================================================== */ + void UTI_TimevalToTimespec(struct timeval *tv, struct timespec *ts) { diff --git a/util.h b/util.h index 72d520d..2f2332a 100644 --- a/util.h +++ b/util.h @@ -37,6 +37,9 @@ /* Zero a timespec */ extern void UTI_ZeroTimespec(struct timespec *ts); +/* Check if a timespec is zero */ +extern int UTI_IsZeroTimespec(struct timespec *ts); + /* Convert a timeval into a timespec */ extern void UTI_TimevalToTimespec(struct timeval *tv, struct timespec *ts);