[Git][NTPsec/ntpsec][master] Remove two unnecessary functions.
Eric S. Raymond
gitlab at mg.gitlab.com
Thu Nov 9 20:58:55 UTC 2017
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
2d88a7d8 by Eric S. Raymond at 2017-11-09T15:58:31-05:00
Remove two unnecessary functions.
- - - - -
5 changed files:
- libntp/systime.c
- libntp/timespecops.c
- − libntp/timetoa.c
- libntp/wscript
- tests/libntp/timespecops.c
Changes:
=====================================
libntp/systime.c
=====================================
--- a/libntp/systime.c
+++ b/libntp/systime.c
@@ -187,10 +187,11 @@ normalize_time(
if (lfp_prev != 0 && !lamport_violated) {
if (!L_ISGTU(result, lfp_prev) &&
sys_fuzz > 0.) {
- msyslog(LOG_ERR, "CLOCK: ts_prev %s ts_min %s",
- tspectoa(ts_prev_log),
- tspectoa(ts_min));
- msyslog(LOG_ERR, "CLOCK: ts %s", tspectoa(ts));
+ msyslog(LOG_ERR, "CLOCK: ts_prev %ld s + %ld ns, ts_min %ld s + %ld ns",
+ ts_prev_log.tv_sec, ts_prev.tv_nsec,
+ ts_min.tv_sec, ts_min.tv_nsec);
+ msyslog(LOG_ERR, "CLOCK: ts %ld s + %ld ns",
+ ts.tv_sec, ts.tv_nsec);
msyslog(LOG_ERR, "CLOCK: sys_fuzz %ld nsec, prior fuzz %.9f",
sys_fuzz_nsec, dfuzz_prev);
msyslog(LOG_ERR, "CLOCK: this fuzz %.9f",
=====================================
libntp/timespecops.c
=====================================
--- a/libntp/timespecops.c
+++ b/libntp/timespecops.c
@@ -263,15 +263,6 @@ test_tspec_denorm(
return test_tspec(normalize_tspec(a));
}
-/* return LIB buffer ptr to string rep */
-const char *
-tspectoa(
- struct timespec x
- )
-{
- return format_time_fraction(x.tv_sec, x.tv_nsec, 9);
-}
-
/*
* convert to l_fp type, relative and absolute
*/
=====================================
libntp/timetoa.c deleted
=====================================
--- a/libntp/timetoa.c
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * timetoa.c -- time_t related string formatting
- *
- * Written by Juergen Perlinger <perlinger at ntp.org> for the NTP project.
- *
- * Printing a 'time_t' has a lot of portability pitfalls, due to it's
- * opaque base type. The only requirement imposed by the standard is
- * that it must be a numeric type. For all practical purposes it's a
- * signed int, and 32 bits are common.
- *
- * Since the UN*X time epoch will cause a signed integer overflow for
- * 32-bit signed int in the year 2038, implementations slowly move to
- * 64bit base types for time_t, even in 32-bit environments.
- *
- * Here we take the easy way out and just use the widest possible int.
- *
- * Copyright 2015 by the NTPsec project contributors
- * SPDX-License-Identifier: NTP
- */
-
-#include "config.h"
-
-#include <math.h>
-#include <stdio.h>
-
-#include "timetoa.h"
-#include "ntp_assert.h"
-#include "lib_strbuf.h"
-
-/* longest possible unsigned int */
-typedef unsigned long long u_time;
-
-/*
- * Formatting to string needs at max 40 bytes (even with 64 bit time_t),
- * so we check LIB_BUFLENGTH is big enough for our purpose.
- */
-#if LIB_BUFLENGTH < 40
-# include "GRONK: LIB_BUFLENGTH is not sufficient"
-#endif
-
-/*
- * general fractional timestamp formatting
- *
- * Many pieces of ntpd require a machine with two's complement
- * representation of signed integers, so we don't go through the whole
- * rigamarole of creating fully portable code here. But we have to stay
- * away from signed integer overflow, as this might cause trouble even
- * with two's complement representation.
- */
-const char *
-format_time_fraction(
- time_t secs,
- long frac,
- int prec
- )
-{
- char * cp;
- unsigned int prec_u;
- u_time secs_u;
- unsigned int u;
- long fraclimit;
- int notneg; /* flag for non-negative value */
- ldiv_t qr;
-
- //REQUIRE(prec != 0);
-
- cp = lib_getbuf();
- secs_u = (u_time)secs;
-
- /* check if we need signed or unsigned mode */
- notneg = (prec < 0);
- prec_u = (unsigned int)abs(prec);
- /* fraclimit = (long)pow(10, prec_u); */
- for (fraclimit = 10, u = 1; u < prec_u; u++) {
- //INSIST(fraclimit < fraclimit * 10);
- fraclimit *= 10;
- }
-
- /*
- * Since conversion to string uses lots of divisions anyway,
- * there's no big extra penalty for normalisation. We do it for
- * consistency.
- */
- if (frac < 0 || frac >= fraclimit) {
- qr = ldiv(frac, fraclimit);
- if (qr.rem < 0) {
- qr.quot--;
- qr.rem += fraclimit;
- }
- secs_u += (u_time)qr.quot;
- frac = qr.rem;
- }
-
- /* Get the absolute value of the split representation time. */
- notneg = notneg || ((time_t)secs_u >= 0);
- if (!notneg) {
- secs_u = ~secs_u;
- if (0 == frac)
- secs_u++;
- else
- frac = fraclimit - frac;
- }
-
- /* finally format the data and return the result */
- snprintf(cp, LIB_BUFLENGTH, "%s%llu.%0*ld",
- notneg? "" : "-", secs_u, (int)prec_u, frac);
-
- return cp;
-}
=====================================
libntp/wscript
=====================================
--- a/libntp/wscript
+++ b/libntp/wscript
@@ -37,7 +37,6 @@ def build(ctx):
"statestr.c",
"systime.c",
"timespecops.c",
- "timetoa.c",
]
if not ctx.env.HAVE_STRLCAT or not ctx.env.HAVE_STRLCPY:
=====================================
tests/libntp/timespecops.c
=====================================
--- a/tests/libntp/timespecops.c
+++ b/tests/libntp/timespecops.c
@@ -634,33 +634,6 @@ TEST(timespecops, test_LFProundtrip) {
// string formatting
//----------------------------------------------------------------------
-TEST(timespecops, test_ToString) {
- static const struct {
- time_t sec;
- long nsec;
- const char * repr;
- } data [] = {
- { 0, 0, "0.000000000" },
- { 2, 0, "2.000000000" },
- {-2, 0, "-2.000000000" },
- { 0, 1, "0.000000001" },
- { 0,-1, "-0.000000001" },
- { 1,-1, "0.999999999" },
- {-1, 1, "-0.999999999" },
- {-1,-1, "-1.000000001" },
- };
- int i;
-
- for (i = 0; i < (int)COUNTOF(data); ++i) {
- struct timespec a = timespec_init(data[i].sec, data[i].nsec);
- const char * E = data[i].repr;
- const char * r = tspectoa(a);
- TEST_ASSERT_EQUAL_STRING(E, r);
- }
-
- return;
-}
-
TEST_GROUP_RUNNER(timespecops) {
RUN_TEST_CASE(timespecops, Helpers1);
RUN_TEST_CASE(timespecops, Normalise);
@@ -689,7 +662,6 @@ TEST_GROUP_RUNNER(timespecops) {
RUN_TEST_CASE(timespecops, test_FromLFPrelPos);
RUN_TEST_CASE(timespecops, test_FromLFPrelNeg);
RUN_TEST_CASE(timespecops, test_LFProundtrip);
- RUN_TEST_CASE(timespecops, test_ToString);
}
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/2d88a7d847f1de155c731f68d68ccc9a29953a16
---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/2d88a7d847f1de155c731f68d68ccc9a29953a16
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20171109/07f201e8/attachment.html>
More information about the vc
mailing list