1103591Swollman%{
2103591Swollman/*
3103591Swollman * Copyright is disclaimed as to the contents of this file.
4103591Swollman *
5103591Swollman * $FreeBSD$
6103591Swollman */
7103591Swollman
8103591Swollman#include <sys/types.h>
9103591Swollman
10103591Swollman#include <string.h>
11103591Swollman#include <unistd.h>
12103591Swollman
13103591Swollman#include "getconf.h"
14103591Swollman
15103591Swollman/*
16103591Swollman * Override gperf's built-in external scope.
17103591Swollman */
18119312Smarkmstatic const struct map *in_word_set(const char *str);
19103591Swollman
20103591Swollman/*
21103591Swollman * The Standard seems a bit ambiguous over whether the POSIX_V6_*
22103591Swollman * are specified with or without a leading underscore, so we just
23103591Swollman * use both.
24103591Swollman */
25103591Swollman/*
26103591Swollman * The alt_path member gives the path containing another `getconf'
27103591Swollman * executable which was compiled using the specified programming
28103591Swollman * environment.  If it is NULL, the current executable is good enough.
29103591Swollman * If we ever support multiple environments, this table will need to
30103591Swollman * be updated.  (We cheat here and define the supported environments
31103591Swollman * statically.)
32103591Swollman */
33142066Swollman#if defined(__alpha__) || defined(__sparc64__) || defined(__amd64__)
34103591Swollman#define	have_LP64_OFF64		NULL
35103591Swollman#endif
36103591Swollman
37103591Swollman#if defined(__i386__) || defined(__powerpc__)
38103591Swollman#define	have_ILP32_OFFBIG	NULL
39103591Swollman#endif
40103591Swollman
41103591Swollman%}
42103591Swollmanstruct map { const char *name; const char *alt_path; int valid; };
43103591Swollman%%
44103591SwollmanPOSIX_V6_ILP32_OFF32, notdef
45103591SwollmanPOSIX_V6_ILP32_OFFBIG, have_ILP32_OFFBIG
46103591SwollmanPOSIX_V6_LP64_OFF64, have_LP64_OFF64
47103591SwollmanPOSIX_V6_LPBIG_OFFBIG, notdef
48103591Swollman_POSIX_V6_ILP32_OFF32, notdef
49103591Swollman_POSIX_V6_ILP32_OFFBIG, have_ILP32_OFFBIG
50103591Swollman_POSIX_V6_LP64_OFF64, have_LP64_OFF64
51103591Swollman_POSIX_V6_LPBIG_OFFBIG, notdef
52103591Swollman%%
53103591Swollmanint
54103591Swollmanfind_progenv(const char *name, const char **alt_path)
55103591Swollman{
56103591Swollman	const struct map *rv;
57103591Swollman
58119312Smarkm	rv = in_word_set(name);
59103591Swollman	if (rv != NULL) {
60103591Swollman		if (rv->valid) {
61103591Swollman			*alt_path = rv->alt_path;
62103591Swollman			return 1;
63103591Swollman		}
64103591Swollman		return -1;
65103591Swollman	}
66103591Swollman	return 0;
67103591Swollman}
68