xref: /netbsd-src/external/bsd/ntp/dist/libntp/ntp_libopts.c (revision b757af438b42b93f8c6571f026d8b8ef3eaf5fc9)
1 /*	$NetBSD: ntp_libopts.c,v 1.1.1.1 2012/01/31 21:24:15 kardel Exp $	*/
2 
3 /*
4  * ntp_libopts.c
5  *
6  * Common code interfacing with Autogen's libopts command-line option
7  * processing.
8  */
9 #ifdef HAVE_CONFIG_H
10 # include <config.h>
11 #endif
12 
13 #include <stdio.h>
14 #include <stddef.h>
15 #include "ntp_libopts.h"
16 #include "ntp_stdlib.h"
17 
18 extern const char *Version;	/* version.c for each program */
19 
20 
21 /*
22  * ntpOptionProcess() is a clone of libopts' optionProcess which
23  * overrides the --version output, appending detail from version.c
24  * which was not available at Autogen time.
25  */
26 int
27 ntpOptionProcess(
28 	tOptions *	pOpts,
29 	int		argc,
30 	char **		argv
31 	)
32 {
33 	char *		pchOpts;
34 	char **		ppzFullVersion;
35 	char *		pzNewFV;
36 	char *		pzAutogenFV;
37 	size_t		octets;
38 	int		rc;
39 
40 	pchOpts = (void *)pOpts;
41 	ppzFullVersion = (char **)(pchOpts + offsetof(tOptions,
42 						      pzFullVersion));
43 	pzAutogenFV = *ppzFullVersion;
44 	octets = strlen(pzAutogenFV) +
45 		 1 +	/* '\n' */
46 		 strlen(Version) +
47 		 1;	/* '\0' */
48 	pzNewFV = emalloc(octets);
49 	snprintf(pzNewFV, octets, "%s\n%s", pzAutogenFV, Version);
50 	*ppzFullVersion = pzNewFV;
51 	rc = optionProcess(pOpts, argc, argv);
52 	*ppzFullVersion = pzAutogenFV;
53 	free(pzNewFV);
54 
55 	return rc;
56 }
57