[Git][NTPsec/ntpsec][master] Simplify some overcomplicated code.

Eric S. Raymond gitlab at mg.gitlab.com
Sun Oct 23 14:43:48 UTC 2016


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
5d8ce99b by Eric S. Raymond at 2016-10-23T10:40:27-04:00
Simplify some overcomplicated code.

- - - - -


1 changed file:

- libntp/timetoa.c


Changes:

=====================================
libntp/timetoa.c
=====================================
--- a/libntp/timetoa.c
+++ b/libntp/timetoa.c
@@ -12,9 +12,7 @@
  * 32-bit signed int in the year 2038, implementations slowly move to
  * 64bit base types for time_t, even in 32-bit environments.
  *
- * As the printf() family has no standardised type specifier for time_t,
- * guessing the right output format specifier is a bit troublesome and
- * best done with the help of the preprocessor and "config.h".
+ * 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
@@ -29,40 +27,8 @@
 #include "ntp_assert.h"
 #include "lib_strbuf.h"
 
-/*
- * Given the size of time_t, guess what can be used as an unsigned value
- * to hold a time_t and the printf() format specifcation.
- *
- * These should be used with the string constant concatenation feature
- * of the compiler like this:
- *
- * printf("a time stamp: %" TIME_FORMAT " and more\n", a_time_t_value);
- *
- * It's not exactly nice, but there's not much leeway once we want to
- * use the printf() family on time_t values.
- */
-
-#if SIZEOF_TIME_T <= SIZEOF_INT
-
-typedef unsigned int u_time;
-#define TIME_FORMAT "d"
-#define UTIME_FORMAT "u"
-
-#elif SIZEOF_TIME_T <= SIZEOF_LONG
-
-typedef unsigned long u_time;
-#define TIME_FORMAT "ld"
-#define UTIME_FORMAT "lu"
-
-#elif defined(SIZEOF_LONG_LONG) && SIZEOF_TIME_T <= SIZEOF_LONG_LONG
-
+/* longest possible unsigned int */
 typedef unsigned long long u_time;
-#define TIME_FORMAT "lld"
-#define UTIME_FORMAT "llu"
-
-#else
-#include "GRONK: what size has a time_t here?"
-#endif
 
 /*
  * Formatting to string needs at max 40 bytes (even with 64 bit time_t),
@@ -136,7 +102,7 @@ format_time_fraction(
 	}
 
 	/* finally format the data and return the result */
-	snprintf(cp, LIB_BUFLENGTH, "%s%" UTIME_FORMAT ".%0*ld",
+	snprintf(cp, LIB_BUFLENGTH, "%s%llu.%0*ld",
 	    notneg? "" : "-", secs_u, prec_u, frac);
 	
 	return cp;



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/5d8ce99b1d1fbe6a5ba54e3705951d9437ad0406
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20161023/a7acf555/attachment.html>


More information about the vc mailing list