1 |
|
|
/* $OpenBSD: getconf.c,v 1.18 2015/11/17 17:29:27 jca Exp $ */ |
2 |
|
|
|
3 |
|
|
/*- |
4 |
|
|
* Copyright (c) 1996 The NetBSD Foundation, Inc. |
5 |
|
|
* All rights reserved. |
6 |
|
|
* |
7 |
|
|
* This code is derived from software contributed to The NetBSD Foundation |
8 |
|
|
* by J.T. Conklin. |
9 |
|
|
* |
10 |
|
|
* Redistribution and use in source and binary forms, with or without |
11 |
|
|
* modification, are permitted provided that the following conditions |
12 |
|
|
* are met: |
13 |
|
|
* 1. Redistributions of source code must retain the above copyright |
14 |
|
|
* notice, this list of conditions and the following disclaimer. |
15 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright |
16 |
|
|
* notice, this list of conditions and the following disclaimer in the |
17 |
|
|
* documentation and/or other materials provided with the distribution. |
18 |
|
|
* 3. All advertising materials mentioning features or use of this software |
19 |
|
|
* must display the following acknowledgement: |
20 |
|
|
* This product includes software developed by Winning Strategies, Inc. |
21 |
|
|
* 4. The name of the author may not be used to endorse or promote products |
22 |
|
|
* derived from this software without specific prior written permission. |
23 |
|
|
* |
24 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
25 |
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
26 |
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
27 |
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
28 |
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
29 |
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
30 |
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
31 |
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
32 |
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
33 |
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
34 |
|
|
*/ |
35 |
|
|
|
36 |
|
|
/* |
37 |
|
|
* POSIX.2 getconf utility |
38 |
|
|
* |
39 |
|
|
* Written by: |
40 |
|
|
* J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. |
41 |
|
|
*/ |
42 |
|
|
|
43 |
|
|
#include <stdio.h> |
44 |
|
|
#include <stdlib.h> |
45 |
|
|
#include <string.h> |
46 |
|
|
#include <limits.h> |
47 |
|
|
#include <locale.h> |
48 |
|
|
#include <unistd.h> |
49 |
|
|
#include <err.h> |
50 |
|
|
#include <errno.h> |
51 |
|
|
|
52 |
|
|
static void usage(void); |
53 |
|
|
static void list_var(int); |
54 |
|
|
static int compilation_spec_valid(const char *); |
55 |
|
|
|
56 |
|
|
struct conf_variable |
57 |
|
|
{ |
58 |
|
|
const char *name; |
59 |
|
|
enum { SYSCONF, CONFSTR, PATHCONF, CONSTANT } type; |
60 |
|
|
long value; |
61 |
|
|
}; |
62 |
|
|
|
63 |
|
|
|
64 |
|
|
#define constant_row(name) { #name, CONSTANT, name }, |
65 |
|
|
#define sysconf_row(name) { #name, SYSCONF, _SC_##name }, |
66 |
|
|
#define pathconf_row(name) { #name, PATHCONF, _PC_##name }, |
67 |
|
|
#define confstr_row(name) { #name, CONFSTR, _CS_##name }, |
68 |
|
|
#define posix_constant_row(name) { #name, CONSTANT, _POSIX_##name }, |
69 |
|
|
#define posix_confstr_row(name) { #name, CONFSTR, _CS_POSIX_##name }, |
70 |
|
|
#define compat_posix2_sysconf_row(name) { #name, SYSCONF, _SC_2_##name }, |
71 |
|
|
#define compat_posix2_constant_row(name) { #name, CONSTANT, _POSIX2_##name }, |
72 |
|
|
|
73 |
|
|
/* Some sysconf variables don't follow the pattern of the others */ |
74 |
|
|
#define posix2_sysconf_row(name) \ |
75 |
|
|
{ "_POSIX2_" #name, SYSCONF, _SC_2_##name }, |
76 |
|
|
#define posix2_pathconf_row(name) \ |
77 |
|
|
{ "_POSIX2_" #name, PATHCONF, _PC_2_##name }, |
78 |
|
|
#define pthread_sysconf_row(name) \ |
79 |
|
|
{ "_PTHREAD_" #name, SYSCONF, _SC_THREAD_##name }, |
80 |
|
|
#define xopen_sysconf_row(name) \ |
81 |
|
|
{ "_XOPEN_" #name, SYSCONF, _SC_XOPEN_##name }, |
82 |
|
|
|
83 |
|
|
const struct conf_variable conf_table[] = |
84 |
|
|
{ |
85 |
|
|
/* Configuration strings */ |
86 |
|
|
confstr_row(PATH) |
87 |
|
|
confstr_row(V7_ENV) |
88 |
|
|
confstr_row(V6_ENV) |
89 |
|
|
|
90 |
|
|
/* Symbolic Utility Limits */ |
91 |
|
|
sysconf_row(BC_BASE_MAX) |
92 |
|
|
sysconf_row(BC_DIM_MAX) |
93 |
|
|
sysconf_row(BC_SCALE_MAX) |
94 |
|
|
sysconf_row(BC_STRING_MAX) |
95 |
|
|
sysconf_row(COLL_WEIGHTS_MAX) |
96 |
|
|
sysconf_row(EXPR_NEST_MAX) |
97 |
|
|
sysconf_row(LINE_MAX) |
98 |
|
|
sysconf_row(RE_DUP_MAX) |
99 |
|
|
|
100 |
|
|
/* POSIX.1 Configurable System Variables */ |
101 |
|
|
sysconf_row(AIO_LISTIO_MAX) |
102 |
|
|
sysconf_row(AIO_MAX) |
103 |
|
|
sysconf_row(AIO_PRIO_DELTA_MAX) |
104 |
|
|
sysconf_row(ARG_MAX) |
105 |
|
|
sysconf_row(CHILD_MAX) |
106 |
|
|
sysconf_row(CLK_TCK) |
107 |
|
|
sysconf_row(NGROUPS_MAX) |
108 |
|
|
sysconf_row(OPEN_MAX) |
109 |
|
|
sysconf_row(STREAM_MAX) |
110 |
|
|
sysconf_row(TZNAME_MAX) |
111 |
|
|
sysconf_row(PAGE_SIZE) |
112 |
|
|
sysconf_row(PAGESIZE) |
113 |
|
|
|
114 |
|
|
sysconf_row(SEM_NSEMS_MAX) |
115 |
|
|
sysconf_row(SEM_VALUE_MAX) |
116 |
|
|
sysconf_row(HOST_NAME_MAX) |
117 |
|
|
sysconf_row(LOGIN_NAME_MAX) |
118 |
|
|
|
119 |
|
|
sysconf_row(ATEXIT_MAX) |
120 |
|
|
sysconf_row(DELAYTIMER_MAX) |
121 |
|
|
sysconf_row(IOV_MAX) |
122 |
|
|
sysconf_row(MQ_OPEN_MAX) |
123 |
|
|
sysconf_row(MQ_PRIO_MAX) |
124 |
|
|
sysconf_row(RTSIG_MAX) |
125 |
|
|
sysconf_row(SIGQUEUE_MAX) |
126 |
|
|
sysconf_row(SYMLOOP_MAX) |
127 |
|
|
sysconf_row(TIMER_MAX) |
128 |
|
|
sysconf_row(TTY_NAME_MAX) |
129 |
|
|
|
130 |
|
|
posix2_sysconf_row(PBS) |
131 |
|
|
posix2_sysconf_row(PBS_ACCOUNTING) |
132 |
|
|
posix2_sysconf_row(PBS_CHECKPOINT) |
133 |
|
|
posix2_sysconf_row(PBS_LOCATE) |
134 |
|
|
posix2_sysconf_row(PBS_MESSAGE) |
135 |
|
|
posix2_sysconf_row(PBS_TRACK) |
136 |
|
|
|
137 |
|
|
pthread_sysconf_row(DESTRUCTOR_ITERATIONS) |
138 |
|
|
pthread_sysconf_row(KEYS_MAX) |
139 |
|
|
pthread_sysconf_row(STACK_MIN) |
140 |
|
|
pthread_sysconf_row(THREADS_MAX) |
141 |
|
|
|
142 |
|
|
xopen_sysconf_row(SHM) |
143 |
|
|
xopen_sysconf_row(CRYPT) |
144 |
|
|
xopen_sysconf_row(ENH_I18N) |
145 |
|
|
xopen_sysconf_row(REALTIME) |
146 |
|
|
xopen_sysconf_row(REALTIME_THREADS) |
147 |
|
|
xopen_sysconf_row(STREAMS) |
148 |
|
|
xopen_sysconf_row(UNIX) |
149 |
|
|
xopen_sysconf_row(UUCP) |
150 |
|
|
xopen_sysconf_row(VERSION) |
151 |
|
|
|
152 |
|
|
pathconf_row(FILESIZEBITS) |
153 |
|
|
pathconf_row(LINK_MAX) |
154 |
|
|
pathconf_row(MAX_CANON) |
155 |
|
|
pathconf_row(MAX_INPUT) |
156 |
|
|
pathconf_row(NAME_MAX) |
157 |
|
|
pathconf_row(PATH_MAX) |
158 |
|
|
pathconf_row(PIPE_BUF) |
159 |
|
|
pathconf_row(SYMLINK_MAX) |
160 |
|
|
|
161 |
|
|
posix2_pathconf_row(SYMLINKS) |
162 |
|
|
|
163 |
|
|
constant_row(_POSIX2_CHARCLASS_NAME_MAX) |
164 |
|
|
constant_row(_XOPEN_IOV_MAX) |
165 |
|
|
constant_row(_XOPEN_NAME_MAX) |
166 |
|
|
constant_row(_XOPEN_PATH_MAX) |
167 |
|
|
|
168 |
|
|
/* Extensions */ |
169 |
|
|
sysconf_row(PHYS_PAGES) |
170 |
|
|
sysconf_row(AVPHYS_PAGES) |
171 |
|
|
sysconf_row(NPROCESSORS_CONF) |
172 |
|
|
sysconf_row(NPROCESSORS_ONLN) |
173 |
|
|
|
174 |
|
|
{ NULL } |
175 |
|
|
}; |
176 |
|
|
|
177 |
|
|
/* |
178 |
|
|
* Lots of names have a leading "_POSIX_", so put them in a table with |
179 |
|
|
* that prefix trimmed |
180 |
|
|
*/ |
181 |
|
|
const char uposix_prefix[] = "_POSIX_"; |
182 |
|
|
const struct conf_variable uposix_conf_table[] = |
183 |
|
|
{ |
184 |
|
|
/* POSIX.1 Maximum Values */ |
185 |
|
|
posix_constant_row(CLOCKRES_MIN) |
186 |
|
|
|
187 |
|
|
/* POSIX.1 Minimum Values */ |
188 |
|
|
/*posix_constant_row(AIO_LISTIO_MAX)*/ |
189 |
|
|
/*posix_constant_row(AIO_MAX)*/ |
190 |
|
|
posix_constant_row(ARG_MAX) |
191 |
|
|
posix_constant_row(CHILD_MAX) |
192 |
|
|
/*posix_constant_row(DELAYTIMER_MAX)*/ |
193 |
|
|
posix_constant_row(HOST_NAME_MAX) |
194 |
|
|
posix_constant_row(LINK_MAX) |
195 |
|
|
posix_constant_row(LOGIN_NAME_MAX) |
196 |
|
|
posix_constant_row(MAX_CANON) |
197 |
|
|
posix_constant_row(MAX_INPUT) |
198 |
|
|
/*posix_constant_row(MQ_OPEN_MAX)*/ |
199 |
|
|
/*posix_constant_row(MQ_PRIO_MAX)*/ |
200 |
|
|
posix_constant_row(NAME_MAX) |
201 |
|
|
posix_constant_row(NGROUPS_MAX) |
202 |
|
|
posix_constant_row(OPEN_MAX) |
203 |
|
|
posix_constant_row(PATH_MAX) |
204 |
|
|
posix_constant_row(PIPE_BUF) |
205 |
|
|
posix_constant_row(RE_DUP_MAX) |
206 |
|
|
/*posix_constant_row(RTSIG_MAX)*/ |
207 |
|
|
posix_constant_row(SEM_NSEMS_MAX) |
208 |
|
|
posix_constant_row(SEM_VALUE_MAX) |
209 |
|
|
/*posix_constant_row(SIGQUEUE_MAX)*/ |
210 |
|
|
posix_constant_row(SSIZE_MAX) |
211 |
|
|
/*posix_constant_row(SS_REPL_MAX)*/ |
212 |
|
|
posix_constant_row(STREAM_MAX) |
213 |
|
|
posix_constant_row(SYMLINK_MAX) |
214 |
|
|
posix_constant_row(SYMLOOP_MAX) |
215 |
|
|
posix_constant_row(THREAD_DESTRUCTOR_ITERATIONS) |
216 |
|
|
posix_constant_row(THREAD_KEYS_MAX) |
217 |
|
|
posix_constant_row(THREAD_THREADS_MAX) |
218 |
|
|
/*posix_constant_row(TIMER_MAX)*/ |
219 |
|
|
posix_constant_row(TTY_NAME_MAX) |
220 |
|
|
posix_constant_row(TZNAME_MAX) |
221 |
|
|
|
222 |
|
|
/* POSIX.1 Configurable System Variables */ |
223 |
|
|
sysconf_row(JOB_CONTROL) |
224 |
|
|
sysconf_row(SAVED_IDS) |
225 |
|
|
sysconf_row(VERSION) |
226 |
|
|
sysconf_row(FSYNC) |
227 |
|
|
sysconf_row(MONOTONIC_CLOCK) |
228 |
|
|
sysconf_row(THREAD_SAFE_FUNCTIONS) |
229 |
|
|
sysconf_row(ADVISORY_INFO) |
230 |
|
|
sysconf_row(BARRIERS) |
231 |
|
|
sysconf_row(ASYNCHRONOUS_IO) |
232 |
|
|
sysconf_row(CLOCK_SELECTION) |
233 |
|
|
sysconf_row(CPUTIME) |
234 |
|
|
sysconf_row(IPV6) |
235 |
|
|
sysconf_row(MAPPED_FILES) |
236 |
|
|
sysconf_row(MEMLOCK) |
237 |
|
|
sysconf_row(MEMLOCK_RANGE) |
238 |
|
|
sysconf_row(MEMORY_PROTECTION) |
239 |
|
|
sysconf_row(MESSAGE_PASSING) |
240 |
|
|
sysconf_row(PRIORITIZED_IO) |
241 |
|
|
sysconf_row(PRIORITY_SCHEDULING) |
242 |
|
|
sysconf_row(RAW_SOCKETS) |
243 |
|
|
sysconf_row(READER_WRITER_LOCKS) |
244 |
|
|
sysconf_row(REALTIME_SIGNALS) |
245 |
|
|
sysconf_row(REGEXP) |
246 |
|
|
sysconf_row(SEMAPHORES) |
247 |
|
|
sysconf_row(SHARED_MEMORY_OBJECTS) |
248 |
|
|
sysconf_row(SHELL) |
249 |
|
|
sysconf_row(SPAWN) |
250 |
|
|
sysconf_row(SPIN_LOCKS) |
251 |
|
|
sysconf_row(SPORADIC_SERVER) |
252 |
|
|
sysconf_row(SS_REPL_MAX) |
253 |
|
|
sysconf_row(SYNCHRONIZED_IO) |
254 |
|
|
sysconf_row(THREAD_ATTR_STACKADDR) |
255 |
|
|
sysconf_row(THREAD_ATTR_STACKSIZE) |
256 |
|
|
sysconf_row(THREAD_CPUTIME) |
257 |
|
|
sysconf_row(THREAD_PRIO_INHERIT) |
258 |
|
|
sysconf_row(THREAD_PRIO_PROTECT) |
259 |
|
|
sysconf_row(THREAD_PRIORITY_SCHEDULING) |
260 |
|
|
sysconf_row(THREAD_PROCESS_SHARED) |
261 |
|
|
sysconf_row(THREAD_ROBUST_PRIO_INHERIT) |
262 |
|
|
sysconf_row(THREAD_SPORADIC_SERVER) |
263 |
|
|
sysconf_row(THREADS) |
264 |
|
|
sysconf_row(TIMEOUTS) |
265 |
|
|
sysconf_row(TIMERS) |
266 |
|
|
sysconf_row(TRACE) |
267 |
|
|
sysconf_row(TRACE_EVENT_FILTER) |
268 |
|
|
sysconf_row(TRACE_EVENT_NAME_MAX) |
269 |
|
|
sysconf_row(TRACE_INHERIT) |
270 |
|
|
sysconf_row(TRACE_LOG) |
271 |
|
|
sysconf_row(TRACE_NAME_MAX) |
272 |
|
|
sysconf_row(TRACE_SYS_MAX) |
273 |
|
|
sysconf_row(TRACE_USER_EVENT_MAX) |
274 |
|
|
sysconf_row(TYPED_MEMORY_OBJECTS) |
275 |
|
|
|
276 |
|
|
/* |
277 |
|
|
* If new compilation specification are added (V8_*?) then add them |
278 |
|
|
* to the compilation_specs array below too |
279 |
|
|
*/ |
280 |
|
|
sysconf_row(V7_ILP32_OFF32) |
281 |
|
|
sysconf_row(V7_ILP32_OFFBIG) |
282 |
|
|
sysconf_row(V7_LP64_OFF64) |
283 |
|
|
sysconf_row(V7_LPBIG_OFFBIG) |
284 |
|
|
sysconf_row(V6_ILP32_OFF32) |
285 |
|
|
sysconf_row(V6_ILP32_OFFBIG) |
286 |
|
|
sysconf_row(V6_LP64_OFF64) |
287 |
|
|
sysconf_row(V6_LPBIG_OFFBIG) |
288 |
|
|
|
289 |
|
|
/* POSIX.1 Configurable Path Variables */ |
290 |
|
|
pathconf_row(CHOWN_RESTRICTED) |
291 |
|
|
pathconf_row(NO_TRUNC) |
292 |
|
|
pathconf_row(VDISABLE) |
293 |
|
|
pathconf_row(ASYNC_IO) |
294 |
|
|
pathconf_row(PRIO_IO) |
295 |
|
|
pathconf_row(SYNC_IO) |
296 |
|
|
pathconf_row(TIMESTAMP_RESOLUTION) |
297 |
|
|
|
298 |
|
|
{ NULL } |
299 |
|
|
}; |
300 |
|
|
|
301 |
|
|
/* |
302 |
|
|
* Then there are the "POSIX_*" values |
303 |
|
|
*/ |
304 |
|
|
const char posix_prefix[] = "POSIX_"; |
305 |
|
|
const struct conf_variable posix_conf_table[] = |
306 |
|
|
{ |
307 |
|
|
pathconf_row(ALLOC_SIZE_MIN) |
308 |
|
|
pathconf_row(REC_INCR_XFER_SIZE) |
309 |
|
|
pathconf_row(REC_MAX_XFER_SIZE) |
310 |
|
|
pathconf_row(REC_MIN_XFER_SIZE) |
311 |
|
|
pathconf_row(REC_XFER_ALIGN) |
312 |
|
|
|
313 |
|
|
posix_confstr_row(V7_ILP32_OFF32_CFLAGS) |
314 |
|
|
posix_confstr_row(V7_ILP32_OFF32_LDFLAGS) |
315 |
|
|
posix_confstr_row(V7_ILP32_OFF32_LIBS) |
316 |
|
|
posix_confstr_row(V7_ILP32_OFFBIG_CFLAGS) |
317 |
|
|
posix_confstr_row(V7_ILP32_OFFBIG_LDFLAGS) |
318 |
|
|
posix_confstr_row(V7_ILP32_OFFBIG_LIBS) |
319 |
|
|
posix_confstr_row(V7_LP64_OFF64_CFLAGS) |
320 |
|
|
posix_confstr_row(V7_LP64_OFF64_LDFLAGS) |
321 |
|
|
posix_confstr_row(V7_LP64_OFF64_LIBS) |
322 |
|
|
posix_confstr_row(V7_LPBIG_OFFBIG_CFLAGS) |
323 |
|
|
posix_confstr_row(V7_LPBIG_OFFBIG_LDFLAGS) |
324 |
|
|
posix_confstr_row(V7_LPBIG_OFFBIG_LIBS) |
325 |
|
|
posix_confstr_row(V7_THREADS_CFLAGS) |
326 |
|
|
posix_confstr_row(V7_THREADS_LDFLAGS) |
327 |
|
|
posix_confstr_row(V7_WIDTH_RESTRICTED_ENVS) |
328 |
|
|
posix_confstr_row(V6_ILP32_OFF32_CFLAGS) |
329 |
|
|
posix_confstr_row(V6_ILP32_OFF32_LDFLAGS) |
330 |
|
|
posix_confstr_row(V6_ILP32_OFF32_LIBS) |
331 |
|
|
posix_confstr_row(V6_ILP32_OFFBIG_CFLAGS) |
332 |
|
|
posix_confstr_row(V6_ILP32_OFFBIG_LDFLAGS) |
333 |
|
|
posix_confstr_row(V6_ILP32_OFFBIG_LIBS) |
334 |
|
|
posix_confstr_row(V6_LP64_OFF64_CFLAGS) |
335 |
|
|
posix_confstr_row(V6_LP64_OFF64_LDFLAGS) |
336 |
|
|
posix_confstr_row(V6_LP64_OFF64_LIBS) |
337 |
|
|
posix_confstr_row(V6_LPBIG_OFFBIG_CFLAGS) |
338 |
|
|
posix_confstr_row(V6_LPBIG_OFFBIG_LDFLAGS) |
339 |
|
|
posix_confstr_row(V6_LPBIG_OFFBIG_LIBS) |
340 |
|
|
posix_confstr_row(V6_WIDTH_RESTRICTED_ENVS) |
341 |
|
|
|
342 |
|
|
{ NULL } |
343 |
|
|
}; |
344 |
|
|
|
345 |
|
|
/* |
346 |
|
|
* Finally, there are variables that are accepted with a prefix |
347 |
|
|
* of either "_POSIX2_" or "POSIX2_" |
348 |
|
|
*/ |
349 |
|
|
const char compat_posix2_prefix[] = "POSIX2_"; |
350 |
|
|
const struct conf_variable compat_posix2_conf_table[] = |
351 |
|
|
{ |
352 |
|
|
/* Optional Facility Configuration Values */ |
353 |
|
|
compat_posix2_sysconf_row(VERSION) |
354 |
|
|
compat_posix2_sysconf_row(C_BIND) |
355 |
|
|
compat_posix2_sysconf_row(C_DEV) |
356 |
|
|
compat_posix2_sysconf_row(CHAR_TERM) |
357 |
|
|
compat_posix2_sysconf_row(FORT_DEV) |
358 |
|
|
compat_posix2_sysconf_row(FORT_RUN) |
359 |
|
|
compat_posix2_sysconf_row(LOCALEDEF) |
360 |
|
|
compat_posix2_sysconf_row(SW_DEV) |
361 |
|
|
compat_posix2_sysconf_row(UPE) |
362 |
|
|
|
363 |
|
|
/* Utility Limit Minimum Values */ |
364 |
|
|
compat_posix2_constant_row(BC_BASE_MAX) |
365 |
|
|
compat_posix2_constant_row(BC_DIM_MAX) |
366 |
|
|
compat_posix2_constant_row(BC_SCALE_MAX) |
367 |
|
|
compat_posix2_constant_row(BC_STRING_MAX) |
368 |
|
|
compat_posix2_constant_row(COLL_WEIGHTS_MAX) |
369 |
|
|
compat_posix2_constant_row(EXPR_NEST_MAX) |
370 |
|
|
compat_posix2_constant_row(LINE_MAX) |
371 |
|
|
compat_posix2_constant_row(RE_DUP_MAX) |
372 |
|
|
|
373 |
|
|
{ NULL } |
374 |
|
|
}; |
375 |
|
|
|
376 |
|
|
#undef constant_row |
377 |
|
|
#undef sysconf_row |
378 |
|
|
#undef pathconf_row |
379 |
|
|
#undef confstr_row |
380 |
|
|
#undef posix_constant_row |
381 |
|
|
#undef posix_confstr_row |
382 |
|
|
#undef compat_posix2_sysconf_row |
383 |
|
|
#undef compat_posix2_constant_row |
384 |
|
|
|
385 |
|
|
|
386 |
|
|
/* |
387 |
|
|
* What values are possibly accepted by the -v option? |
388 |
|
|
* These are implied to have a prefix of posix_prefix |
389 |
|
|
*/ |
390 |
|
|
const char *compilation_specs[] = { |
391 |
|
|
"V7_ILP32_OFF32", |
392 |
|
|
"V7_ILP32_OFFBIG", |
393 |
|
|
"V7_LP64_OFF64", |
394 |
|
|
"V7_LPBIG_OFFBIG", |
395 |
|
|
"V6_ILP32_OFF32", |
396 |
|
|
"V6_ILP32_OFFBIG", |
397 |
|
|
"V6_LP64_OFF64", |
398 |
|
|
"V6_LPBIG_OFFBIG", |
399 |
|
|
NULL |
400 |
|
|
}; |
401 |
|
|
|
402 |
|
|
int |
403 |
|
|
main(int argc, char *argv[]) |
404 |
|
2 |
{ |
405 |
|
|
int ch; |
406 |
|
|
const struct conf_variable *cp; |
407 |
|
|
|
408 |
|
|
long val; |
409 |
|
|
size_t slen; |
410 |
|
|
char * sval; |
411 |
|
|
|
412 |
|
2 |
setlocale(LC_ALL, ""); |
413 |
|
|
|
414 |
✗✓ |
4 |
while ((ch = getopt(argc, argv, "lLv:")) != -1) { |
415 |
|
|
switch (ch) { |
416 |
|
|
case 'l': /* nonstandard: list system variables */ |
417 |
|
|
list_var(0); |
418 |
|
|
return (0); |
419 |
|
|
case 'L': /* nonstandard: list path variables */ |
420 |
|
|
list_var(1); |
421 |
|
|
return (0); |
422 |
|
|
case 'v': |
423 |
|
|
if (! compilation_spec_valid(optarg)) |
424 |
|
|
errx(1, "%s: unknown specification", optarg); |
425 |
|
|
break; |
426 |
|
|
case '?': |
427 |
|
|
default: |
428 |
|
|
usage(); |
429 |
|
|
} |
430 |
|
|
} |
431 |
|
2 |
argc -= optind; |
432 |
|
2 |
argv += optind; |
433 |
|
|
|
434 |
✗✓ |
2 |
if (argc < 1 || argc > 2) |
435 |
|
|
usage(); |
436 |
|
|
|
437 |
|
|
/* pick a table based on a possible prefix */ |
438 |
✗✓ |
2 |
if (strncmp(*argv, uposix_prefix, sizeof(uposix_prefix) - 1) == 0) { |
439 |
|
|
cp = uposix_conf_table; |
440 |
|
|
slen = sizeof(uposix_prefix) - 1; |
441 |
✗✓ |
2 |
} else if (strncmp(*argv, posix_prefix, |
442 |
|
|
sizeof(posix_prefix) - 1) == 0) { |
443 |
|
|
cp = posix_conf_table; |
444 |
|
|
slen = sizeof(posix_prefix) - 1; |
445 |
|
|
} else { |
446 |
|
2 |
cp = conf_table; |
447 |
|
2 |
slen = 0; |
448 |
|
|
} |
449 |
|
|
|
450 |
|
|
/* scan the table */ |
451 |
|
|
for (; cp->name != NULL; cp++) |
452 |
✓✗ |
2 |
if (strcmp(*argv + slen, cp->name) == 0) |
453 |
|
2 |
break; |
454 |
|
|
|
455 |
|
|
/* |
456 |
|
|
* If no match, then make a final check against |
457 |
|
|
* compat_posix2_conf_table, with special magic to accept/skip |
458 |
|
|
* a leading underbar |
459 |
|
|
*/ |
460 |
|
2 |
slen = argv[0][0] == '_'; |
461 |
✗✓✗✗
|
2 |
if (cp->name == NULL && strncmp(*argv + slen, compat_posix2_prefix, |
462 |
|
|
sizeof(compat_posix2_prefix) - 1) == 0) { |
463 |
|
|
slen += sizeof(compat_posix2_prefix) - 1; |
464 |
|
|
for (cp = compat_posix2_conf_table; cp->name != NULL; cp++) { |
465 |
|
|
if (strcmp(*argv + slen, cp->name) == 0) |
466 |
|
|
break; |
467 |
|
|
} |
468 |
|
|
} |
469 |
|
|
|
470 |
✗✓ |
2 |
if (cp->name == NULL) |
471 |
|
|
errx(1, "%s: unknown variable", *argv); |
472 |
|
|
|
473 |
✗✓ |
2 |
if (cp->type == PATHCONF) { |
474 |
|
|
if (argc != 2) usage(); |
475 |
|
|
} else { |
476 |
✗✓ |
2 |
if (argc != 1) usage(); |
477 |
|
|
} |
478 |
|
|
|
479 |
✗✓✗✗ ✗ |
2 |
switch (cp->type) { |
480 |
|
|
case CONSTANT: |
481 |
|
|
if (pledge("stdio wpath cpath rpath", NULL) == -1) |
482 |
|
|
err(1, "pledge"); |
483 |
|
|
printf("%ld\n", cp->value); |
484 |
|
|
break; |
485 |
|
|
|
486 |
|
|
case CONFSTR: |
487 |
✗✓ |
2 |
if (pledge("stdio wpath cpath rpath", NULL) == -1) |
488 |
|
|
err(1, "pledge"); |
489 |
|
2 |
errno = 0; |
490 |
✗✓ |
2 |
if ((slen = confstr(cp->value, NULL, 0)) == 0) { |
491 |
|
|
if (errno != 0) |
492 |
|
|
err(1, NULL); |
493 |
|
|
|
494 |
|
|
printf("undefined\n"); |
495 |
|
|
} else { |
496 |
✗✓ |
2 |
if ((sval = malloc(slen)) == NULL) |
497 |
|
|
err(1, NULL); |
498 |
|
|
|
499 |
|
2 |
confstr(cp->value, sval, slen); |
500 |
|
2 |
printf("%s\n", sval); |
501 |
|
|
} |
502 |
|
|
break; |
503 |
|
|
|
504 |
|
|
case SYSCONF: |
505 |
|
|
if (pledge("stdio inet ps vminfo wpath cpath rpath", NULL) == -1) |
506 |
|
|
err(1, "pledge"); |
507 |
|
|
errno = 0; |
508 |
|
|
if ((val = sysconf(cp->value)) == -1) { |
509 |
|
|
if (errno != 0) |
510 |
|
|
err(1, NULL); |
511 |
|
|
|
512 |
|
|
printf("undefined\n"); |
513 |
|
|
} else { |
514 |
|
|
printf("%ld\n", val); |
515 |
|
|
} |
516 |
|
|
break; |
517 |
|
|
|
518 |
|
|
case PATHCONF: |
519 |
|
|
if (pledge("stdio rpath wpath cpath", NULL) == -1) |
520 |
|
|
err(1, "pledge"); |
521 |
|
|
errno = 0; |
522 |
|
|
if ((val = pathconf(argv[1], cp->value)) == -1) { |
523 |
|
|
if (errno != 0) |
524 |
|
|
err(1, "%s", argv[1]); |
525 |
|
|
|
526 |
|
|
printf("undefined\n"); |
527 |
|
|
} else { |
528 |
|
|
printf("%ld\n", val); |
529 |
|
|
} |
530 |
|
|
break; |
531 |
|
|
} |
532 |
|
|
|
533 |
✓✗ |
2 |
exit(ferror(stdout)); |
534 |
|
|
} |
535 |
|
|
|
536 |
|
|
|
537 |
|
|
static void |
538 |
|
|
usage(void) |
539 |
|
|
{ |
540 |
|
|
extern char *__progname; |
541 |
|
|
|
542 |
|
|
(void)fprintf(stderr, |
543 |
|
|
"usage: %s [-Ll] [-v specification] name [pathname]\n", |
544 |
|
|
__progname); |
545 |
|
|
exit(1); |
546 |
|
|
} |
547 |
|
|
|
548 |
|
|
static void |
549 |
|
|
list_var(int do_pathconf) |
550 |
|
|
{ |
551 |
|
|
const struct conf_variable *cp; |
552 |
|
|
|
553 |
|
|
for (cp = uposix_conf_table; cp->name != NULL; cp++) |
554 |
|
|
if ((cp->type == PATHCONF) == do_pathconf) |
555 |
|
|
printf("%s%s\n", uposix_prefix, cp->name); |
556 |
|
|
for (cp = posix_conf_table; cp->name != NULL; cp++) |
557 |
|
|
if ((cp->type == PATHCONF) == do_pathconf) |
558 |
|
|
printf("%s%s\n", posix_prefix, cp->name); |
559 |
|
|
for (cp = conf_table; cp->name != NULL; cp++) |
560 |
|
|
if ((cp->type == PATHCONF) == do_pathconf) |
561 |
|
|
printf("%s\n", cp->name); |
562 |
|
|
for (cp = compat_posix2_conf_table; cp->name != NULL; cp++) |
563 |
|
|
if ((cp->type == PATHCONF) == do_pathconf) |
564 |
|
|
printf("_%s%s\n", compat_posix2_prefix, cp->name); |
565 |
|
|
} |
566 |
|
|
|
567 |
|
|
static int |
568 |
|
|
compilation_spec_valid(const char *spec) |
569 |
|
|
{ |
570 |
|
|
const char **sp; |
571 |
|
|
const struct conf_variable *cp; |
572 |
|
|
|
573 |
|
|
if (strncmp(spec, posix_prefix, sizeof(posix_prefix) - 1) != 0) |
574 |
|
|
return (0); |
575 |
|
|
|
576 |
|
|
spec += sizeof(posix_prefix) - 1; |
577 |
|
|
for (sp = compilation_specs; *sp != NULL; sp++) |
578 |
|
|
if (strcmp(spec, *sp) == 0) |
579 |
|
|
break; |
580 |
|
|
if (*sp == NULL) |
581 |
|
|
return (0); |
582 |
|
|
|
583 |
|
|
for (cp = uposix_conf_table; cp->name != NULL; cp++) |
584 |
|
|
if (strcmp(spec, cp->name) == 0 && cp->type == SYSCONF) |
585 |
|
|
return (sysconf(cp->value) != -1); |
586 |
|
|
|
587 |
|
|
return (0); |
588 |
|
|
} |