summaryrefslogtreecommitdiff
path: root/libntp/ntp_libopts.c
diff options
context:
space:
mode:
authorOllivier Robert <roberto@FreeBSD.org>2013-12-04 21:33:17 +0000
committerOllivier Robert <roberto@FreeBSD.org>2013-12-04 21:33:17 +0000
commit2b45e011ca352ce509bc83ae148230aeee0c7e0d (patch)
treea618007bb41d13153794a598e3d904ace2976324 /libntp/ntp_libopts.c
parent9b5bd0a264b0a21eefac2b929b574c73bd601507 (diff)
Notes
Diffstat (limited to 'libntp/ntp_libopts.c')
-rw-r--r--libntp/ntp_libopts.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/libntp/ntp_libopts.c b/libntp/ntp_libopts.c
new file mode 100644
index 000000000000..f15597001994
--- /dev/null
+++ b/libntp/ntp_libopts.c
@@ -0,0 +1,54 @@
+/*
+ * ntp_libopts.c
+ *
+ * Common code interfacing with Autogen's libopts command-line option
+ * processing.
+ */
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stddef.h>
+#include "ntp_libopts.h"
+#include "ntp_stdlib.h"
+
+extern const char *Version; /* version.c for each program */
+
+
+/*
+ * ntpOptionProcess() is a clone of libopts' optionProcess which
+ * overrides the --version output, appending detail from version.c
+ * which was not available at Autogen time.
+ */
+int
+ntpOptionProcess(
+ tOptions * pOpts,
+ int argc,
+ char ** argv
+ )
+{
+ char * pchOpts;
+ char ** ppzFullVersion;
+ char * pzNewFV;
+ char * pzAutogenFV;
+ size_t octets;
+ int rc;
+
+ pchOpts = (void *)pOpts;
+ ppzFullVersion = (char **)(pchOpts + offsetof(tOptions,
+ pzFullVersion));
+ pzAutogenFV = *ppzFullVersion;
+ octets = strlen(pzAutogenFV) +
+ 1 + /* '\n' */
+ strlen(Version) +
+ 1; /* '\0' */
+ pzNewFV = emalloc(octets);
+ snprintf(pzNewFV, octets, "%s\n%s", pzAutogenFV, Version);
+ *ppzFullVersion = pzNewFV;
+ rc = optionProcess(pOpts, argc, argv);
+ *ppzFullVersion = pzAutogenFV;
+ free(pzNewFV);
+
+ return rc;
+}