GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usr.bin/getconf/getconf.c Lines: 23 93 24.7 %
Date: 2017-11-07 Branches: 16 93 17.2 %

Line Branch Exec Source
1
/*	$OpenBSD: getconf.c,v 1.19 2016/10/28 07:22:59 schwarze 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 <err.h>
44
#include <errno.h>
45
#include <limits.h>
46
#include <stdio.h>
47
#include <stdlib.h>
48
#include <string.h>
49
#include <unistd.h>
50
51
static void __dead usage(void);
52
static void list_var(int);
53
static int compilation_spec_valid(const char *);
54
55
struct conf_variable
56
{
57
  const char *name;
58
  enum { SYSCONF, CONFSTR, PATHCONF, CONSTANT } type;
59
  long value;
60
};
61
62
63
#define constant_row(name)		 { #name, CONSTANT, name },
64
#define sysconf_row(name)		 { #name, SYSCONF,  _SC_##name },
65
#define pathconf_row(name)		 { #name, PATHCONF, _PC_##name },
66
#define confstr_row(name)		 { #name, CONFSTR,  _CS_##name },
67
#define posix_constant_row(name)	 { #name, CONSTANT, _POSIX_##name },
68
#define posix_confstr_row(name)		 { #name, CONFSTR,  _CS_POSIX_##name },
69
#define compat_posix2_sysconf_row(name)	 { #name, SYSCONF,  _SC_2_##name },
70
#define compat_posix2_constant_row(name) { #name, CONSTANT, _POSIX2_##name },
71
72
/* Some sysconf variables don't follow the pattern of the others */
73
#define posix2_sysconf_row(name) \
74
			{ "_POSIX2_" #name, SYSCONF,  _SC_2_##name },
75
#define posix2_pathconf_row(name) \
76
			{ "_POSIX2_" #name, PATHCONF,  _PC_2_##name },
77
#define pthread_sysconf_row(name) \
78
			{ "_PTHREAD_" #name, SYSCONF,  _SC_THREAD_##name },
79
#define xopen_sysconf_row(name) \
80
			{ "_XOPEN_" #name, SYSCONF,  _SC_XOPEN_##name },
81
82
const struct conf_variable conf_table[] =
83
{
84
  /* Configuration strings */
85
  confstr_row(PATH)
86
  confstr_row(V7_ENV)
87
  confstr_row(V6_ENV)
88
89
  /* Symbolic Utility Limits */
90
  sysconf_row(BC_BASE_MAX)
91
  sysconf_row(BC_DIM_MAX)
92
  sysconf_row(BC_SCALE_MAX)
93
  sysconf_row(BC_STRING_MAX)
94
  sysconf_row(COLL_WEIGHTS_MAX)
95
  sysconf_row(EXPR_NEST_MAX)
96
  sysconf_row(LINE_MAX)
97
  sysconf_row(RE_DUP_MAX)
98
99
  /* POSIX.1 Configurable System Variables */
100
  sysconf_row(AIO_LISTIO_MAX)
101
  sysconf_row(AIO_MAX)
102
  sysconf_row(AIO_PRIO_DELTA_MAX)
103
  sysconf_row(ARG_MAX)
104
  sysconf_row(CHILD_MAX)
105
  sysconf_row(CLK_TCK)
106
  sysconf_row(NGROUPS_MAX)
107
  sysconf_row(OPEN_MAX)
108
  sysconf_row(STREAM_MAX)
109
  sysconf_row(TZNAME_MAX)
110
  sysconf_row(PAGE_SIZE)
111
  sysconf_row(PAGESIZE)
112
113
  sysconf_row(SEM_NSEMS_MAX)
114
  sysconf_row(SEM_VALUE_MAX)
115
  sysconf_row(HOST_NAME_MAX)
116
  sysconf_row(LOGIN_NAME_MAX)
117
118
  sysconf_row(ATEXIT_MAX)
119
  sysconf_row(DELAYTIMER_MAX)
120
  sysconf_row(IOV_MAX)
121
  sysconf_row(MQ_OPEN_MAX)
122
  sysconf_row(MQ_PRIO_MAX)
123
  sysconf_row(RTSIG_MAX)
124
  sysconf_row(SIGQUEUE_MAX)
125
  sysconf_row(SYMLOOP_MAX)
126
  sysconf_row(TIMER_MAX)
127
  sysconf_row(TTY_NAME_MAX)
128
129
  posix2_sysconf_row(PBS)
130
  posix2_sysconf_row(PBS_ACCOUNTING)
131
  posix2_sysconf_row(PBS_CHECKPOINT)
132
  posix2_sysconf_row(PBS_LOCATE)
133
  posix2_sysconf_row(PBS_MESSAGE)
134
  posix2_sysconf_row(PBS_TRACK)
135
136
  pthread_sysconf_row(DESTRUCTOR_ITERATIONS)
137
  pthread_sysconf_row(KEYS_MAX)
138
  pthread_sysconf_row(STACK_MIN)
139
  pthread_sysconf_row(THREADS_MAX)
140
141
  xopen_sysconf_row(SHM)
142
  xopen_sysconf_row(CRYPT)
143
  xopen_sysconf_row(ENH_I18N)
144
  xopen_sysconf_row(REALTIME)
145
  xopen_sysconf_row(REALTIME_THREADS)
146
  xopen_sysconf_row(STREAMS)
147
  xopen_sysconf_row(UNIX)
148
  xopen_sysconf_row(UUCP)
149
  xopen_sysconf_row(VERSION)
150
151
  pathconf_row(FILESIZEBITS)
152
  pathconf_row(LINK_MAX)
153
  pathconf_row(MAX_CANON)
154
  pathconf_row(MAX_INPUT)
155
  pathconf_row(NAME_MAX)
156
  pathconf_row(PATH_MAX)
157
  pathconf_row(PIPE_BUF)
158
  pathconf_row(SYMLINK_MAX)
159
160
  posix2_pathconf_row(SYMLINKS)
161
162
  constant_row(_POSIX2_CHARCLASS_NAME_MAX)
163
  constant_row(_XOPEN_IOV_MAX)
164
  constant_row(_XOPEN_NAME_MAX)
165
  constant_row(_XOPEN_PATH_MAX)
166
167
  /* Extensions */
168
  sysconf_row(PHYS_PAGES)
169
  sysconf_row(AVPHYS_PAGES)
170
  sysconf_row(NPROCESSORS_CONF)
171
  sysconf_row(NPROCESSORS_ONLN)
172
173
  { NULL }
174
};
175
176
/*
177
 * Lots of names have a leading "_POSIX_", so put them in a table with
178
 * that prefix trimmed
179
 */
180
const char uposix_prefix[] = "_POSIX_";
181
const struct conf_variable uposix_conf_table[] =
182
{
183
  /* POSIX.1 Maximum Values */
184
  posix_constant_row(CLOCKRES_MIN)
185
186
  /* POSIX.1 Minimum Values */
187
  /*posix_constant_row(AIO_LISTIO_MAX)*/
188
  /*posix_constant_row(AIO_MAX)*/
189
  posix_constant_row(ARG_MAX)
190
  posix_constant_row(CHILD_MAX)
191
  /*posix_constant_row(DELAYTIMER_MAX)*/
192
  posix_constant_row(HOST_NAME_MAX)
193
  posix_constant_row(LINK_MAX)
194
  posix_constant_row(LOGIN_NAME_MAX)
195
  posix_constant_row(MAX_CANON)
196
  posix_constant_row(MAX_INPUT)
197
  /*posix_constant_row(MQ_OPEN_MAX)*/
198
  /*posix_constant_row(MQ_PRIO_MAX)*/
199
  posix_constant_row(NAME_MAX)
200
  posix_constant_row(NGROUPS_MAX)
201
  posix_constant_row(OPEN_MAX)
202
  posix_constant_row(PATH_MAX)
203
  posix_constant_row(PIPE_BUF)
204
  posix_constant_row(RE_DUP_MAX)
205
  /*posix_constant_row(RTSIG_MAX)*/
206
  posix_constant_row(SEM_NSEMS_MAX)
207
  posix_constant_row(SEM_VALUE_MAX)
208
  /*posix_constant_row(SIGQUEUE_MAX)*/
209
  posix_constant_row(SSIZE_MAX)
210
  /*posix_constant_row(SS_REPL_MAX)*/
211
  posix_constant_row(STREAM_MAX)
212
  posix_constant_row(SYMLINK_MAX)
213
  posix_constant_row(SYMLOOP_MAX)
214
  posix_constant_row(THREAD_DESTRUCTOR_ITERATIONS)
215
  posix_constant_row(THREAD_KEYS_MAX)
216
  posix_constant_row(THREAD_THREADS_MAX)
217
  /*posix_constant_row(TIMER_MAX)*/
218
  posix_constant_row(TTY_NAME_MAX)
219
  posix_constant_row(TZNAME_MAX)
220
221
  /* POSIX.1 Configurable System Variables */
222
  sysconf_row(JOB_CONTROL)
223
  sysconf_row(SAVED_IDS)
224
  sysconf_row(VERSION)
225
  sysconf_row(FSYNC)
226
  sysconf_row(MONOTONIC_CLOCK)
227
  sysconf_row(THREAD_SAFE_FUNCTIONS)
228
  sysconf_row(ADVISORY_INFO)
229
  sysconf_row(BARRIERS)
230
  sysconf_row(ASYNCHRONOUS_IO)
231
  sysconf_row(CLOCK_SELECTION)
232
  sysconf_row(CPUTIME)
233
  sysconf_row(IPV6)
234
  sysconf_row(MAPPED_FILES)
235
  sysconf_row(MEMLOCK)
236
  sysconf_row(MEMLOCK_RANGE)
237
  sysconf_row(MEMORY_PROTECTION)
238
  sysconf_row(MESSAGE_PASSING)
239
  sysconf_row(PRIORITIZED_IO)
240
  sysconf_row(PRIORITY_SCHEDULING)
241
  sysconf_row(RAW_SOCKETS)
242
  sysconf_row(READER_WRITER_LOCKS)
243
  sysconf_row(REALTIME_SIGNALS)
244
  sysconf_row(REGEXP)
245
  sysconf_row(SEMAPHORES)
246
  sysconf_row(SHARED_MEMORY_OBJECTS)
247
  sysconf_row(SHELL)
248
  sysconf_row(SPAWN)
249
  sysconf_row(SPIN_LOCKS)
250
  sysconf_row(SPORADIC_SERVER)
251
  sysconf_row(SS_REPL_MAX)
252
  sysconf_row(SYNCHRONIZED_IO)
253
  sysconf_row(THREAD_ATTR_STACKADDR)
254
  sysconf_row(THREAD_ATTR_STACKSIZE)
255
  sysconf_row(THREAD_CPUTIME)
256
  sysconf_row(THREAD_PRIO_INHERIT)
257
  sysconf_row(THREAD_PRIO_PROTECT)
258
  sysconf_row(THREAD_PRIORITY_SCHEDULING)
259
  sysconf_row(THREAD_PROCESS_SHARED)
260
  sysconf_row(THREAD_ROBUST_PRIO_INHERIT)
261
  sysconf_row(THREAD_SPORADIC_SERVER)
262
  sysconf_row(THREADS)
263
  sysconf_row(TIMEOUTS)
264
  sysconf_row(TIMERS)
265
  sysconf_row(TRACE)
266
  sysconf_row(TRACE_EVENT_FILTER)
267
  sysconf_row(TRACE_EVENT_NAME_MAX)
268
  sysconf_row(TRACE_INHERIT)
269
  sysconf_row(TRACE_LOG)
270
  sysconf_row(TRACE_NAME_MAX)
271
  sysconf_row(TRACE_SYS_MAX)
272
  sysconf_row(TRACE_USER_EVENT_MAX)
273
  sysconf_row(TYPED_MEMORY_OBJECTS)
274
275
  /*
276
   * If new compilation specification are added (V8_*?) then add them
277
   * to the compilation_specs array below too
278
   */
279
  sysconf_row(V7_ILP32_OFF32)
280
  sysconf_row(V7_ILP32_OFFBIG)
281
  sysconf_row(V7_LP64_OFF64)
282
  sysconf_row(V7_LPBIG_OFFBIG)
283
  sysconf_row(V6_ILP32_OFF32)
284
  sysconf_row(V6_ILP32_OFFBIG)
285
  sysconf_row(V6_LP64_OFF64)
286
  sysconf_row(V6_LPBIG_OFFBIG)
287
288
  /* POSIX.1 Configurable Path Variables */
289
  pathconf_row(CHOWN_RESTRICTED)
290
  pathconf_row(NO_TRUNC)
291
  pathconf_row(VDISABLE)
292
  pathconf_row(ASYNC_IO)
293
  pathconf_row(PRIO_IO)
294
  pathconf_row(SYNC_IO)
295
  pathconf_row(TIMESTAMP_RESOLUTION)
296
297
  { NULL }
298
};
299
300
/*
301
 * Then there are the "POSIX_*" values
302
 */
303
const char posix_prefix[] = "POSIX_";
304
const struct conf_variable posix_conf_table[] =
305
{
306
  pathconf_row(ALLOC_SIZE_MIN)
307
  pathconf_row(REC_INCR_XFER_SIZE)
308
  pathconf_row(REC_MAX_XFER_SIZE)
309
  pathconf_row(REC_MIN_XFER_SIZE)
310
  pathconf_row(REC_XFER_ALIGN)
311
312
  posix_confstr_row(V7_ILP32_OFF32_CFLAGS)
313
  posix_confstr_row(V7_ILP32_OFF32_LDFLAGS)
314
  posix_confstr_row(V7_ILP32_OFF32_LIBS)
315
  posix_confstr_row(V7_ILP32_OFFBIG_CFLAGS)
316
  posix_confstr_row(V7_ILP32_OFFBIG_LDFLAGS)
317
  posix_confstr_row(V7_ILP32_OFFBIG_LIBS)
318
  posix_confstr_row(V7_LP64_OFF64_CFLAGS)
319
  posix_confstr_row(V7_LP64_OFF64_LDFLAGS)
320
  posix_confstr_row(V7_LP64_OFF64_LIBS)
321
  posix_confstr_row(V7_LPBIG_OFFBIG_CFLAGS)
322
  posix_confstr_row(V7_LPBIG_OFFBIG_LDFLAGS)
323
  posix_confstr_row(V7_LPBIG_OFFBIG_LIBS)
324
  posix_confstr_row(V7_THREADS_CFLAGS)
325
  posix_confstr_row(V7_THREADS_LDFLAGS)
326
  posix_confstr_row(V7_WIDTH_RESTRICTED_ENVS)
327
  posix_confstr_row(V6_ILP32_OFF32_CFLAGS)
328
  posix_confstr_row(V6_ILP32_OFF32_LDFLAGS)
329
  posix_confstr_row(V6_ILP32_OFF32_LIBS)
330
  posix_confstr_row(V6_ILP32_OFFBIG_CFLAGS)
331
  posix_confstr_row(V6_ILP32_OFFBIG_LDFLAGS)
332
  posix_confstr_row(V6_ILP32_OFFBIG_LIBS)
333
  posix_confstr_row(V6_LP64_OFF64_CFLAGS)
334
  posix_confstr_row(V6_LP64_OFF64_LDFLAGS)
335
  posix_confstr_row(V6_LP64_OFF64_LIBS)
336
  posix_confstr_row(V6_LPBIG_OFFBIG_CFLAGS)
337
  posix_confstr_row(V6_LPBIG_OFFBIG_LDFLAGS)
338
  posix_confstr_row(V6_LPBIG_OFFBIG_LIBS)
339
  posix_confstr_row(V6_WIDTH_RESTRICTED_ENVS)
340
341
  { NULL }
342
};
343
344
/*
345
 * Finally, there are variables that are accepted with a prefix
346
 * of either "_POSIX2_" or "POSIX2_"
347
 */
348
const char compat_posix2_prefix[] = "POSIX2_";
349
const struct conf_variable compat_posix2_conf_table[] =
350
{
351
  /* Optional Facility Configuration Values */
352
  compat_posix2_sysconf_row(VERSION)
353
  compat_posix2_sysconf_row(C_BIND)
354
  compat_posix2_sysconf_row(C_DEV)
355
  compat_posix2_sysconf_row(CHAR_TERM)
356
  compat_posix2_sysconf_row(FORT_DEV)
357
  compat_posix2_sysconf_row(FORT_RUN)
358
  compat_posix2_sysconf_row(LOCALEDEF)
359
  compat_posix2_sysconf_row(SW_DEV)
360
  compat_posix2_sysconf_row(UPE)
361
362
  /* Utility Limit Minimum Values */
363
  compat_posix2_constant_row(BC_BASE_MAX)
364
  compat_posix2_constant_row(BC_DIM_MAX)
365
  compat_posix2_constant_row(BC_SCALE_MAX)
366
  compat_posix2_constant_row(BC_STRING_MAX)
367
  compat_posix2_constant_row(COLL_WEIGHTS_MAX)
368
  compat_posix2_constant_row(EXPR_NEST_MAX)
369
  compat_posix2_constant_row(LINE_MAX)
370
  compat_posix2_constant_row(RE_DUP_MAX)
371
372
  { NULL }
373
};
374
375
#undef constant_row
376
#undef sysconf_row
377
#undef pathconf_row
378
#undef confstr_row
379
#undef posix_constant_row
380
#undef posix_confstr_row
381
#undef compat_posix2_sysconf_row
382
#undef compat_posix2_constant_row
383
384
385
/*
386
 * What values are possibly accepted by the -v option?
387
 * These are implied to have a prefix of posix_prefix
388
 */
389
const char *compilation_specs[] = {
390
  "V7_ILP32_OFF32",
391
  "V7_ILP32_OFFBIG",
392
  "V7_LP64_OFF64",
393
  "V7_LPBIG_OFFBIG",
394
  "V6_ILP32_OFF32",
395
  "V6_ILP32_OFFBIG",
396
  "V6_LP64_OFF64",
397
  "V6_LPBIG_OFFBIG",
398
  NULL
399
};
400
401
int
402
main(int argc, char *argv[])
403
{
404
	int ch;
405
	const struct conf_variable *cp;
406
407
	long val;
408
	size_t slen;
409
	char * sval;
410
411
150
	while ((ch = getopt(argc, argv, "lLv:")) != -1) {
412
		switch (ch) {
413
		case 'l':	/* nonstandard: list system variables */
414
			list_var(0);
415
			return (0);
416
		case 'L':	/* nonstandard: list path variables */
417
			list_var(1);
418
			return (0);
419
		case 'v':
420
			if (! compilation_spec_valid(optarg))
421
				errx(1, "%s: unknown specification", optarg);
422
			break;
423
		case '?':
424
		default:
425
			usage();
426
		}
427
	}
428
50
	argc -= optind;
429
50
	argv += optind;
430
431
50
	if (argc < 1 || argc > 2)
432
		usage();
433
434
	/* pick a table based on a possible prefix */
435
50
	if (strncmp(*argv, uposix_prefix, sizeof(uposix_prefix) - 1) == 0) {
436
		cp = uposix_conf_table;
437
		slen = sizeof(uposix_prefix) - 1;
438
100
	} else if (strncmp(*argv, posix_prefix,
439
50
	    sizeof(posix_prefix) - 1) == 0) {
440
		cp = posix_conf_table;
441
		slen = sizeof(posix_prefix) - 1;
442
	} else {
443
		cp = conf_table;
444
		slen = 0;
445
	}
446
447
	/* scan the table */
448
50
	for (; cp->name != NULL; cp++)
449
50
		if (strcmp(*argv + slen, cp->name) == 0)
450
			break;
451
452
	/*
453
	 * If no match, then make a final check against
454
	 * compat_posix2_conf_table, with special magic to accept/skip
455
	 * a leading underbar
456
	 */
457
50
	slen = argv[0][0] == '_';
458

50
	if (cp->name == NULL && strncmp(*argv + slen, compat_posix2_prefix,
459
	    sizeof(compat_posix2_prefix) - 1) == 0) {
460
		slen += sizeof(compat_posix2_prefix) - 1;
461
		for (cp = compat_posix2_conf_table; cp->name != NULL; cp++) {
462
			if (strcmp(*argv + slen, cp->name) == 0)
463
				break;
464
		}
465
	}
466
467
50
	if (cp->name == NULL)
468
		errx(1, "%s: unknown variable", *argv);
469
470
50
	if (cp->type == PATHCONF) {
471
		if (argc != 2) usage();
472
	} else {
473
50
		if (argc != 1) usage();
474
	}
475
476

100
	switch (cp->type) {
477
	case CONSTANT:
478
		if (pledge("stdio flock rpath cpath wpath", NULL) == -1)
479
			err(1, "pledge");
480
		printf("%ld\n", cp->value);
481
		break;
482
483
	case CONFSTR:
484
50
		if (pledge("stdio flock rpath cpath wpath", NULL) == -1)
485
			err(1, "pledge");
486
50
		errno = 0;
487
50
		if ((slen = confstr(cp->value, NULL, 0)) == 0) {
488
			if (errno != 0)
489
				err(1, NULL);
490
491
			printf("undefined\n");
492
		} else {
493
50
			if ((sval = malloc(slen)) == NULL)
494
				err(1, NULL);
495
496
50
			confstr(cp->value, sval, slen);
497
50
			printf("%s\n", sval);
498
		}
499
		break;
500
501
	case SYSCONF:
502
		if (pledge("stdio inet ps vminfo flock rpath cpath wpath", NULL) == -1)
503
			err(1, "pledge");
504
		errno = 0;
505
		if ((val = sysconf(cp->value)) == -1) {
506
			if (errno != 0)
507
				err(1, NULL);
508
509
			printf("undefined\n");
510
		} else {
511
			printf("%ld\n", val);
512
		}
513
		break;
514
515
	case PATHCONF:
516
		if (pledge("stdio rpath flock cpath wpath", NULL) == -1)
517
			err(1, "pledge");
518
		errno = 0;
519
		if ((val = pathconf(argv[1], cp->value)) == -1) {
520
			if (errno != 0)
521
				err(1, "%s", argv[1]);
522
523
			printf("undefined\n");
524
		} else {
525
			printf("%ld\n", val);
526
		}
527
		break;
528
	}
529
530
150
	return ferror(stdout);
531
50
}
532
533
534
static void __dead
535
usage(void)
536
{
537
	extern char *__progname;
538
539
	(void)fprintf(stderr,
540
	    "usage: %s [-Ll] [-v specification] name [pathname]\n",
541
	    __progname);
542
	exit(1);
543
}
544
545
static void
546
list_var(int do_pathconf)
547
{
548
	const struct conf_variable *cp;
549
550
	for (cp = uposix_conf_table; cp->name != NULL; cp++)
551
		if ((cp->type == PATHCONF) == do_pathconf)
552
			printf("%s%s\n", uposix_prefix, cp->name);
553
	for (cp = posix_conf_table; cp->name != NULL; cp++)
554
		if ((cp->type == PATHCONF) == do_pathconf)
555
			printf("%s%s\n", posix_prefix, cp->name);
556
	for (cp = conf_table; cp->name != NULL; cp++)
557
		if ((cp->type == PATHCONF) == do_pathconf)
558
			printf("%s\n", cp->name);
559
	for (cp = compat_posix2_conf_table; cp->name != NULL; cp++)
560
		if ((cp->type == PATHCONF) == do_pathconf)
561
			printf("_%s%s\n", compat_posix2_prefix, cp->name);
562
}
563
564
static int
565
compilation_spec_valid(const char *spec)
566
{
567
	const char **sp;
568
	const struct conf_variable *cp;
569
570
	if (strncmp(spec, posix_prefix, sizeof(posix_prefix) - 1) != 0)
571
		return (0);
572
573
	spec += sizeof(posix_prefix) - 1;
574
	for (sp = compilation_specs; *sp != NULL; sp++)
575
		if (strcmp(spec, *sp) == 0)
576
			break;
577
	if (*sp == NULL)
578
		return (0);
579
580
	for (cp = uposix_conf_table; cp->name != NULL; cp++)
581
		if (strcmp(spec, cp->name) == 0 && cp->type == SYSCONF)
582
			return (sysconf(cp->value) != -1);
583
584
	return (0);
585
}