xref: /freebsd/usr.bin/getconf/progenv.gperf (revision b4b4b5304bd22eab265c9c049cb7fc6b55c4ef3f)
1e9cfb9aeSGarrett Wollman%{
2e9cfb9aeSGarrett Wollman/*
3e9cfb9aeSGarrett Wollman * Copyright is disclaimed as to the contents of this file.
4e9cfb9aeSGarrett Wollman *
5e9cfb9aeSGarrett Wollman * $FreeBSD$
6e9cfb9aeSGarrett Wollman */
7e9cfb9aeSGarrett Wollman
8e9cfb9aeSGarrett Wollman#include <sys/types.h>
9e9cfb9aeSGarrett Wollman
10e9cfb9aeSGarrett Wollman#include <string.h>
11e9cfb9aeSGarrett Wollman#include <unistd.h>
12e9cfb9aeSGarrett Wollman
13e9cfb9aeSGarrett Wollman#include "getconf.h"
14e9cfb9aeSGarrett Wollman
15e9cfb9aeSGarrett Wollman/*
16e9cfb9aeSGarrett Wollman * Override gperf's built-in external scope.
17e9cfb9aeSGarrett Wollman */
18a272cd3aSMark Murraystatic const struct map *in_word_set(const char *str);
19e9cfb9aeSGarrett Wollman
20e9cfb9aeSGarrett Wollman/*
21e9cfb9aeSGarrett Wollman * The Standard seems a bit ambiguous over whether the POSIX_V6_*
22e9cfb9aeSGarrett Wollman * are specified with or without a leading underscore, so we just
23e9cfb9aeSGarrett Wollman * use both.
24e9cfb9aeSGarrett Wollman */
25e9cfb9aeSGarrett Wollman/*
26e9cfb9aeSGarrett Wollman * The alt_path member gives the path containing another `getconf'
27e9cfb9aeSGarrett Wollman * executable which was compiled using the specified programming
28e9cfb9aeSGarrett Wollman * environment.  If it is NULL, the current executable is good enough.
29e9cfb9aeSGarrett Wollman * If we ever support multiple environments, this table will need to
30e9cfb9aeSGarrett Wollman * be updated.  (We cheat here and define the supported environments
31e9cfb9aeSGarrett Wollman * statically.)
32e9cfb9aeSGarrett Wollman */
33*b4b4b530SBaptiste Daroussin#if defined(__sparc64__) || defined(__amd64__)
34e9cfb9aeSGarrett Wollman#define	have_LP64_OFF64		NULL
35e9cfb9aeSGarrett Wollman#endif
36e9cfb9aeSGarrett Wollman
37*b4b4b530SBaptiste Daroussin#if defined(__i386__) || defined(__powerpc__)
38e9cfb9aeSGarrett Wollman#define	have_ILP32_OFFBIG	NULL
39e9cfb9aeSGarrett Wollman#endif
40e9cfb9aeSGarrett Wollman
41e9cfb9aeSGarrett Wollman%}
42e9cfb9aeSGarrett Wollmanstruct map { const char *name; const char *alt_path; int valid; };
43e9cfb9aeSGarrett Wollman%%
44e9cfb9aeSGarrett WollmanPOSIX_V6_ILP32_OFF32, notdef
45e9cfb9aeSGarrett WollmanPOSIX_V6_ILP32_OFFBIG, have_ILP32_OFFBIG
46e9cfb9aeSGarrett WollmanPOSIX_V6_LP64_OFF64, have_LP64_OFF64
47*b4b4b530SBaptiste DaroussinPOSIX_V6_LPBIG_OFFBIG, notdef
48e9cfb9aeSGarrett Wollman_POSIX_V6_ILP32_OFF32, notdef
49e9cfb9aeSGarrett Wollman_POSIX_V6_ILP32_OFFBIG, have_ILP32_OFFBIG
50e9cfb9aeSGarrett Wollman_POSIX_V6_LP64_OFF64, have_LP64_OFF64
51*b4b4b530SBaptiste Daroussin_POSIX_V6_LPBIG_OFFBIG, notdef
52e9cfb9aeSGarrett Wollman%%
53e9cfb9aeSGarrett Wollmanint
54e9cfb9aeSGarrett Wollmanfind_progenv(const char *name, const char **alt_path)
55e9cfb9aeSGarrett Wollman{
56e9cfb9aeSGarrett Wollman	const struct map *rv;
57e9cfb9aeSGarrett Wollman
58a272cd3aSMark Murray	rv = in_word_set(name);
59e9cfb9aeSGarrett Wollman	if (rv != NULL) {
60e9cfb9aeSGarrett Wollman		if (rv->valid) {
61e9cfb9aeSGarrett Wollman			*alt_path = rv->alt_path;
62e9cfb9aeSGarrett Wollman			return 1;
63e9cfb9aeSGarrett Wollman		}
64e9cfb9aeSGarrett Wollman		return -1;
65e9cfb9aeSGarrett Wollman	}
66e9cfb9aeSGarrett Wollman	return 0;
67e9cfb9aeSGarrett Wollman}
68