[ntp:bk-ntp-dev-send] BitKeeper diffs

Harlan Stenn stenn at deacon.udel.edu
Wed Apr 27 20:24:56 UTC 2011


#### ChangeSet ####
2011-04-23 11:38:29+02:00, jnperlin at hydra.localnet
  minor cleanup in timespecops/timevalops

==== ChangeLog ====
2011-04-23 11:38:29+02:00, jnperlin at hydra.localnet +1 -0
  minor cleanup in timespecops/timevalops

--- 1.861/ChangeLog	2011-04-21 02:16:23 -04:00
+++ 1.862/ChangeLog	2011-04-23 05:38:29 -04:00
@@ -1,3 +1,4 @@
+* cleanup in timespecops.c / timevalops.c
 (4.2.7p157) 2011/04/21 Released by Harlan Stenn <stenn at ntp.org>
 * [Bug 1890] 4.2.7p156 segfault in duplicate freeaddrinfo().
 (4.2.7p156) 2011/04/19 Released by Harlan Stenn <stenn at ntp.org>

==== libntp/timespecops.c ====
2011-04-23 11:38:29+02:00, jnperlin at hydra.localnet +12 -69
  unified with tvalops, use string formatting in libntp, fixed misleading comments

--- 1.5/libntp/timespecops.c	2011-01-20 03:27:31 -05:00
+++ 1.6/libntp/timespecops.c	2011-04-23 05:38:29 -04:00
@@ -8,17 +8,10 @@
 #include <config.h>
 #include <math.h>
 
-#include "lib_strbuf.h"
-#include "ntp_calendar.h"
-
 #include "timespecops.h"
 
-/* formatting to string needs at max 31 bytes (even with 64 bit time_t),
- * so we check LIB_BUFLENGTH is big enough for our pupose.
- */
-#if LIB_BUFLENGTH < 32
-#error LIB_BUFLENGTH not big enough
-#endif
+#include "timetoa.h"
+#include "ntp_calendar.h"
 
 /* make sure we have the right definition for NANOSECONDS */
 #undef NANOSECONDS
@@ -26,7 +19,7 @@
 
 /* conversion between l_fp fractions and nanoseconds */
 #if SIZEOF_LONG >= 8
-# define MYFTOTVN(tsf,tvu)						\
+# define MYFTOTVN(tsf, tvu)						\
 	((tvu) = (int32)						\
 		(((u_long)(tsf) * NANOSECONDS + 0x80000000) >> 32))
 # define MYTVNTOF(tvu, tsf)						\
@@ -40,20 +33,6 @@
 	((tsf) = (u_int32)floor((tvu) * 4.294967296 + 0.5))
 #endif
 
-/* using snprintf is troublesome with time_t. Try to resolve it. */
-#if SIZEOF_TIME_T <= SIZEOF_INT
-typedef unsigned int u_time;
-#define TIMEFMT ""
-#elif SIZEOF_TIME_T <= SIZEOF_LONG
-typedef unsigned long u_time;
-#define TIMEFMT "l"
-#elif defined(SIZEOF_LONG_LONG) && SIZEOF_TIME_T <= SIZEOF_LONG_LONG
-typedef unsigned long long u_time;
-#define TIMEFMT "ll"
-#else
-#include "GRONK: what size has a time_t here?"
-#endif
-
 
 /* copy and normalise. Used often enough to warrant a macro. */
 #define COPYNORM(dst, src)						\
@@ -75,7 +54,7 @@ timespec_norm(
 	 * involved. On the other hand, division by constant should be
 	 * fast enough; so we do a division of the nanoseconds in that
 	 * case. The floor adjustment step follows with the standard
-	 * normalisation loops.  And 'labs' is intentinally not used
+	 * normalisation loops.	 And 'labs' is intentinally not used
 	 * here: its has implementation defined behaviour when applied
 	 * to LONG_MIN. */
 	if (x->tv_nsec < -3l * NANOSECONDS ||
@@ -188,7 +167,7 @@ timespec_neg(
 
 /*
  * x = abs(a)
- * returns nonzero if negation was needed
+ * return value is nonzero if negation was needed
  */
 int
 timespec_abs(
@@ -216,7 +195,7 @@ timespec_abs(
 
 /*
  * compare previously-normalised a and b
- * return 1 / 0 / -1 if	 a < / == / > b
+ * return -1 / 0 / 1 if	 a < / == / > b
  */
 int
 timespec_cmp_fast(
@@ -236,7 +215,7 @@ timespec_cmp_fast(
 
 /*
  * compare possibly denormal a and b
- * return 1 / 0 / -1 if	 a < / == / > b
+ * return -1 / 0 / 1 if	 a < / == / > b
  */
 int
 timespec_cmp(
@@ -260,7 +239,7 @@ timespec_cmp(
 
 /*
  * test previously-normalised a
- * return 1 / 0 / -1 if	 a < / == / > 0
+ * return -1 / 0 / 1 if	 a < / == / > 0
  */
 int
 timespec_test_fast(
@@ -278,15 +257,15 @@ timespec_test_fast(
 
 /*
  * test possibly denormal a
- * return 1 / 0 / -1 if	 a < / == / > 0
+ * return -1 / 0 / 1 if	 a < / == / > 0
  */
 int
 timespec_test(
 	const struct timespec *a
 	)
 {
-	int		r;
 	struct timespec A;
+	int		r;
 
 	COPYNORM(&A, a);
 	r = (A.tv_sec > 0) - (A.tv_sec < 0);
@@ -296,49 +275,13 @@ timespec_test(
 	return r;
 }
 
+/* return LIB buffer ptr to string rep */
 const char*
 timespec_tostr(
 	const struct timespec *x
 	)
 {
-	/*
-	 * Formatting a 'time_t' to a string of decimal digits poses
-	 * some interesting portability problems regarding the size of a
-	 * time_t and the handling of signed integer overflow, which is
-	 * undefined and must be avoided.
-	 *
-	 * Even with 64 bit time_t, 32 chars will suffice. Hopefully,
-	 * LIB_BUFLENGTH is big enough; the current definiton checks
-	 * this by the preprocessor just at the top of this file. */
-	static const char *fmt = "-%" TIMEFMT "u.%09lu";
-	
-	struct timespec v;
-	char	       *cp;
-	int		notneg;
-	u_time		itmp;
-	u_long		ftmp;
-	
-	/* normalise and get absolute value into unsigned values. Since
-	 * the negation of TIME_T_MIN (if it existed) is implementation
-	 * defined, we try to avoid it. */
-	COPYNORM(&v, x);
-	notneg = v.tv_sec >= 0;
-	if (notneg != 0) {
-		itmp = (u_time)v.tv_sec;
-		ftmp = (u_long)v.tv_nsec;
-	} else if (v.tv_nsec != 0) {
-		itmp = (u_time)-(v.tv_sec + 1);
-		ftmp = (u_long)(NANOSECONDS - v.tv_nsec);
-	} else {
-		itmp = ((u_time) -(v.tv_sec + 1)) + 1;
-		ftmp = 0;
-	}
-
-	/* get buffer and format data */
-	LIB_GETBUF(cp);
-	snprintf(cp, LIB_BUFLENGTH, fmt + notneg, itmp, ftmp);
-	
-	return cp;
+	return format_time_fraction(x->tv_sec, x->tv_nsec, 9);
 }
 
 void

==== libntp/timevalops.c ====
2011-04-23 11:38:29+02:00, jnperlin at hydra.localnet +9 -4
  fixed misleading comments

--- 1.6/libntp/timevalops.c	2011-01-25 15:08:29 -05:00
+++ 1.7/libntp/timevalops.c	2011-04-23 05:38:29 -04:00
@@ -186,8 +186,9 @@ timeval_abs(
 	return r;
 }
 
-/* compare a <--> b
- * return 1 / 0 / -1 if	 a < / == / > b
+/*
+ * compare previously-normalised a and b
+ * return -1 / 0 / 1 if	 a < / == / > b
  */
 int
 timeval_cmp_fast(
@@ -205,6 +206,10 @@ timeval_cmp_fast(
 	return r;
 }
 
+/*
+ * compare possibly denormal a and b
+ * return -1 / 0 / 1 if	 a < / == / > b
+ */
 int
 timeval_cmp(
 	const struct timeval *a,
@@ -227,7 +232,7 @@ timeval_cmp(
 
 /*
  * test previously-normalised a
- * return 1 / 0 / -1 if	 a < / == / > 0
+ * return -1 / 0 / 1 if	 a < / == / > 0
  */
 int
 timeval_test_fast(
@@ -245,7 +250,7 @@ timeval_test_fast(
 
 /*
  * test possibly denormal a
- * return 1 / 0 / -1 if	 a < / == / > 0
+ * return -1 / 0 / 1 if	 a < / == / > 0
  */
 int
 timeval_test(


More information about the bk-ntp-dev-send mailing list