xref: /freebsd/usr.bin/getconf/sysconf.gperf (revision 814aaaa7da4dab462d90e12e7b48b75f2093ccfd)
1%{
2/*
3 * Copyright is disclaimed as to the contents of this file.
4 *
5 * $FreeBSD$
6 */
7
8#include <sys/types.h>
9
10#include <string.h>
11#include <unistd.h>
12#ifdef APPLE_GETCONF_UNDERSCORE
13#include <alloca.h>
14#endif /* APPLE_GETCONF_UNDERSCORE */
15
16#include "getconf.h"
17
18/*
19 * Override gperf's built-in external scope.
20 */
21static const struct map *in_word_set(const char *str);
22
23%}
24struct map { const char *name; int key; int valid; };
25%%
26AIO_LISTIO_MAX, _SC_AIO_LISTIO_MAX
27AIO_MAX, _SC_AIO_MAX
28AIO_PRIO_DELTA_MAX, _SC_AIO_PRIO_DELTA_MAX
29ARG_MAX, _SC_ARG_MAX
30ATEXIT_MAX, _SC_ATEXIT_MAX
31BC_BASE_MAX, _SC_BC_BASE_MAX
32BC_DIM_MAX, _SC_BC_DIM_MAX
33BC_SCALE_MAX, _SC_BC_SCALE_MAX
34BC_STRING_MAX, _SC_BC_STRING_MAX
35CHILD_MAX, _SC_CHILD_MAX
36CLK_TCK, _SC_CLK_TCK
37COLL_WEIGHTS_MAX, _SC_COLL_WEIGHTS_MAX
38DELAYTIMER_MAX, _SC_DELAYTIMER_MAX
39EXPR_NEST_MAX, _SC_EXPR_NEST_MAX
40GETGR_R_SIZE_MAX, _SC_GETGR_R_SIZE_MAX
41GETPW_R_SIZE_MAX, _SC_GETPW_R_SIZE_MAX
42HOST_NAME_MAX, _SC_HOST_NAME_MAX
43IOV_MAX, _SC_IOV_MAX
44LINE_MAX, _SC_LINE_MAX
45LOGIN_NAME_MAX, _SC_LOGIN_NAME_MAX
46MQ_OPEN_MAX, _SC_MQ_OPEN_MAX
47MQ_PRIO_MAX, _SC_MQ_PRIO_MAX
48NGROUPS_MAX, _SC_NGROUPS_MAX
49NPROCESSORS_CONF, _SC_NPROCESSORS_CONF
50NPROCESSORS_ONLN, _SC_NPROCESSORS_ONLN
51OPEN_MAX, _SC_OPEN_MAX
52PAGESIZE, _SC_PAGESIZE
53PAGE_SIZE, _SC_PAGESIZE
54PASS_MAX, _SC_PASS_MAX
55PTHREAD_DESTRUCTOR_ITERATIONS, _SC_THREAD_DESTRUCTOR_ITERATIONS
56PTHREAD_KEYS_MAX, _SC_THREAD_KEYS_MAX
57PTHREAD_STACK_MIN, _SC_THREAD_STACK_MIN
58PTHREAD_THREADS_MAX, _SC_THREAD_THREADS_MAX
59RE_DUP_MAX, _SC_RE_DUP_MAX
60RTSIG_MAX, _SC_RTSIG_MAX
61SEM_NSEMS_MAX, _SC_SEM_NSEMS_MAX
62SEM_VALUE_MAX, _SC_SEM_VALUE_MAX
63SIGQUEUE_MAX, _SC_SIGQUEUE_MAX
64STREAM_MAX, _SC_STREAM_MAX
65SYMLOOP_MAX, _SC_SYMLOOP_MAX
66TIMER_MAX, _SC_TIMER_MAX
67TTY_NAME_MAX, _SC_TTY_NAME_MAX
68TZNAME_MAX, _SC_TZNAME_MAX
69_POSIX2_CHAR_TERM, _SC_2_CHAR_TERM
70_POSIX2_C_BIND, _SC_2_C_BIND
71_POSIX2_C_DEV, _SC_2_C_DEV
72_POSIX2_C_VERSION, _SC_2_C_VERSION
73_POSIX2_FORT_DEV, _SC_2_FORT_DEV
74_POSIX2_FORT_RUN, _SC_2_FORT_RUN
75_POSIX2_LOCALEDEF, _SC_2_LOCALEDEF
76_POSIX2_PBS, _SC_PBS
77_POSIX2_PBS_ACCOUNTING, _SC_PBS_ACCOUNTING
78_POSIX2_PBS_CHECKPOINT, _SC_PBS_CHECKPOINT
79_POSIX2_PBS_LOCATE, _SC_PBS_LOCATE
80_POSIX2_PBS_MESSAGE, _SC_PBS_MESSAGE
81_POSIX2_PBS_TRACK, _SC_PBS_TRACK
82_POSIX2_SW_DEV, _SC_2_SW_DEV
83_POSIX2_UPE, _SC_2_UPE
84_POSIX2_VERSION, _SC_2_VERSION
85_POSIX_ADVISORY_INFO, _SC_ADVISORY_INFO
86_POSIX_ASYNCHRONOUS_IO, _SC_ASYNCHRONOUS_IO
87_POSIX_BARRIERS, _SC_BARRIERS
88_POSIX_CLOCK_SELECTION, _SC_CLOCK_SELECTION
89_POSIX_CPUTIME, _SC_CPUTIME
90_POSIX_FILE_LOCKING, _SC_FILE_LOCKING
91_POSIX_FSYNC, _SC_FSYNC
92_POSIX_IPV6, _SC_IPV6
93_POSIX_JOB_CONTROL, _SC_JOB_CONTROL
94_POSIX_MAPPED_FILES, _SC_MAPPED_FILES
95_POSIX_MEMLOCK, _SC_MEMLOCK
96_POSIX_MEMLOCK_RANGE, _SC_MEMLOCK_RANGE
97_POSIX_MEMORY_PROTECTION, _SC_MEMORY_PROTECTION
98_POSIX_MESSAGE_PASSING, _SC_MESSAGE_PASSING
99_POSIX_MONOTONIC_CLOCK, _SC_MONOTONIC_CLOCK
100_POSIX_PRIORITIZED_IO, _SC_PRIORITIZED_IO
101_POSIX_PRIORITY_SCHEDULING, _SC_PRIORITY_SCHEDULING
102_POSIX_RAW_SOCKETS, _SC_RAW_SOCKETS
103_POSIX_READER_WRITER_LOCKS, _SC_READER_WRITER_LOCKS
104_POSIX_REALTIME_SIGNALS, _SC_REALTIME_SIGNALS
105_POSIX_REGEXP, _SC_REGEXP
106_POSIX_SAVED_IDS, _SC_SAVED_IDS
107_POSIX_SEMAPHORES, _SC_SEMAPHORES
108_POSIX_SHARED_MEMORY_OBJECTS, _SC_SHARED_MEMORY_OBJECTS
109_POSIX_SHELL, _SC_SHELL
110_POSIX_SPAWN, _SC_SPAWN
111_POSIX_SPIN_LOCKS, _SC_SPIN_LOCKS
112_POSIX_SPORADIC_SERVER, _SC_SPORADIC_SERVER
113_POSIX_SS_REPL_MAX, _SC_SS_REPL_MAX
114_POSIX_SYNCHRONIZED_IO, _SC_SYNCHRONIZED_IO
115_POSIX_THREADS, _SC_THREADS
116_POSIX_THREAD_ATTR_STACKADDR, _SC_THREAD_ATTR_STACKADDR
117_POSIX_THREAD_ATTR_STACKSIZE, _SC_THREAD_ATTR_STACKSIZE
118_POSIX_THREAD_CPUTIME, _SC_THREAD_CPUTIME
119_POSIX_THREAD_PRIORITY_SCHEDULING, _SC_THREAD_PRIORITY_SCHEDULING
120_POSIX_THREAD_PRIO_INHERIT, _SC_THREAD_PRIO_INHERIT
121_POSIX_THREAD_PRIO_PROTECT, _SC_THREAD_PRIO_PROTECT
122_POSIX_THREAD_PROCESS_SHARED, _SC_THREAD_PROCESS_SHARED
123_POSIX_THREAD_SAFE_FUNCTIONS, _SC_THREAD_SAFE_FUNCTIONS
124_POSIX_THREAD_SPORADIC_SERVER, _SC_THREAD_SPORADIC_SERVER
125_POSIX_TIMEOUTS, _SC_TIMEOUTS
126_POSIX_TIMERS, _SC_TIMERS
127_POSIX_TRACE, _SC_TRACE
128_POSIX_TRACE_EVENT_FILTER, _SC_TRACE_EVENT_FILTER
129_POSIX_TRACE_EVENT_NAME_MAX, _SC_TRACE_EVENT_NAME_MAX
130_POSIX_TRACE_INHERIT, _SC_TRACE_INHERIT
131_POSIX_TRACE_LOG, _SC_TRACE_LOG
132_POSIX_TRACE_NAME_MAX, _SC_TRACE_NAME_MAX
133_POSIX_TRACE_SYS_MAX, _SC_TRACE_SYS_MAX
134_POSIX_TRACE_USER_EVENT_MAX, _SC_TRACE_USER_EVENT_MAX
135_POSIX_TYPED_MEMORY_OBJECTS, _SC_TYPED_MEMORY_OBJECTS
136_POSIX_V6_ILP32_OFF32, _SC_V6_ILP32_OFF32
137_POSIX_V6_ILP32_OFFBIG, _SC_V6_ILP32_OFFBIG
138_POSIX_V6_LP64_OFF64, _SC_V6_LP64_OFF64
139_POSIX_V6_LPBIG_OFFBIG, _SC_V6_LPBIG_OFFBIG
140_POSIX_VERSION, _SC_VERSION
141_XOPEN_CRYPT, _SC_XOPEN_CRYPT
142_XOPEN_ENH_I18N, _SC_XOPEN_ENH_I18N
143_XOPEN_LEGACY, _SC_XOPEN_LEGACY
144_XOPEN_REALTIME, _SC_XOPEN_REALTIME
145_XOPEN_REALTIME_THREADS, _SC_XOPEN_REALTIME_THREADS
146_XOPEN_SHM, _SC_XOPEN_SHM
147_XOPEN_STREAMS, _SC_XOPEN_STREAMS
148_XOPEN_UNIX, _SC_XOPEN_UNIX
149_XOPEN_VERSION, _SC_XOPEN_VERSION
150_XOPEN_XCU_VERSION, _SC_XCU_VERSION
151%%
152int
153find_sysconf(const char *name, int *key)
154{
155	const struct map *rv;
156#ifdef APPLE_GETCONF_UNDERSCORE
157	char *alt;
158#endif /* APPLE_GETCONF_UNDERSCORE */
159
160	rv = in_word_set(name);
161	if (rv != NULL) {
162		if (rv->valid) {
163			*key = rv->key;
164			return 1;
165		}
166		return -1;
167	}
168#ifdef APPLE_GETCONF_UNDERSCORE
169	if(*name == '_')
170		alt = (char *)name + 1;
171	else {
172		if((alt = (char *)alloca(strlen(name) + 2)) == NULL)
173			return 0;
174		*alt = '_';
175		strcpy(alt + 1, name);
176	}
177	rv = in_word_set(alt);
178	if (rv != NULL) {
179		if (rv->valid) {
180			*key = rv->key;
181			return 1;
182		}
183		return -1;
184	}
185#endif /* APPLE_GETCONF_UNDERSCORE */
186	return 0;
187}
188