[ntpsec commit] Add test for VSNPRINTF_PERCENT_M. Could be improved...

Eric S. Raymond esr at ntpsec.org
Thu Oct 1 09:38:03 UTC 2015


Module:    ntpsec
Branch:    master
Commit:    edaf177622bf478409745cc86fcbcac5781ddf91
Changeset: http://git.ntpsec.org/ntpsec/commit/?id=edaf177622bf478409745cc86fcbcac5781ddf91

Author:    Eric S. Raymond <esr at thyrsus.com>
Date:      Thu Oct  1 05:35:29 2015 -0400

Add test for VSNPRINTF_PERCENT_M.  Could be improved...

...with a waf configurator method for compilng and then checking the
compiled program's return status.

---

 pylib/configure.py |  3 +++
 pylib/probes.py    | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 util/ntptime.c     |  2 +-
 3 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/pylib/configure.py b/pylib/configure.py
index cf84765..5013671 100644
--- a/pylib/configure.py
+++ b/pylib/configure.py
@@ -104,6 +104,7 @@ def cmd_configure(ctx):
 	structure_fields = (
 		("time_tick", "timex", "sys/timex.h"),
 		("modes", "timex", "sys/timex.h"),
+		("tv_nsec", "ntp_timeval", "sys/timex.h"),
 		)
 	for (f, s, h) in structure_fields:
 		ctx.check_structfield(f, s, h)
@@ -385,6 +386,8 @@ def cmd_configure(ctx):
 		from check_openssl import configure_ssl
 		configure_ssl(ctx)
 
+	probe_vsprintfm(ctx, "VSNPRINTF_PERCENT_M",
+			    "Checking for %m expansion in vsnprintf(3)")
 
 	ctx.define("NTPS_CFLAGS", " ".join(ctx.env.CFLAGS).replace("\"", "\\\""))
 	ctx.define("NTPS_LDFLAGS", " ".join(ctx.env.LDFLAGS).replace("\"", "\\\""))
diff --git a/pylib/probes.py b/pylib/probes.py
index 6e279b1..7d6435a 100644
--- a/pylib/probes.py
+++ b/pylib/probes.py
@@ -29,3 +29,57 @@ int main() {
 		define_name=symbol,
 		msg = legend,
 		mandatory = False)
+
+# What we really want to do here is test to see if the following program
+# compiles *and exits with 9 status*.  Because we don;t know how to check
+# the return status we must seettle for a simpler tesl
+'''
+#include <stdarg.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+
+int call_vsnprintf(char *dst, size_t sz, const char *fmt, ...);
+
+int call_vsnprintf(char *dst, size_t sz, const char *fmt,...)
+{
+	va_list	ap;
+	int		rc;
+
+	va_start(ap, fmt);
+	rc = vsnprintf(dst, sz, fmt, ap);
+	va_end(ap);
+
+	return rc;
+}
+
+int main()
+{
+	char	sbuf[512];
+	char	pbuf[512];
+	int		slen;
+
+	strcpy(sbuf, strerror(ENOENT));
+	errno = ENOENT;
+	slen = call_vsnprintf(pbuf, sizeof(pbuf), "%m",
+			  "wrong");
+	return strcmp(sbuf, pbuf);
+}
+'''
+
+
+def probe_vsprintfm(ctx, symbol, legend):
+	"Probe for %m expanding to strerror(error) in glibc style."
+	ctx.check_cc(
+		fragment='''
+#include <features.h>
+int main()
+{
+#ifndef __GLIBC__
+# error __GLIBC__ is not defined
+#endif
+}
+''',
+		define_name=symbol,
+		msg = legend,
+		mandatory = False)
diff --git a/util/ntptime.c b/util/ntptime.c
index cce8274..b64f893 100644
--- a/util/ntptime.c
+++ b/util/ntptime.c
@@ -19,7 +19,7 @@
 #include <signal.h>
 #include <setjmp.h>
 
-#ifdef HAVE_STRUCT_NTPTIMEVAL_TIME_TV_NSEC
+#ifdef STRUCT_NTP_TIMEVAL_HAS_TV_NSEC
 #define tv_frac_sec tv_nsec
 #else
 #define tv_frac_sec tv_usec



More information about the vc mailing list