+* [Bug 2570] cleanup: reduced logging noise, moved some functions
+ into libntp.
(4.2.7p434) 2014/03/21 Released by Harlan Stenn <stenn@ntp.org>
* [Bug 2577] Update VS2013 solution and project files.
(4.2.7p433) 2014/03/10 Released by Harlan Stenn <stenn@ntp.org>
timetoa.h \
timevalops.h \
trimble.h \
+ vint64ops.h \
$(NULL)
extern int32_t
ntpcal_periodic_extend(int32_t pivot, int32_t value, int32_t cycle);
+extern int
+ntpcal_ntp64_to_date(struct calendar *jd, const vint64 *ntp);
+
extern int
ntpcal_ntp_to_date(struct calendar *jd, uint32_t ntp, const time_t *pivot);
+extern vint64
+ntpcal_date_to_ntp64(const struct calendar *jd);
+
extern uint32_t
ntpcal_date_to_ntp(const struct calendar *jd);
extern ntpcal_split
isocal_split_eraweeks(int32_t weeks);
+extern int
+isocal_ntp64_to_date(struct isodate *id, const vint64 *ntp);
+
extern int
isocal_ntp_to_date(struct isodate *id, uint32_t ntp, const time_t *pivot);
+extern vint64
+isocal_date_to_ntp64(const struct isodate *id);
+
extern uint32_t
isocal_date_to_ntp(const struct isodate *id);
--- /dev/null
+/*
+ * vint64ops.h - operations on 'vint64' values
+ *
+ * Written by Juergen Perlinger (perlinger@ntp.org) for the NTP project.
+ * The contents of 'html/copyright.html' apply.
+ * ----------------------------------------------------------------------
+ * This is an attempt to get the vint64 calculations stuff centralised.
+ */
+#ifndef VINT64OPS_H
+#define VINT64OPS_H
+
+/* signed/unsigned compare. returns 1/0/-1 if lhs >/=/< rhs */
+extern int icmpv64(const vint64 * lhs, const vint64 * rhs);
+extern int ucmpv64(const vint64 * lhs, const vint64 * rhs);
+
+/* add / subtract */
+extern vint64 addv64(const vint64 *lhs, const vint64 *rhs);
+extern vint64 addv64i32(const vint64 * lhs, int32_t rhs);
+extern vint64 addv64u32(const vint64 * lhs, uint32_t rhs);
+
+extern vint64 subv64(const vint64 *lhs, const vint64 *rhs);
+extern vint64 subv64i32(const vint64 * lhs, int32_t rhs);
+extern vint64 subv64u32(const vint64 * lhs, uint32_t rhs);
+
+/* parsing. works like strtoul() or strtoull() */
+extern vint64 strtouv64(const char * begp, char ** endp, int base);
+
+#endif /*!defined(VINT64OPS_H)*/
timetoa.c \
timevalops.c \
uglydate.c \
+ vint64ops.c \
work_fork.c \
work_thread.c \
ymd2yd.c \
*
* ==================================================================
*/
+int
+ntpcal_ntp64_to_date(
+ struct calendar *jd,
+ const vint64 *ntp
+ )
+{
+ ntpcal_split ds;
+
+ ds = ntpcal_daysplit(ntp);
+ ds.hi += ntpcal_daysec_to_date(jd, ds.lo);
+
+ return ntpcal_rd_to_date(jd, ds.hi + DAY_NTP_STARTS);
+}
+
int
ntpcal_ntp_to_date(
struct calendar *jd,
const time_t *piv
)
{
- vint64 vl;
- ntpcal_split ds;
+ vint64 ntp64;
/*
* Unfold ntp time around current time into NTP domain. Split
* into days and seconds, shift days into CE domain and
* process the parts.
*/
- vl = ntpcal_ntp_to_ntp(ntp, piv);
- ds = ntpcal_daysplit(&vl);
- ds.hi += ntpcal_daysec_to_date(jd, ds.lo);
+ ntp64 = ntpcal_ntp_to_ntp(ntp, piv);
+ return ntpcal_ntp64_to_date(jd, &ntp64);
+}
- return ntpcal_rd_to_date(jd, ds.hi + DAY_NTP_STARTS);
+
+vint64
+ntpcal_date_to_ntp64(
+ const struct calendar *jd
+ )
+{
+ /*
+ * Convert date to NTP. Ignore yearday, use d/m/y only.
+ */
+ return ntpcal_dayjoin(ntpcal_date_to_rd(jd) - DAY_NTP_STARTS,
+ ntpcal_date_to_daysec(jd));
}
)
{
/*
- * Convert date to NTP. Ignore yearday, use d/m/y only.
+ * Get lower half of 64-bit NTP timestamp from date/time.
*/
- return ntpcal_dayjoin(ntpcal_date_to_rd(jd) - DAY_NTP_STARTS,
- ntpcal_date_to_daysec(jd)).d_s.lo;
+ return ntpcal_date_to_ntp64(jd).d_s.lo;
}
+
+
/*
* ==================================================================
*
* stamp.
*/
int
-isocal_ntp_to_date(
+isocal_ntp64_to_date(
struct isodate *id,
- uint32_t ntp,
- const time_t *piv
+ const vint64 *ntp
)
{
- vint64 vl;
ntpcal_split ds;
int32_t ts[3];
/*
- * Unfold ntp time around current time into NTP domain. Split
- * into days and seconds, shift days into CE domain and
- * process the parts.
+ * Split NTP time into days and seconds, shift days into CE
+ * domain and process the parts.
*/
- vl = ntpcal_ntp_to_ntp(ntp, piv);
- ds = ntpcal_daysplit(&vl);
+ ds = ntpcal_daysplit(ntp);
/* split time part */
ds.hi += priv_timesplit(ts, ds.lo);
return (ds.hi >= 0 && ds.hi < 0xFFFFU);
}
+int
+isocal_ntp_to_date(
+ struct isodate *id,
+ uint32_t ntp,
+ const time_t *piv
+ )
+{
+ vint64 ntp64;
+
+ /*
+ * Unfold ntp time around current time into NTP domain, then
+ * convert the full time stamp.
+ */
+ ntp64 = ntpcal_ntp_to_ntp(ntp, piv);
+ return isocal_ntp64_to_date(id, &ntp64);
+}
+
/*
* Convert a ISO date spec into a second in the NTP time scale,
* properly truncated to 32 bit.
*/
-uint32_t
-isocal_date_to_ntp(
+vint64
+isocal_date_to_ntp64(
const struct isodate *id
)
{
/* days is RDN of ISO date now */
secs = ntpcal_etime_to_seconds(id->hour, id->minute, id->second);
- return ntpcal_dayjoin(days - DAY_NTP_STARTS, secs).d_s.lo;
+ return ntpcal_dayjoin(days - DAY_NTP_STARTS, secs);
+}
+
+uint32_t
+isocal_date_to_ntp(
+ const struct isodate *id
+ )
+{
+ /*
+ * Get lower half of 64-bit NTP timestamp from date/time.
+ */
+ return isocal_date_to_ntp64(id).d_s.lo;
}
/* -*-EOF-*- */
--- /dev/null
+/*
+ * vint64ops.c - operations on 'vint64' values
+ *
+ * Written by Juergen Perlinger (perlinger@ntp.org) for the NTP project.
+ * The contents of 'html/copyright.html' apply.
+ * ----------------------------------------------------------------------
+ * This is an attempt to get the vint64 calculations stuff centralised.
+ */
+
+#include <config.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+#include <errno.h>
+
+#include "ntp_types.h"
+#include "ntp_fp.h"
+#include "vint64ops.h"
+
+/* ---------------------------------------------------------------------
+ * GCC is rather sticky with its 'const' attribute. We have to do it more
+ * explicit than with a cast if we want to get rid of a CONST qualifier.
+ * Greetings from the PASCAL world, where casting was only possible via
+ * untagged unions...
+ */
+static inline void*
+noconst(
+ const void* ptr
+ )
+{
+ union {
+ const void * cp;
+ void * vp;
+ } tmp;
+ tmp.cp = ptr;
+ return tmp.vp;
+}
+
+/* -------------------------------------------------------------------------*/
+
+vint64
+strtouv64(
+ const char * begp,
+ char ** endp,
+ int base
+ )
+{
+ vint64 res;
+ u_char digit;
+ int sig, num;
+ const u_char *src;
+
+ num = sig = 0;
+ src = (const u_char*)begp;
+ while (isspace(*src))
+ src++;
+
+ if (*src == '-') {
+ src++;
+ sig = 1;
+ } else if (*src == '+') {
+ src++;
+ }
+
+ if (base == 0) {
+ base = 10;
+ if (*src == '0') {
+ base = 8;
+ if (toupper(*++src) == 'X') {
+ src++;
+ base = 16;
+ }
+ }
+ } else if (base == 16) { /* remove optional leading '0x' or '0X' */
+ if (src[0] == '0' && toupper(src[1]) == 'X')
+ src += 2;
+ } else if (base <= 2 || base > 36) {
+ memset(&res, 0xFF, sizeof(res));
+ errno = ERANGE;
+ return res;
+ }
+
+ memset(&res, 0, sizeof(res));
+ while (*src) {
+ if (isdigit(*src))
+ digit = *src - '0';
+ else if (isupper(*src))
+ digit = *src - 'A' + 10;
+ else if (islower(*src))
+ digit = *src - 'a' + 10;
+ else
+ break;
+ if (digit >= base)
+ break;
+ num = 1;
+#if defined(HAVE_INT64)
+ res.Q_s = res.Q_s * base + digit;
+#else
+ /* res *= base, using 16x16->32 bit
+ * multiplication. Slow but portable.
+ */
+ {
+ uint32_t accu;
+ accu = (uint32_t)res.W_s.ll * base;
+ res.W_s.ll = (uint16_t)accu;
+ accu = (accu >> 16)
+ + (uint32_t)res.W_s.lh * base;
+ res.W_s.lh = (uint16_t)accu;
+ /* the upper bits can be done in one step: */
+ res.D_s.hi = res.D_s.hi * base + (accu >> 16);
+ }
+ M_ADD(res.D_s.hi, res.D_s.lo, 0, digit);
+#endif
+ src++;
+ }
+ if (!num)
+ errno = EINVAL;
+ if (endp)
+ *endp = (char*)noconst(src);
+ if (sig)
+ M_NEG(res.D_s.hi, res.D_s.lo);
+ return res;
+}
+
+/* -------------------------------------------------------------------------*/
+
+int
+icmpv64(
+ const vint64 * lhs,
+ const vint64 * rhs
+ )
+{
+ int res;
+
+#if defined(HAVE_INT64)
+ res = (lhs->q_s > rhs->q_s)
+ - (lhs->q_s < rhs->q_s);
+#else
+ res = (lhs->d_s.hi > rhs->d_s.hi)
+ - (lhs->d_s.hi < rhs->d_s.hi);
+ if ( ! res )
+ res = (lhs->D_s.lo > rhs->D_s.lo)
+ - (lhs->D_s.lo < rhs->D_s.lo);
+#endif
+
+ return res;
+}
+
+/* -------------------------------------------------------------------------*/
+
+int
+ucmpv64(
+ const vint64 * lhs,
+ const vint64 * rhs
+ )
+{
+ int res;
+
+#if defined(HAVE_INT64)
+ res = (lhs->Q_s > rhs->Q_s)
+ - (lhs->Q_s < rhs->Q_s);
+#else
+ res = (lhs->D_s.hi > rhs->D_s.hi)
+ - (lhs->D_s.hi < rhs->D_s.hi);
+ if ( ! res )
+ res = (lhs->D_s.lo > rhs->D_s.lo)
+ - (lhs->D_s.lo < rhs->D_s.lo);
+#endif
+ return res;
+}
+
+/* -------------------------------------------------------------------------*/
+
+vint64
+addv64(
+ const vint64 *lhs,
+ const vint64 *rhs
+ )
+{
+ vint64 res;
+
+#if defined(HAVE_INT64)
+ res.Q_s = lhs->Q_s + rhs->Q_s;
+#else
+ res = *lhs;
+ M_ADD(res.D_s.hi, res.D_s.lo, rhs->D_s.hi, rhs->D_s.lo);
+#endif
+ return res;
+}
+
+/* -------------------------------------------------------------------------*/
+
+vint64
+subv64(
+ const vint64 *lhs,
+ const vint64 *rhs
+ )
+{
+ vint64 res;
+
+#if defined(HAVE_INT64)
+ res.Q_s = lhs->Q_s - rhs->Q_s;
+#else
+ res = *lhs;
+ M_SUB(res.D_s.hi, res.D_s.lo, rhs->D_s.hi, rhs->D_s.lo);
+#endif
+ return res;
+}
+
+/* -------------------------------------------------------------------------*/
+
+vint64
+addv64i32(
+ const vint64 * lhs,
+ int32_t rhs
+ )
+{
+ vint64 res;
+
+ res = *lhs;
+#if defined(HAVE_INT64)
+ res.q_s += rhs;
+#else
+ M_ADD(res.D_s.hi, res.D_s.lo, -(rhs < 0), rhs);
+#endif
+ return res;
+}
+
+/* -------------------------------------------------------------------------*/
+
+vint64
+subv64i32(
+ const vint64 * lhs,
+ int32_t rhs
+ )
+{
+ vint64 res;
+
+ res = *lhs;
+#if defined(HAVE_INT64)
+ res.q_s -= rhs;
+#else
+ M_SUB(res.D_s.hi, res.D_s.lo, -(rhs < 0), rhs);
+#endif
+ return res;
+}
+
+/* -------------------------------------------------------------------------*/
+
+vint64
+addv64u32(
+ const vint64 * lhs,
+ uint32_t rhs
+ )
+{
+ vint64 res;
+
+ res = *lhs;
+#if defined(HAVE_INT64)
+ res.Q_s += rhs;
+#else
+ M_ADD(res.D_s.hi, res.D_s.lo, 0, rhs);
+#endif
+ return res;
+}
+
+/* -------------------------------------------------------------------------*/
+
+vint64
+subv64u32(
+ const vint64 * lhs,
+ uint32_t rhs
+ )
+{
+ vint64 res;
+
+ res = *lhs;
+#if defined(HAVE_INT64)
+ res.Q_s -= rhs;
+#else
+ M_SUB(res.D_s.hi, res.D_s.lo, 0, rhs);
+#endif
+ return res;
+}
#include "ntp_calendar.h"
#include "ntp_leapsec.h"
#include "ntp.h"
+#include "vint64ops.h"
#include "isc/sha1.h"
* Greetings from the PASCAL world, where casting was only possible via
* untagged unions...
*/
-static void* noconst(const void* ptr)
+static inline void*
+noconst(
+ const void* ptr
+ )
{
union {
const void * cp;
return tmp.vp;
}
-/* ---------------------------------------------------------------------
- * Things to put into libntp...
- */
-
-vint64
-strtouv64(
- const char * begp,
- char ** endp,
- int base)
-{
- vint64 res;
- u_char digit;
- int sig, num;
- const u_char *src;
-
- num = sig = 0;
- src = (const u_char*)begp;
- while (isspace(*src))
- src++;
-
- if (*src == '-') {
- src++;
- sig = 1;
- } else if (*src == '+') {
- src++;
- }
-
- if (base == 0) {
- base = 10;
- if (*src == '0') {
- base = 8;
- if (toupper(*++src) == 'X') {
- src++;
- base = 16;
- }
- }
- } else if (base == 16) { /* remove optional leading '0x' or '0X' */
- if (src[0] == '0' && toupper(src[1]) == 'X')
- src += 2;
- } else if (base <= 2 || base > 36) {
- memset(&res, 0xFF, sizeof(res));
- errno = ERANGE;
- return res;
- }
-
- memset(&res, 0, sizeof(res));
- while (*src) {
- if (isdigit(*src))
- digit = *src - '0';
- else if (isupper(*src))
- digit = *src - 'A' + 10;
- else if (islower(*src))
- digit = *src - 'a' + 10;
- else
- break;
- if (digit >= base)
- break;
- num = 1;
-#if defined(HAVE_INT64)
- res.Q_s = res.Q_s * base + digit;
-#else
- /* res *= base, using 16x16->32 bit
- * multiplication. Slow but portable.
- */
- {
- uint32_t accu;
- accu = (uint32_t)res.W_s.ll * base;
- res.W_s.ll = (uint16_t)accu;
- accu = (accu >> 16)
- + (uint32_t)res.W_s.lh * base;
- res.W_s.lh = (uint16_t)accu;
- /* the upper bits can be done in one step: */
- res.D_s.hi = res.D_s.hi * base + (accu >> 16);
- }
- M_ADD(res.D_s.hi, res.D_s.lo, 0, digit);
-#endif
- src++;
- }
- if (!num)
- errno = EINVAL;
- if (endp)
- *endp = (char*)noconst(src);
- if (sig)
- M_NEG(res.D_s.hi, res.D_s.lo);
- return res;
-}
-
-int icmpv64(
- const vint64 * lhs,
- const vint64 * rhs)
-{
- int res;
-
-#if defined(HAVE_INT64)
- res = (lhs->q_s > rhs->q_s)
- - (lhs->q_s < rhs->q_s);
-#else
- res = (lhs->d_s.hi > rhs->d_s.hi)
- - (lhs->d_s.hi < rhs->d_s.hi);
- if ( ! res )
- res = (lhs->D_s.lo > rhs->D_s.lo)
- - (lhs->D_s.lo < rhs->D_s.lo);
-#endif
-
- return res;
-}
-
-
-int ucmpv64(
- const vint64 * lhs,
- const vint64 * rhs)
-{
- int res;
-
-#if defined(HAVE_INT64)
- res = (lhs->Q_s > rhs->Q_s)
- - (lhs->Q_s < rhs->Q_s);
-#else
- res = (lhs->D_s.hi > rhs->D_s.hi)
- - (lhs->D_s.hi < rhs->D_s.hi);
- if ( ! res )
- res = (lhs->D_s.lo > rhs->D_s.lo)
- - (lhs->D_s.lo < rhs->D_s.lo);
-#endif
- return res;
-}
-
-#if 0
-static vint64
-addv64(
- const vint64 *lhs,
- const vint64 *rhs)
-{
- vint64 res;
-
-#if defined(HAVE_INT64)
- res.Q_s = lhs->Q_s + rhs->Q_s;
-#else
- res = *lhs;
- M_ADD(res.D_s.hi, res.D_s.lo, rhs->D_s.hi, rhs->D_s.lo);
-#endif
- return res;
-}
-#endif
-
-static vint64
-subv64(
- const vint64 *lhs,
- const vint64 *rhs)
-{
- vint64 res;
-
-#if defined(HAVE_INT64)
- res.Q_s = lhs->Q_s - rhs->Q_s;
-#else
- res = *lhs;
- M_SUB(res.D_s.hi, res.D_s.lo, rhs->D_s.hi, rhs->D_s.lo);
-#endif
- return res;
-}
-
-static vint64
-addv64i32(
- const vint64 * lhs,
- int32_t rhs)
-{
- vint64 res;
-
- res = *lhs;
-#if defined(HAVE_INT64)
- res.q_s += rhs;
-#else
- M_ADD(res.D_s.hi, res.D_s.lo, -(rhs < 0), rhs);
-#endif
- return res;
-}
-
-#if 0
-static vint64
-subv64i32(
- const vint64 * lhs,
- int32_t rhs)
-{
- vint64 res;
-
- res = *lhs;
-#if defined(HAVE_INT64)
- res.q_s -= rhs;
-#else
- M_SUB(res.D_s.hi, res.D_s.lo, -(rhs < 0), rhs);
-#endif
- return res;
-}
-#endif
-
-#if 0
-static vint64
-addv64u32(
- const vint64 * lhs,
- uint32_t rhs)
-{
- vint64 res;
-
- res = *lhs;
-#if defined(HAVE_INT64)
- res.Q_s += rhs;
-#else
- M_ADD(res.D_s.hi, res.D_s.lo, 0, rhs);
-#endif
- return res;
-}
-#endif
-
-static vint64
-subv64u32(
- const vint64 * lhs,
- uint32_t rhs)
-{
- vint64 res;
-
- res = *lhs;
-#if defined(HAVE_INT64)
- res.Q_s -= rhs;
-#else
- M_SUB(res.D_s.hi, res.D_s.lo, 0, rhs);
-#endif
- return res;
-}
-
-/* ---------------------------------------------------------------------
- * Things to put into ntp_calendar... (and consequently into libntp...)
- */
-
-/* ------------------------------------------------------------------ */
-static int
-ntpcal_ntp64_to_date(
- struct calendar *jd,
- const vint64 *ntp)
-{
- ntpcal_split ds;
-
- ds = ntpcal_daysplit(ntp);
- ds.hi += ntpcal_daysec_to_date(jd, ds.lo);
-
- return ntpcal_rd_to_date(jd, ds.hi + DAY_NTP_STARTS);
-}
-
-/* ------------------------------------------------------------------ */
-static vint64
-ntpcal_date_to_ntp64(
- const struct calendar *jd)
-{
- return ntpcal_dayjoin(ntpcal_date_to_rd(jd) - DAY_NTP_STARTS,
- ntpcal_date_to_daysec(jd));
-}
-
-
/* ---------------------------------------------------------------------
* Our internal data structure
*/
*/
int/*BOOL*/
leapsec_load_file(
- FILE * ifp ,
- int blimit,
- int hcheck)
+ FILE * ifp ,
+ const char * fname)
{
+ static const char * const logPrefix = "leapsecond file";
+
leap_table_t * pt;
int rcheck;
- hcheck = (hcheck != 0);
+ if (NULL == fname)
+ fname = "<unknown>";
+
rcheck = leapsec_validate((leapsec_reader)getc, ifp);
switch (rcheck)
{
case LSVALID_GOODHASH:
- msyslog(LOG_NOTICE, "%s",
- "leapsecond file: good hash signature");
+ msyslog(LOG_NOTICE, "%s ('%s'): good hash signature",
+ logPrefix, fname);
break;
case LSVALID_NOHASH:
- msyslog(LOG_INFO, "%s",
- "leapsecond file: no hash signature");
+ msyslog(LOG_INFO, "%s ('%s'): no hash signature",
+ logPrefix, fname);
break;
case LSVALID_BADHASH:
- msyslog(LOG_ERR, "%s",
- "leapsecond file: signature mismatch");
+ msyslog(LOG_ERR, "%s ('%s'): signature mismatch",
+ logPrefix, fname);
break;
case LSVALID_BADFORMAT:
- msyslog(LOG_ERR, "%s",
- "leapsecond file: malformed hash signature");
+ msyslog(LOG_ERR, "%s ('%s'): malformed hash signature",
+ logPrefix, fname);
break;
default:
- msyslog(LOG_ERR, "leapsecond file: unknown error code %d",
- rcheck);
+ msyslog(LOG_ERR, "%s ('%s'): unknown error code %d",
+ logPrefix, fname, rcheck);
break;
}
- if (rcheck < hcheck)
- return 0;
+ if (rcheck < 0)
+ return FALSE;
rewind(ifp);
pt = leapsec_get_table(TRUE);
- return leapsec_load(pt, (leapsec_reader)getc, ifp, blimit)
- && leapsec_set_table(pt);
+ if (!leapsec_load(pt, (leapsec_reader)getc, ifp, TRUE)) {
+ switch (errno) {
+ case EINVAL:
+ msyslog(LOG_ERR, "%s ('%s'): bad transition time",
+ logPrefix, fname);
+ break;
+ case ERANGE:
+ msyslog(LOG_ERR, "%s ('%s'): times not ascending",
+ logPrefix, fname);
+ break;
+ default:
+ msyslog(LOG_ERR, "%s ('%s'): parsing error",
+ logPrefix, fname);
+ break;
+ }
+ return FALSE;
+ }
+ msyslog(LOG_NOTICE, "%s '%s' loaded", logPrefix, fname);
+ return leapsec_set_table(pt);
}
/* ------------------------------------------------------------------ */
#ifndef NTP_LEAPSEC_H
#define NTP_LEAPSEC_H
-/* these should probably go to libntp... */
-extern vint64 strtouv64(const char * src, char ** endp, int base);
-extern int icmpv64(const vint64 * lhs, const vint64 * rhs);
-extern int ucmpv64(const vint64 * lhs, const vint64 * rhs);
-
/* function pointer types. Note that 'fprintf' and 'getc' can be casted
* to the dumper resp. reader type, provided the auxiliary argument is a
* valid FILE pointer in hat case.
/* Read a leap second file. This is a convenience wrapper around the
* generic load function, 'leapsec_load()'.
*/
-extern int/*BOOL*/ leapsec_load_file(FILE * fp, int blimit, int checked);
+extern int/*BOOL*/ leapsec_load_file(FILE * fp, const char * fname);
/* Get the current leap data signature. This consists of the last
* ransition, the table expiration, and the total TAI difference at the
msyslog(LOG_ERR,
"leapseconds: stat(%s) failed: %m",
leapseconds_file);
- } else if (!leapsec_load_file(fp, TRUE, FALSE)) {
- msyslog(LOG_ERR,
- "format error leapseconds file %s",
- leapseconds_file);
- } else {
+ } else if (leapsec_load_file(fp, leapseconds_file)) {
leap_signature_t lsig;
leapsec_getsig(&lsig);
} else if ( (sp1->st_mtime != sp2->st_mtime)
|| (sp1->st_ctime != sp2->st_ctime)) {
leapseconds_file_sb1 = leapseconds_file_sb2;
- if (!leapsec_load_file(fp, TRUE, FALSE)) {
- msyslog(LOG_ERR,
- "format error leapseconds file %s",
- leapseconds_file);
+ if (!leapsec_load_file(fp, leapseconds_file))
rc = -1;
- }
}
if (rc >= 0) {
rc = leapsec_daystolive(now.l_ui, NULL);
tstotv.cpp \
tvtots.cpp \
uglydate.cpp \
+ vi64ops.cpp \
ymd2yd.cpp \
$(NULL)
--- /dev/null
+#include "libntptest.h"
+
+extern "C" {
+#include "vint64ops.h"
+}
+
+class vi64Test : public libntptest {
+public:
+ ::testing::AssertionResult IsEqual(const vint64 &expected, const vint64 &actual) {
+ if (0 == memcmp(&expected, &actual, sizeof(vint64))) {
+ return ::testing::AssertionSuccess();
+ } else {
+ return ::testing::AssertionFailure()
+ << "expected: "
+ << std::hex << expected.D_s.hi << '.'
+ << std::hex << expected.D_s.lo
+ << " but was "
+ << std::hex << actual.D_s.hi << '.'
+ << std::hex << actual.D_s.lo;
+ }
+ }
+};
+
+// ----------------------------------------------------------------------
+// test number parser
+TEST_F(vi64Test, ParseVUI64_pos) {
+ vint64 act, exp;
+ const char *sp;
+ char *ep;
+
+ sp = "1234x";
+ exp.D_s.hi = 0;
+ exp.D_s.lo = 1234;
+ act = strtouv64(sp, &ep, 0);
+ EXPECT_TRUE(IsEqual(exp, act));
+ EXPECT_EQ(*ep, 'x');
+}
+
+TEST_F(vi64Test, ParseVUI64_neg) {
+ vint64 act, exp;
+ const char *sp;
+ char *ep;
+
+ sp = "-1234x";
+ exp.D_s.hi = ~0;
+ exp.D_s.lo = -1234;
+ act = strtouv64(sp, &ep, 0);
+ EXPECT_TRUE(IsEqual(exp, act));
+ EXPECT_EQ(*ep, 'x');
+}
+
+TEST_F(vi64Test, ParseVUI64_case) {
+ vint64 act, exp;
+ const char *sp;
+ char *ep;
+
+ sp = "0123456789AbCdEf";
+ exp.D_s.hi = 0x01234567;
+ exp.D_s.lo = 0x89ABCDEF;
+ act = strtouv64(sp, &ep, 16);
+ EXPECT_TRUE(IsEqual(exp, act));
+ EXPECT_EQ(*ep, '\0');
+}
+
<< CalendarToString(actual);
}
}
- ::testing::AssertionResult IsEqual(const vint64 &expected, const vint64 &actual) {
- if (0 == memcmp(&expected, &actual, sizeof(vint64))) {
- return ::testing::AssertionSuccess();
- } else {
- return ::testing::AssertionFailure()
- << "expected: "
- << std::hex << expected.D_s.hi << '.'
- << std::hex << expected.D_s.lo
- << " but was "
- << std::hex << actual.D_s.hi << '.'
- << std::hex << actual.D_s.lo;
- }
- }
};
void leapsecTest::SetUp()
// BASIC FUNCTIONS
// =====================================================================
-// ----------------------------------------------------------------------
-// test number parser
-TEST_F(leapsecTest, ParseVUI64) {
- vint64 act, exp;
- const char *sp;
- char *ep;
-
- sp = "1234x";
- exp.D_s.hi = 0;
- exp.D_s.lo = 1234;
- act = strtouv64(sp, &ep, 0);
- EXPECT_TRUE(IsEqual(exp, act));
- EXPECT_EQ(*ep, 'x');
-
- sp = "-1234x";
- exp.D_s.hi = ~0;
- exp.D_s.lo = -1234;
- act = strtouv64(sp, &ep, 0);
- EXPECT_TRUE(IsEqual(exp, act));
- EXPECT_EQ(*ep, 'x');
-
- sp = "0123456789AbCdEf";
- exp.D_s.hi = 0x01234567;
- exp.D_s.lo = 0x89ABCDEF;
- act = strtouv64(sp, &ep, 16);
- EXPECT_TRUE(IsEqual(exp, act));
- EXPECT_EQ(*ep, '\0');
-}
-
// ----------------------------------------------------------------------
// test table selection
TEST_F(leapsecTest, tableSelect) {