[Git][NTPsec/ntpsec][master] Remove use of waf define NTP_SIZEOF_TIME_T

Hal Murray (@hal.murray) gitlab at mg.gitlab.com
Fri Feb 7 07:32:15 UTC 2025



Hal Murray pushed to branch master at NTPsec / ntpsec


Commits:
38ac9f36 by Gary E. Miller at 2025-02-07T07:29:01+00:00
Remove use of waf define NTP_SIZEOF_TIME_T

- - - - -


4 changed files:

- libntp/prettydate.c
- libntp/systime.c
- libntp/timespecops.c
- ntpd/ntp_leapsec.c


Changes:

=====================================
libntp/prettydate.c
=====================================
@@ -11,10 +11,6 @@
 #include "ntp_calendar.h"
 #include "PIVOT.h"
 
-#if NTP_SIZEOF_TIME_T < 4
-# error sizeof(time_t) < 4 -- this will not work!
-#endif
-
 /* Helper function to handle possible wraparound of the ntp epoch.
  *
  * Works by periodic extension of the ntp time stamp in the UN*X epoch.


=====================================
libntp/systime.c
=====================================
@@ -198,43 +198,45 @@ step_systime(
 	 * very often, we can afford to do the whole calculation from
 	 * scratch. And we're not in the time-critical path yet.
 	 */
-#if NTP_SIZEOF_TIME_T > 4
-	/*
-	 * This code makes sure the resulting time stamp for the new
-	 * system time is in the 2^32 seconds starting at 1970-01-01,
-	 * 00:00:00 UTC.
-	 */
-	pivot = 0x80000000;
+        if (4 < sizeof(time_t)) {
+            // 64-bit time_t
+            /*
+             * This code makes sure the resulting time stamp for the new
+             * system time is in the 2^32 seconds starting at 1970-01-01,
+             * 00:00:00 UTC.
+             */
+            pivot = 0x80000000;
 #if USE_COMPILETIME_PIVOT
-	/*
-	 * Add the compile time minus 10 years to get a possible target
-	 * area of (compile time - 10 years) to (compile time + 126
-	 * years).  This should be sufficient for a given binary of
-	 * NTPD.
-	 */
-	if (ntpcal_get_build_date(&jd)) {
-		jd.year -= 10;
-		pivot += ntpcal_date_to_time(&jd);
-	} else {
-		msyslog(LOG_ERR,
-			"CLOCK: step_systime: assume 1970-01-01 as build date");
-	}
-#else
-	UNUSED_LOCAL(jd);
-#endif /* USE_COMPILETIME_PIVOT */
+            /*
+             * Add the compile time minus 10 years to get a possible target
+             * area of (compile time - 10 years) to (compile time + 126
+             * years).  This should be sufficient for a given binary of
+             * NTPD.
+             */
+            if (ntpcal_get_build_date(&jd)) {
+                    jd.year -= 10;
+                    pivot += ntpcal_date_to_time(&jd);
+            } else {
+                    msyslog(LOG_ERR,
+                       "CLOCK: step_systime: assume 1970-01-01 as build date");
+            }
 #else
-	UNUSED_LOCAL(jd);
-	/* This makes sure the resulting time stamp is on or after
-	 * 1969-12-31/23:59:59 UTC and gives us additional two years,
-	 * from the change of NTP era in 2036 to the UNIX rollover in
-	 * 2038. (Minus one second, but that won't hurt.) We *really*
-	 * need a longer 'time_t' after that!  Or a different baseline,
-	 * but that would cause other serious trouble, too.
-	 */
-	pivot = 0x7FFFFFFF;
-#endif
+            UNUSED_LOCAL(jd);
+#endif  // USE_COMPILETIME_PIVOT
+    } else {
+            // 32-bit time_t
+            UNUSED_LOCAL(jd);
+            /* This makes sure the resulting time stamp is on or after
+             * 1969-12-31/23:59:59 UTC and gives us additional two years,
+             * from the change of NTP era in 2036 to the UNIX rollover in
+             * 2038. (Minus one second, but that won't hurt.) We *really*
+             * need a longer 'time_t' after that!  Or a different baseline,
+             * but that would cause other serious trouble, too.
+             */
+            pivot = 0x7FFFFFFF;
+    }
 
-	/* get the complete jump distance as l_fp */
+	// get the complete jump distance as l_fp
 	fp_sys = dtolfp(sys_residual);
 	fp_ofs = dtolfp(step);
 	fp_ofs += fp_sys;


=====================================
libntp/timespecops.c
=====================================
@@ -360,12 +360,12 @@ lfp_stamp_to_tspec(
 	sec = ntpcal_ntp_to_time(lfpuint(x), p);
 	out.tv_nsec = FTOTVN(lfpfrac(x));
 
-	/* copying a time64_t to a time_t needs some care... */
-#if NTP_SIZEOF_TIME_T <= 4
-	out.tv_sec = (time_t)time64lo(sec);
-#else
-	out.tv_sec = (time_t)time64s(sec);
-#endif
+        // copying a time64_t to a time_t needs some care...
+        if (4 >= sizeof(time_t)) {
+            out.tv_sec = (time_t)time64lo(sec);
+        } else {
+            out.tv_sec = (time_t)time64s(sec);
+        }
 
 	return out;
 }


=====================================
ntpd/ntp_leapsec.c
=====================================
@@ -83,12 +83,8 @@ static void   reset_times(leap_table_t*);
 static bool   leapsec_add(leap_table_t*, time_t, int);
 static bool   leapsec_raw(leap_table_t*, time_t, int, bool);
 
-/* time_t is unsigned.  This is used for infinity in tables */
-#if NTP_SIZEOF_TIME_T == 8
-# define LAST_time_t 0x7fffffffffffffff
-#elif NTP_SIZEOF_TIME_T == 4
-# define LAST_time_t 0x7fffffff
-#endif
+// time_t is unsigned.  This is used for infinity in tables
+#define LAST_time_t ((8 == sizeof(time_t))? 0x7fffffffffffffff : 0x7fffffff)
 
 /* =====================================================================
  * Get & Set the current leap table



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/38ac9f36b401a0ecaf9cfb12021b8b3041de2c00

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/38ac9f36b401a0ecaf9cfb12021b8b3041de2c00
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/20250207/22a5afae/attachment-0001.htm>


More information about the vc mailing list