aboutsummaryrefslogtreecommitdiff
path: root/libntp/ntp_libopts.c
blob: f155970019947929e226167f2de34f170bdea0b9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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;
}