xref: /titanic_41/usr/src/cmd/getconf/getconf.c (revision d5ace9454616652a717c9831d949dffa319381f9)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * Copyright 1985, 1993 by Mortice Kern Systems Inc.  All rights reserved.
29  *
30  */
31 
32 #pragma ident	"%Z%%M%	%I%	%E% SMI"
33 
34 /*
35  * getconf -- POSIX.2 compatible utility to query configuration specific
36  *	      parameters.
37  *         -- XPG4 support added June/93
38  *
39  *         -- XPG5 support added Dec/97
40  *
41  *         -- XPG6 support added May/2003
42  */
43 
44 #include <stdio.h>
45 #include <stdlib.h>
46 #include <string.h>
47 #include <errno.h>
48 #include <unistd.h>
49 #include <limits.h>
50 #include <locale.h>
51 #include <libintl.h>
52 #include <assert.h>
53 
54 extern size_t confstr(int, char *, size_t);
55 
56 static int aflag = 0;
57 
58 #define	INVAL_ARG	"getconf: Invalid argument (%s)\n"
59 #define	INVAL_PATHARG	"getconf: Invalid argument (%s or %s)\n"
60 
61 /*
62  *  Notes:
63  *  The sctab.value field is defined to be a long.
64  *  There are some values that are "unsigned long"; these values
65  *  can be stored in a "long" field but when output, must be printed
66  *  as an unsigned value. Thus, these values must have UNSIGNED_VALUE bit
67  *  set in sctab.flag field.
68  *
69  *  There are 2 different ways to indicate a symbol is undefined:
70  *     1) sctab.flag = UNDEFINED
71  *     2) or sctab.value = -1 (and if !UNDEFINED and !UNSIGNED_VALUE)
72  *
73  *  There are a group of symbols (e.g CHAR_MIN, INT_MAX, INT_MIN, LONG_BIT ...)
74  *  which we may set to -1 if they are not pre-defined in a system header file.
75  *  This is used to indicate that these symbols are "undefined".
76  *  We are assuming that these symbols cannot reasonably have a value of -1
77  *  if they were defined in a system header file.
78  *  (Unless of course -1 can be used to indicate "undefined" for that symbol)
79  */
80 
81 static struct sctab {
82 	long value;
83 	char *name;
84 	enum { SELFCONF, SYSCONF, PATHCONF, CONFSTR } type;
85 	int flag;
86 /* bit fields for sctab.flag member */
87 #define	NOFLAGS		0	/* no special indicators */
88 #define	UNDEFINED	1	/* value is known undefined at compile time */
89 #define	UNSIGNED_VALUE	2	/* value is an unsigned */
90 } sctab[] = {
91 /*
92  * Some entries in this structure have both leading _ and non leading _
93  * versions for compatibility with various versions of the specifications.
94  * It is not expected that both forms will be required for new entries.
95  */
96 
97 	/* POSIX.2-1992 table 2-17 */
98 	_POSIX2_BC_BASE_MAX,	"POSIX2_BC_BASE_MAX",	SELFCONF,   NOFLAGS,
99 	_POSIX2_BC_BASE_MAX,	"_POSIX2_BC_BASE_MAX",	SELFCONF,  NOFLAGS,
100 	_POSIX2_BC_DIM_MAX,	"POSIX2_BC_DIM_MAX",	SELFCONF,   NOFLAGS,
101 	_POSIX2_BC_DIM_MAX,	"_POSIX2_BC_DIM_MAX",	SELFCONF,  NOFLAGS,
102 	_POSIX2_BC_SCALE_MAX,	"POSIX2_BC_SCALE_MAX",	SELFCONF,   NOFLAGS,
103 	_POSIX2_BC_SCALE_MAX,	"_POSIX2_BC_SCALE_MAX",	SELFCONF,  NOFLAGS,
104 	_POSIX2_BC_STRING_MAX,	"POSIX2_BC_STRING_MAX",	SELFCONF,   NOFLAGS,
105 	_POSIX2_BC_STRING_MAX,	"_POSIX2_BC_STRING_MAX", SELFCONF, NOFLAGS,
106 	_POSIX2_COLL_WEIGHTS_MAX, "POSIX2_COLL_WEIGHTS_MAX", SELFCONF,  NOFLAGS,
107 	_POSIX2_COLL_WEIGHTS_MAX, "_POSIX2_COLL_WEIGHTS_MAX", SELFCONF, NOFLAGS,
108 	_POSIX2_EXPR_NEST_MAX,	"POSIX2_EXPR_NEST_MAX",	SELFCONF,   NOFLAGS,
109 	_POSIX2_EXPR_NEST_MAX,	"_POSIX2_EXPR_NEST_MAX", SELFCONF,   NOFLAGS,
110 	_POSIX2_LINE_MAX,	"POSIX2_LINE_MAX",	SELFCONF,   NOFLAGS,
111 	_POSIX2_LINE_MAX,	"_POSIX2_LINE_MAX",	SELFCONF,  NOFLAGS,
112 	_POSIX2_RE_DUP_MAX,	"POSIX2_RE_DUP_MAX",	SELFCONF,   NOFLAGS,
113 	_POSIX2_RE_DUP_MAX,	"_POSIX2_RE_DUP_MAX",	SELFCONF,   NOFLAGS,
114 	/* See limits.h section below for _POSIX_RE_DUP_MAX */
115 
116 	/* UNIX 98 */
117 	_POSIX_AIO_LISTIO_MAX,	"_POSIX_AIO_LISTIO_MAX", SELFCONF, 	NOFLAGS,
118 	_POSIX_AIO_MAX,		"_POSIX_AIO_MAX",	 SELFCONF, 	NOFLAGS,
119 	_POSIX_DELAYTIMER_MAX,	"_POSIX_DELAYTIMER_MAX", SELFCONF, 	NOFLAGS,
120 	_POSIX_LOGIN_NAME_MAX,	"_POSIX_LOGIN_NAME_MAX", SELFCONF, 	NOFLAGS,
121 	_POSIX_MQ_OPEN_MAX,	"_POSIX_MQ_OPEN_MAX",	 SELFCONF, 	NOFLAGS,
122 	_POSIX_MQ_PRIO_MAX,	"_POSIX_MQ_PRIO_MAX",	 SELFCONF, 	NOFLAGS,
123 	_POSIX_RTSIG_MAX,	"_POSIX_RTSIG_MAX",	 SELFCONF,	NOFLAGS,
124 	_POSIX_SEM_NSEMS_MAX,	"_POSIX_SEM_NSEMS_MAX",	 SELFCONF,	NOFLAGS,
125 	_POSIX_SEM_VALUE_MAX,	"_POSIX_SEM_VALUE_MAX",	 SELFCONF,	NOFLAGS,
126 	_POSIX_SIGQUEUE_MAX,	"_POSIX_SIGQUEUE_MAX",	 SELFCONF,	NOFLAGS,
127 	_POSIX_TTY_NAME_MAX,	"_POSIX_TTY_NAME_MAX",	 SELFCONF,	NOFLAGS,
128 
129 	/* UNIX 03 */
130 	_POSIX_HOST_NAME_MAX,	"_POSIX_HOST_NAME_MAX",	  SELFCONF,   NOFLAGS,
131 	_POSIX_RE_DUP_MAX,	"_POSIX_RE_DUP_MAX",	  SELFCONF,   NOFLAGS,
132 	_POSIX_CLOCKRES_MIN,	"_POSIX_CLOCKRES_MIN",	  SELFCONF,   NOFLAGS,
133 	_POSIX_SYMLINK_MAX,	"_POSIX_SYMLINK_MAX",	  SELFCONF,   NOFLAGS,
134 	_POSIX_SYMLOOP_MAX,	"_POSIX_SYMLOOP_MAX",	  SELFCONF,   NOFLAGS,
135 	CHARCLASS_NAME_MAX, "_POSIX2_CHARCLASS_NAME_MAX", SELFCONF,   NOFLAGS,
136 
137 	/* POSIX.2-1992 table 2-17 */
138 	_SC_2_VERSION,		"POSIX2_VERSION",	SYSCONF,   NOFLAGS,
139 	_SC_2_VERSION,		"_POSIX2_VERSION",	SYSCONF,   NOFLAGS,
140 
141 	/* POSIX.2-1992 table 2-18 */
142 	_SC_BC_BASE_MAX,	"BC_BASE_MAX",		SYSCONF,   NOFLAGS,
143 	_SC_BC_DIM_MAX,		"BC_DIM_MAX",		SYSCONF,   NOFLAGS,
144 	_SC_BC_SCALE_MAX,	"BC_SCALE_MAX",		SYSCONF,   NOFLAGS,
145 	_SC_BC_STRING_MAX,	"BC_STRING_MAX",	SYSCONF,   NOFLAGS,
146 	_SC_COLL_WEIGHTS_MAX,	"COLL_WEIGHTS_MAX",	SYSCONF,   NOFLAGS,
147 	_SC_EXPR_NEST_MAX,	"EXPR_NEST_MAX",	SYSCONF,   NOFLAGS,
148 	_SC_LINE_MAX,		"LINE_MAX",		SYSCONF,   NOFLAGS,
149 	_SC_RE_DUP_MAX,		"RE_DUP_MAX",		SYSCONF,   NOFLAGS,
150 
151 	/* POSIX.2-1992 table 2-19 */
152 	_SC_2_C_BIND,		"POSIX2_C_BIND",	SYSCONF,   NOFLAGS,
153 	_SC_2_C_BIND,		"_POSIX2_C_BIND",	SYSCONF,   NOFLAGS,
154 	_SC_2_C_DEV,		"POSIX2_C_DEV",		SYSCONF,   NOFLAGS,
155 	_SC_2_C_DEV,		"_POSIX2_C_DEV",	SYSCONF,   NOFLAGS,
156 	_SC_2_CHAR_TERM,	"POSIX2_CHAR_TERM",	SYSCONF,   NOFLAGS,
157 	_SC_2_CHAR_TERM,	"_POSIX2_CHAR_TERM",	SYSCONF,   NOFLAGS,
158 	_SC_2_FORT_DEV,		"POSIX2_FORT_DEV",	SYSCONF,   NOFLAGS,
159 	_SC_2_FORT_DEV,		"_POSIX2_FORT_DEV",	SYSCONF,   NOFLAGS,
160 	_SC_2_FORT_RUN,		"POSIX2_FORT_RUN",	SYSCONF,   NOFLAGS,
161 	_SC_2_FORT_RUN,		"_POSIX2_FORT_RUN",	SYSCONF,   NOFLAGS,
162 	_SC_2_LOCALEDEF,	"POSIX2_LOCALEDEF",	SYSCONF,   NOFLAGS,
163 	_SC_2_LOCALEDEF,	"_POSIX2_LOCALEDEF",	SYSCONF,   NOFLAGS,
164 	_SC_2_SW_DEV,		"POSIX2_SW_DEV",	SYSCONF,   NOFLAGS,
165 	_SC_2_SW_DEV,		"_POSIX2_SW_DEV",	SYSCONF,   NOFLAGS,
166 	_SC_2_UPE,		"POSIX2_UPE",		SYSCONF,   NOFLAGS,
167 	_SC_2_UPE,		"_POSIX2_UPE",		SYSCONF,   NOFLAGS,
168 
169 	/* POSIX.1-1990 table 2-3 */
170 	_POSIX_ARG_MAX,		"_POSIX_ARG_MAX",	SELFCONF,   NOFLAGS,
171 	_POSIX_CHILD_MAX,	"_POSIX_CHILD_MAX",	SELFCONF,   NOFLAGS,
172 	_POSIX_LINK_MAX,	"_POSIX_LINK_MAX",	SELFCONF,   NOFLAGS,
173 	_POSIX_MAX_CANON,	"_POSIX_MAX_CANON",	SELFCONF,   NOFLAGS,
174 	_POSIX_MAX_INPUT,	"_POSIX_MAX_INPUT",	SELFCONF,   NOFLAGS,
175 	_POSIX_NAME_MAX,	"_POSIX_NAME_MAX",	SELFCONF,   NOFLAGS,
176 	_POSIX_NGROUPS_MAX,	"_POSIX_NGROUPS_MAX",	SELFCONF,   NOFLAGS,
177 	_POSIX_OPEN_MAX,	"_POSIX_OPEN_MAX",	SELFCONF,   NOFLAGS,
178 	_POSIX_PATH_MAX,	"_POSIX_PATH_MAX",	SELFCONF,   NOFLAGS,
179 	_POSIX_PIPE_BUF,	"_POSIX_PIPE_BUF",	SELFCONF,   NOFLAGS,
180 	_POSIX_SSIZE_MAX,	"_POSIX_SSIZE_MAX",	SELFCONF,   NOFLAGS,
181 	_POSIX_STREAM_MAX,	"_POSIX_STREAM_MAX",	SELFCONF,   NOFLAGS,
182 	_POSIX_TIMER_MAX,	"_POSIX_TIMER_MAX",	SELFCONF,   NOFLAGS,
183 	_POSIX_THREAD_DESTRUCTOR_ITERATIONS,
184 		"_POSIX_THREAD_DESTRUCTOR_ITERATIONS",	SELFCONF,   NOFLAGS,
185 	_POSIX_THREAD_KEYS_MAX,
186 		"_POSIX_THREAD_KEYS_MAX",		SELFCONF,   NOFLAGS,
187 	_POSIX_THREAD_THREADS_MAX,
188 		"_POSIX_THREAD_THREADS_MAX",		SELFCONF,   NOFLAGS,
189 	_POSIX_TZNAME_MAX,	"_POSIX_TZNAME_MAX",	SELFCONF,   NOFLAGS,
190 
191 	/* POSIX.1-1990 table 4-2 */
192 	_SC_ARG_MAX,		"ARG_MAX",		SYSCONF,   NOFLAGS,
193 	_SC_CHILD_MAX,		"CHILD_MAX",		SYSCONF,   NOFLAGS,
194 	_SC_CLK_TCK,		"CLK_TCK",		SYSCONF,   NOFLAGS,
195 	_SC_JOB_CONTROL,	"_POSIX_JOB_CONTROL",	SYSCONF,   NOFLAGS,
196 	_SC_NGROUPS_MAX,	"NGROUPS_MAX",		SYSCONF,   NOFLAGS,
197 	_SC_OPEN_MAX,		"OPEN_MAX",		SYSCONF,   NOFLAGS,
198 	_SC_SAVED_IDS,		"_POSIX_SAVED_IDS",	SYSCONF,   NOFLAGS,
199 	_SC_STREAM_MAX,		"STREAM_MAX",		SYSCONF,   NOFLAGS,
200 	_SC_TZNAME_MAX,		"TZNAME_MAX",		SYSCONF,   NOFLAGS,
201 	_SC_VERSION,		"_POSIX_VERSION",	SYSCONF,   NOFLAGS,
202 
203 	/* pathconf() variables */
204 
205 	/* POSIX.1-1990 table 5-2 */
206 
207 	_PC_LINK_MAX,		"LINK_MAX",		PATHCONF,  NOFLAGS,
208 	_PC_MAX_CANON,		"MAX_CANON",		PATHCONF,  NOFLAGS,
209 	_PC_MAX_INPUT,		"MAX_INPUT",		PATHCONF,  NOFLAGS,
210 	_PC_NAME_MAX,		"NAME_MAX",		PATHCONF,  NOFLAGS,
211 	_PC_PATH_MAX,		"PATH_MAX",		PATHCONF,  NOFLAGS,
212 	_PC_PIPE_BUF,		"PIPE_BUF",		PATHCONF,  NOFLAGS,
213 	_PC_CHOWN_RESTRICTED,	"_POSIX_CHOWN_RESTRICTED", PATHCONF,  NOFLAGS,
214 	_PC_NO_TRUNC,		"_POSIX_NO_TRUNC",	PATHCONF,  NOFLAGS,
215 	_PC_VDISABLE,		"_POSIX_VDISABLE",	PATHCONF,  NOFLAGS,
216 
217 	/* UNIX 98 additions */
218 
219 	_PC_ASYNC_IO,		"_POSIX_ASYNC_IO",	PATHCONF,  NOFLAGS,
220 	_PC_PRIO_IO,		"_POSIX_PRIO_IO",	PATHCONF,  NOFLAGS,
221 	_PC_SYNC_IO,		"_POSIX_SYNC_IO",	PATHCONF,  NOFLAGS,
222 
223 	/* Large File Summit name (UNIX 98) */
224 
225 	_PC_FILESIZEBITS,	"FILESIZEBITS",		PATHCONF,  NOFLAGS,
226 
227 	/* UNIX 03 Additions */
228 
229 	/* Advisory Information (ADV) */
230 	_PC_ALLOC_SIZE_MIN,	"POSIX_ALLOC_SIZE_MIN",	PATHCONF,  NOFLAGS,
231 	_PC_REC_INCR_XFER_SIZE,	"POSIX_REC_INCR_XFER_SIZE", PATHCONF,  NOFLAGS,
232 	_PC_REC_MAX_XFER_SIZE,	"POSIX_REC_MAX_XFER_SIZE",  PATHCONF,  NOFLAGS,
233 	_PC_REC_MIN_XFER_SIZE,	"POSIX_REC_MIN_XFER_SIZE",  PATHCONF,  NOFLAGS,
234 	_PC_REC_XFER_ALIGN,	"POSIX_REC_XFER_ALIGN",	PATHCONF,  NOFLAGS,
235 
236 	_PC_2_SYMLINKS,		"POSIX2_SYMLINKS",	PATHCONF,  NOFLAGS,
237 	_PC_SYMLINK_MAX,	"SYMLINK_MAX",		PATHCONF,  NOFLAGS,
238 
239 	/* confstr() variables */
240 
241 	/* POSIX.2-1992 description of getconf utility */
242 	_CS_PATH,		"PATH",			CONFSTR,   NOFLAGS,
243 
244 	/* POSIX.2-1992 table B-18 */
245 	_CS_PATH,		"CS_PATH",		CONFSTR,   NOFLAGS,
246 	_CS_PATH,		"_CS_PATH",		CONFSTR,   NOFLAGS,
247 
248 	/* command names for large file configuration information */
249 	/* large file compilation environment configuration */
250 
251 	_CS_LFS_CFLAGS,		"LFS_CFLAGS",		CONFSTR,   NOFLAGS,
252 	_CS_LFS_LDFLAGS,	"LFS_LDFLAGS",		CONFSTR,   NOFLAGS,
253 	_CS_LFS_LIBS,		"LFS_LIBS",		CONFSTR,   NOFLAGS,
254 	_CS_LFS_LINTFLAGS,	"LFS_LINTFLAGS",	CONFSTR,   NOFLAGS,
255 
256 	/* transitional large file interface configuration */
257 
258 	_CS_LFS64_CFLAGS,	"LFS64_CFLAGS",		CONFSTR,   NOFLAGS,
259 	_CS_LFS64_LDFLAGS,	"LFS64_LDFLAGS",	CONFSTR,   NOFLAGS,
260 	_CS_LFS64_LIBS,		"LFS64_LIBS",		CONFSTR,   NOFLAGS,
261 	_CS_LFS64_LINTFLAGS,	"LFS64_LINTFLAGS",	CONFSTR,   NOFLAGS,
262 
263 	/*
264 	 *  UNIX 98:
265 	 *  confstr additions, these support
266 	 *  programming specifications/environments.
267 	 *
268 	 * Unfortunately there is some uncertainty with
269 	 * the standard at this point about the constant
270 	 * name, thus we need to recognize BOTH with and
271 	 * without the initial underscore.
272 	 */
273 	_CS_XBS5_ILP32_OFF32_CFLAGS,	"XBS5_ILP32_OFF32_CFLAGS",
274 		CONFSTR,	NOFLAGS,
275 	_CS_XBS5_ILP32_OFF32_CFLAGS,	"_XBS5_ILP32_OFF32_CFLAGS",
276 		CONFSTR,	NOFLAGS,
277 
278 	_CS_XBS5_ILP32_OFF32_LDFLAGS,	"XBS5_ILP32_OFF32_LDFLAGS",
279 		CONFSTR,	NOFLAGS,
280 	_CS_XBS5_ILP32_OFF32_LDFLAGS,	"_XBS5_ILP32_OFF32_LDFLAGS",
281 		CONFSTR,	NOFLAGS,
282 
283 	_CS_XBS5_ILP32_OFF32_LIBS,	"XBS5_ILP32_OFF32_LIBS",
284 		CONFSTR,	NOFLAGS,
285 	_CS_XBS5_ILP32_OFF32_LIBS,	"_XBS5_ILP32_OFF32_LIBS",
286 		CONFSTR,	NOFLAGS,
287 
288 	_CS_XBS5_ILP32_OFF32_LINTFLAGS,	"XBS5_ILP32_OFF32_LINTFLAGS",
289 		CONFSTR,	NOFLAGS,
290 	_CS_XBS5_ILP32_OFF32_LINTFLAGS,	"_XBS5_ILP32_OFF32_LINTFLAGS",
291 		CONFSTR,	NOFLAGS,
292 
293 	_CS_XBS5_ILP32_OFFBIG_CFLAGS,	"XBS5_ILP32_OFFBIG_CFLAGS",
294 		CONFSTR,	NOFLAGS,
295 	_CS_XBS5_ILP32_OFFBIG_CFLAGS,	"_XBS5_ILP32_OFFBIG_CFLAGS",
296 		CONFSTR,	NOFLAGS,
297 
298 	_CS_XBS5_ILP32_OFFBIG_LDFLAGS,	"XBS5_ILP32_OFFBIG_LDFLAGS",
299 		CONFSTR,	NOFLAGS,
300 	_CS_XBS5_ILP32_OFFBIG_LDFLAGS,	"_XBS5_ILP32_OFFBIG_LDFLAGS",
301 		CONFSTR,	NOFLAGS,
302 
303 	_CS_XBS5_ILP32_OFFBIG_LIBS,	"XBS5_ILP32_OFFBIG_LIBS",
304 		CONFSTR,	NOFLAGS,
305 	_CS_XBS5_ILP32_OFFBIG_LIBS,	"_XBS5_ILP32_OFFBIG_LIBS",
306 		CONFSTR,	NOFLAGS,
307 
308 	_CS_XBS5_ILP32_OFFBIG_LINTFLAGS, "XBS5_ILP32_OFFBIG_LINTFLAGS",
309 		CONFSTR,	NOFLAGS,
310 	_CS_XBS5_ILP32_OFFBIG_LINTFLAGS, "_XBS5_ILP32_OFFBIG_LINTFLAGS",
311 		CONFSTR,	NOFLAGS,
312 
313 	_CS_XBS5_LP64_OFF64_CFLAGS,	"XBS5_LP64_OFF64_CFLAGS",
314 		CONFSTR,	NOFLAGS,
315 	_CS_XBS5_LP64_OFF64_CFLAGS,	"_XBS5_LP64_OFF64_CFLAGS",
316 		CONFSTR,	NOFLAGS,
317 
318 	_CS_XBS5_LP64_OFF64_LDFLAGS,	"XBS5_LP64_OFF64_LDFLAGS",
319 		CONFSTR,	NOFLAGS,
320 	_CS_XBS5_LP64_OFF64_LDFLAGS,	"_XBS5_LP64_OFF64_LDFLAGS",
321 		CONFSTR,	NOFLAGS,
322 
323 	_CS_XBS5_LP64_OFF64_LIBS,	"XBS5_LP64_OFF64_LIBS",
324 		CONFSTR,	NOFLAGS,
325 	_CS_XBS5_LP64_OFF64_LIBS,	"_XBS5_LP64_OFF64_LIBS",
326 		CONFSTR,	NOFLAGS,
327 
328 	_CS_XBS5_LP64_OFF64_LINTFLAGS,	"XBS5_LP64_OFF64_LINTFLAGS",
329 		CONFSTR,	NOFLAGS,
330 	_CS_XBS5_LP64_OFF64_LINTFLAGS,	"_XBS5_LP64_OFF64_LINTFLAGS",
331 		CONFSTR,	NOFLAGS,
332 
333 	_CS_XBS5_LPBIG_OFFBIG_CFLAGS,	"XBS5_LPBIG_OFFBIG_CFLAGS",
334 		CONFSTR,	NOFLAGS,
335 	_CS_XBS5_LPBIG_OFFBIG_CFLAGS,	"_XBS5_LPBIG_OFFBIG_CFLAGS",
336 		CONFSTR,	NOFLAGS,
337 
338 	_CS_XBS5_LPBIG_OFFBIG_LDFLAGS,	"XBS5_LPBIG_OFFBIG_LDFLAGS",
339 		CONFSTR,	NOFLAGS,
340 	_CS_XBS5_LPBIG_OFFBIG_LDFLAGS,	"_XBS5_LPBIG_OFFBIG_LDFLAGS",
341 		CONFSTR,	NOFLAGS,
342 
343 	_CS_XBS5_LPBIG_OFFBIG_LIBS,	"XBS5_LPBIG_OFFBIG_LIBS",
344 		CONFSTR,	NOFLAGS,
345 	_CS_XBS5_LPBIG_OFFBIG_LIBS,	"_XBS5_LPBIG_OFFBIG_LIBS",
346 		CONFSTR,	NOFLAGS,
347 
348 	_CS_XBS5_LPBIG_OFFBIG_LINTFLAGS, "XBS5_LPBIG_OFFBIG_LINTFLAGS",
349 		CONFSTR,	NOFLAGS,
350 	_CS_XBS5_LPBIG_OFFBIG_LINTFLAGS, "_XBS5_LPBIG_OFFBIG_LINTFLAGS",
351 		CONFSTR,	NOFLAGS,
352 
353 	/*
354 	 * UNIX 03 confstr() additions for compilation environments
355 	 */
356 	_CS_POSIX_V6_ILP32_OFF32_CFLAGS, "POSIX_V6_ILP32_OFF32_CFLAGS",
357 		CONFSTR,	NOFLAGS,
358 	_CS_POSIX_V6_ILP32_OFF32_LDFLAGS, "POSIX_V6_ILP32_OFF32_LDFLAGS",
359 		CONFSTR,	NOFLAGS,
360 	_CS_POSIX_V6_ILP32_OFF32_LIBS, "POSIX_V6_ILP32_OFF32_LIBS",
361 		CONFSTR,	NOFLAGS,
362 	_CS_POSIX_V6_ILP32_OFFBIG_CFLAGS, "POSIX_V6_ILP32_OFFBIG_CFLAGS",
363 		CONFSTR,	NOFLAGS,
364 	_CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS, "POSIX_V6_ILP32_OFFBIG_LDFLAGS",
365 		CONFSTR,	NOFLAGS,
366 	_CS_POSIX_V6_ILP32_OFFBIG_LIBS, "POSIX_V6_ILP32_OFFBIG_LIBS",
367 		CONFSTR,	NOFLAGS,
368 	_CS_POSIX_V6_LP64_OFF64_CFLAGS, "POSIX_V6_LP64_OFF64_CFLAGS",
369 		CONFSTR,	NOFLAGS,
370 	_CS_POSIX_V6_LP64_OFF64_LDFLAGS, "POSIX_V6_LP64_OFF64_LDFLAGS",
371 		CONFSTR,	NOFLAGS,
372 	_CS_POSIX_V6_LP64_OFF64_LIBS, "POSIX_V6_LP64_OFF64_LIBS",
373 		CONFSTR,	NOFLAGS,
374 	_CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS, "POSIX_V6_LPBIG_OFFBIG_CFLAGS",
375 		CONFSTR,	NOFLAGS,
376 	_CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS, "POSIX_V6_LPBIG_OFFBIG_LDFLAGS",
377 		CONFSTR,	NOFLAGS,
378 	_CS_POSIX_V6_LPBIG_OFFBIG_LIBS, "POSIX_V6_LPBIG_OFFBIG_LIBS",
379 		CONFSTR,	NOFLAGS,
380 	_CS_POSIX_V6_WIDTH_RESTRICTED_ENVS, "POSIX_V6_WIDTH_RESTRICTED_ENVS",
381 		CONFSTR,	NOFLAGS,
382 	/* End of UNIX 03 compilation environments */
383 
384 #ifdef  _SC_2_C_VERSION		/* POSIX.2 table B-4 */
385 	_SC_2_C_VERSION,	"_POSIX2_C_VERSION",	SYSCONF,   NOFLAGS,
386 #else
387 	_POSIX2_C_VERSION,	"_POSIX2_C_VERSION",	SELFCONF,   NOFLAGS,
388 #endif
389 
390 /*
391  * XPG4 support BEGINS
392  */
393 
394 #ifndef CHARCLASS_NAME_MAX
395 #define	CHARCLASS_NAME_MAX	-1
396 #endif
397 #ifndef CHAR_BIT
398 #define	CHAR_BIT	-1
399 #endif
400 #ifndef CHAR_MAX
401 #define	CHAR_MAX	-1
402 #endif
403 #ifndef CHAR_MIN
404 #define	CHAR_MIN	-1
405 #endif
406 #ifndef INT_MAX
407 #define	INT_MAX	-1
408 #endif
409 #ifndef INT_MIN
410 #define	INT_MIN	-1
411 #endif
412 #ifndef LONG_BIT
413 #define	LONG_BIT	-1
414 #endif
415 #ifndef LONG_MAX
416 #define	LONG_MAX	-1
417 #endif
418 #ifndef LONG_MIN
419 #define	LONG_MIN	-1
420 #endif
421 #ifndef MB_LEN_MAX
422 #define	MB_LEN_MAX	-1
423 #endif
424 #ifndef NL_NMAX
425 #define	NL_NMAX	-1
426 #endif
427 #ifndef NL_ARGMAX
428 #define	NL_ARGMAX	-1
429 #endif
430 #ifndef NL_LANGMAX
431 #define	NL_LANGMAX	-1
432 #endif
433 #ifndef NL_MSGMAX
434 #define	NL_MSGMAX	-1
435 #endif
436 #ifndef NL_SETMAX
437 #define	NL_SETMAX	-1
438 #endif
439 #ifndef NL_TEXTMAX
440 #define	NL_TEXTMAX	-1
441 #endif
442 #ifndef NZERO
443 #define	NZERO	-1
444 #endif
445 #ifndef SCHAR_MAX
446 #define	SCHAR_MAX	-1
447 #endif
448 #ifndef SCHAR_MIN
449 #define	SCHAR_MIN	-1
450 #endif
451 #ifndef SHRT_MAX
452 #define	SHRT_MAX	-1
453 #endif
454 #ifndef SHRT_MIN
455 #define	SHRT_MIN	-1
456 #endif
457 #ifndef TMP_MAX
458 #define	TMP_MAX	-1
459 #endif
460 #ifndef WORD_BIT
461 #define	WORD_BIT	-1
462 #endif
463 
464 
465 #ifndef	_XOPEN_XPG2
466 #define	_XOPEN_XPG2	-1
467 #endif
468 #ifndef	_XOPEN_XPG3
469 #define	_XOPEN_XPG3	-1
470 #endif
471 #ifndef	_XOPEN_XPG4
472 #define	_XOPEN_XPG4	-1
473 #endif
474 
475 	/*
476 	 * the following are values that we should find in <limits.h>
477 	 * so we use SELFCONF here.
478 	 *
479 	 */
480 
481 	/* POSIX.1-1990 */
482 	CHARCLASS_NAME_MAX,	"CHARCLASS_NAME_MAX",	  SELFCONF,   NOFLAGS,
483 	SSIZE_MAX,		"SSIZE_MAX",	SELFCONF,   NOFLAGS,
484 
485 	/* POSIX.1-1988 */
486 	CHAR_BIT,		"CHAR_BIT",	SELFCONF,   NOFLAGS,
487 	CHAR_MAX,		"CHAR_MAX",	SELFCONF,   NOFLAGS,
488 	CHAR_MIN,		"CHAR_MIN",	SELFCONF,   NOFLAGS,
489 	INT_MAX,		"INT_MAX",	SELFCONF,   NOFLAGS,
490 	INT_MIN,		"INT_MIN",	SELFCONF,   NOFLAGS,
491 	LONG_BIT,		"LONG_BIT",	SELFCONF,   NOFLAGS,
492 	LONG_MAX,		"LONG_MAX",	SELFCONF,   NOFLAGS,
493 	LONG_MIN,		"LONG_MIN",	SELFCONF,   NOFLAGS,
494 	MB_LEN_MAX,		"MB_LEN_MAX",	SELFCONF,   NOFLAGS,
495 	NL_NMAX,		"NL_NMAX",	SELFCONF,   NOFLAGS,
496 	NL_ARGMAX,		"NL_ARGMAX",	SELFCONF,   NOFLAGS,
497 	NL_LANGMAX,		"NL_LANGMAX",	SELFCONF,   NOFLAGS,
498 	NL_MSGMAX,		"NL_MSGMAX",	SELFCONF,   NOFLAGS,
499 	NL_SETMAX,		"NL_SETMAX",	SELFCONF,   NOFLAGS,
500 	NL_TEXTMAX,		"NL_TEXTMAX",	SELFCONF,   NOFLAGS,
501 	NZERO,			"NZERO",	SELFCONF,   NOFLAGS,
502 	SCHAR_MAX,		"SCHAR_MAX",	SELFCONF,   NOFLAGS,
503 	SCHAR_MIN,		"SCHAR_MIN",	SELFCONF,   NOFLAGS,
504 	SHRT_MAX,		"SHRT_MAX",	SELFCONF,   NOFLAGS,
505 	SHRT_MIN,		"SHRT_MIN",	SELFCONF,   NOFLAGS,
506 	TMP_MAX,		"TMP_MAX",	SELFCONF,   NOFLAGS,
507 
508 	/*
509 	 * for the unsigned maximums, we cannot rely on the value -1
510 	 * to indicate "undefined".
511 	 */
512 #ifndef UCHAR_MAX
513 	0,			"UCHAR_MAX",	SELFCONF,   UNDEFINED,
514 #else
515 	(long)UCHAR_MAX,	"UCHAR_MAX",	SELFCONF,   UNSIGNED_VALUE,
516 #endif /* UCHAR_MAX */
517 #ifndef UINT_MAX
518 	0,			"UINT_MAX",	SELFCONF,   UNDEFINED,
519 #else
520 	(long)UINT_MAX,		"UINT_MAX",	SELFCONF,   UNSIGNED_VALUE,
521 #endif /* UINT_MAX */
522 #ifndef ULONG_MAX
523 	0,			"ULONG_MAX",	SELFCONF,   UNDEFINED,
524 #else
525 	(long)ULONG_MAX,	"ULONG_MAX",	SELFCONF,   UNSIGNED_VALUE,
526 #endif /* ULONG_MAX */
527 #ifndef USHRT_MAX
528 	0,			"USHRT_MAX",	SELFCONF,   UNDEFINED,
529 #else
530 	(long)USHRT_MAX,	"USHRT_MAX",	SELFCONF,   UNSIGNED_VALUE,
531 #endif /* USHRT_MAX */
532 #ifndef SIZE_MAX
533 	0,			"SIZE_MAX",	SELFCONF,   UNDEFINED,
534 #else
535 	(long)SIZE_MAX,		"SIZE_MAX",	SELFCONF,   UNSIGNED_VALUE,
536 #endif /* SIZE_MAX */
537 
538 	WORD_BIT,		"WORD_BIT",	SELFCONF,   NOFLAGS,
539 
540 	/* XPG4 Version 2 */
541 	_XOPEN_IOV_MAX,		"_XOPEN_IOV_MAX",  SELFCONF, NOFLAGS,
542 
543 	/* UNIX 03 */
544 	_XOPEN_NAME_MAX,	"_XOPEN_NAME_MAX", SELFCONF, NOFLAGS,
545 	_XOPEN_PATH_MAX,	"_XOPEN_PATH_MAX", SELFCONF, NOFLAGS,
546 
547 	/*
548 	 * The following are defined via sysconf().  These are considered
549 	 * an extension to sysconf().
550 	 * The -0 is needed if _XOPEN_XPG? is defined to be an empty string.
551 	 */
552 	_XOPEN_XPG2-0,		"_XOPEN_XPG2",	SELFCONF,    NOFLAGS,
553 	_XOPEN_XPG3-0,		"_XOPEN_XPG3",	SELFCONF,    NOFLAGS,
554 	_XOPEN_XPG4-0,		"_XOPEN_XPG4",	SELFCONF,    NOFLAGS,
555 
556 	/*
557 	 * The following should be provided by sysconf() (e.g use SYSCONF),
558 	 * so we  look for the appropriate _SC_* symbol in <unistd.h>.
559 	 * If it is not defined, then we use SELFCONF with the value of -1.
560 	 */
561 	_SC_XOPEN_VERSION,	"_XOPEN_VERSION",	SYSCONF,   NOFLAGS,
562 	_SC_XOPEN_XCU_VERSION,	"_XOPEN_XCU_VERSION",	SYSCONF,   NOFLAGS,
563 	_SC_XOPEN_CRYPT,	"_XOPEN_CRYPT",		SYSCONF,   NOFLAGS,
564 	_SC_XOPEN_ENH_I18N,	"_XOPEN_ENH_I18N",	SYSCONF,   NOFLAGS,
565 	_SC_XOPEN_SHM,		"_XOPEN_SHM",		SYSCONF,   NOFLAGS,
566 
567 /*
568  * XPG4 support ends
569  */
570 
571 /* XPG4, Version 2 support */
572 
573 	_SC_ATEXIT_MAX, 	"ATEXIT_MAX",		SYSCONF,	NOFLAGS,
574 	_SC_PAGESIZE,		"PAGESIZE",		SYSCONF,	NOFLAGS,
575 	_SC_PAGE_SIZE,		"PAGE_SIZE",		SYSCONF,	NOFLAGS,
576 	_SC_XOPEN_UNIX,		"_XOPEN_UNIX",		SYSCONF,	NOFLAGS,
577 	_SC_IOV_MAX,		"IOV_MAX",		SYSCONF, 	NOFLAGS,
578 
579 /*
580  * UNIX 98 - XPG5 additions
581  */
582 	_SC_XOPEN_LEGACY,	"_XOPEN_LEGACY",	SYSCONF, 	NOFLAGS,
583 	_SC_PASS_MAX,		"PASS_MAX",		SYSCONF, 	NOFLAGS,
584 	_SC_AIO_LISTIO_MAX,	"AIO_LISTIO_MAX",	SYSCONF, 	NOFLAGS,
585 	_SC_AIO_MAX,		"AIO_MAX",		SYSCONF, 	NOFLAGS,
586 	_SC_AIO_PRIO_DELTA_MAX,	"AIO_PRIO_DELTA_MAX",	SYSCONF, 	NOFLAGS,
587 	_SC_DELAYTIMER_MAX,	"DELAYTIMER_MAX",	SYSCONF, 	NOFLAGS,
588 	_SC_MQ_OPEN_MAX,	"MQ_OPEN_MAX",		SYSCONF, 	NOFLAGS,
589 	_SC_MQ_PRIO_MAX,	"MQ_PRIO_MAX",		SYSCONF, 	NOFLAGS,
590 	_SC_RTSIG_MAX,		"RTSIG_MAX",		SYSCONF, 	NOFLAGS,
591 	_SC_SEM_NSEMS_MAX,	"SEM_NSEMS_MAX",	SYSCONF, 	NOFLAGS,
592 	_SC_SEM_VALUE_MAX,	"SEM_VALUE_MAX",	SYSCONF, 	NOFLAGS,
593 	_SC_SIGQUEUE_MAX,	"SIGQUEUE_MAX",		SYSCONF, 	NOFLAGS,
594 	_SC_TIMER_MAX,		"TIMER_MAX",		SYSCONF, 	NOFLAGS,
595 
596 	_SC_ASYNCHRONOUS_IO,	"_POSIX_ASYNCHRONOUS_IO", SYSCONF, 	NOFLAGS,
597 	_SC_FSYNC,		"_POSIX_FSYNC",		SYSCONF,	NOFLAGS,
598 	_SC_MAPPED_FILES,	"_POSIX_MAPPED_FILES",	SYSCONF, 	NOFLAGS,
599 	_SC_MEMLOCK,		"_POSIX_MEMLOCK",	SYSCONF, 	NOFLAGS,
600 	_SC_MEMLOCK_RANGE,	"_POSIX_MEMLOCK_RANGE",	SYSCONF, 	NOFLAGS,
601 	_SC_MEMORY_PROTECTION,	"_POSIX_MEMORY_PROTECTION", SYSCONF, 	NOFLAGS,
602 	_SC_MESSAGE_PASSING,	"_POSIX_MESSAGE_PASSING", SYSCONF, 	NOFLAGS,
603 	_SC_PRIORITIZED_IO,	"_POSIX_PRIORITIZED_IO", SYSCONF, 	NOFLAGS,
604 	_SC_PRIORITY_SCHEDULING, "_POSIX_PRIORITY_SCHEDULING", SYSCONF, NOFLAGS,
605 	_SC_REALTIME_SIGNALS,	"_POSIX_REALTIME_SIGNALS", SYSCONF, 	NOFLAGS,
606 	_SC_SEMAPHORES,		"_POSIX_SEMAPHORES",	SYSCONF, 	NOFLAGS,
607 
608 	_SC_SHARED_MEMORY_OBJECTS, "_POSIX_SHARED_MEMORY_OBJECTS",
609 	    SYSCONF, 	NOFLAGS,
610 
611 	_SC_SYNCHRONIZED_IO,	"_POSIX_SYNCHRONIZED_IO", SYSCONF, 	NOFLAGS,
612 	_SC_TIMERS,		"_POSIX_TIMERS",	SYSCONF, 	NOFLAGS,
613 
614 	_SC_LOGIN_NAME_MAX,	"LOGIN_NAME_MAX",	SYSCONF, 	NOFLAGS,
615 
616 	_SC_THREAD_DESTRUCTOR_ITERATIONS, "PTHREAD_DESTRUCTOR_ITERATIONS",
617 	    SYSCONF, 	NOFLAGS,
618 
619 	_SC_THREAD_KEYS_MAX,	"PTHREAD_KEYS_MAX",	SYSCONF, 	NOFLAGS,
620 	_SC_THREAD_STACK_MIN,	"PTHREAD_STACK_MIN",	SYSCONF, 	NOFLAGS,
621 	_SC_THREAD_THREADS_MAX,	"PTHREAD_THREADS_MAX",	SYSCONF, 	NOFLAGS,
622 
623 	_SC_THREADS,		"_POSIX_THREADS",	SYSCONF, 	NOFLAGS,
624 
625 	_SC_THREAD_ATTR_STACKADDR, "POSIX_THREAD_ATTR_STACKADDR",
626 	    SYSCONF, 	NOFLAGS,
627 	_SC_THREAD_ATTR_STACKADDR, "_POSIX_THREAD_ATTR_STACKADDR",
628 	    SYSCONF, 	NOFLAGS,
629 
630 	_SC_THREAD_ATTR_STACKSIZE, "POSIX_THREAD_ATTR_STACKSIZE",
631 	    SYSCONF, 	NOFLAGS,
632 	_SC_THREAD_ATTR_STACKSIZE, "_POSIX_THREAD_ATTR_STACKSIZE",
633 	    SYSCONF, 	NOFLAGS,
634 
635 	_SC_THREAD_PRIORITY_SCHEDULING, "POSIX_THREAD_PRIORITY_SCHEDULING",
636 	    SYSCONF, 	NOFLAGS,
637 	_SC_THREAD_PRIORITY_SCHEDULING, "_POSIX_THREAD_PRIORITY_SCHEDULING",
638 	    SYSCONF, 	NOFLAGS,
639 
640 	_SC_THREAD_PRIO_INHERIT, "POSIX_THREAD_PRIO_INHERIT",
641 	    SYSCONF, 	NOFLAGS,
642 	_SC_THREAD_PRIO_INHERIT, "_POSIX_THREAD_PRIO_INHERIT",
643 	    SYSCONF, 	NOFLAGS,
644 
645 	_SC_THREAD_PRIO_PROTECT, "POSIX_THREAD_PRIO_PROTECT",
646 	    SYSCONF, 	NOFLAGS,
647 	_SC_THREAD_PRIO_PROTECT, "_POSIX_THREAD_PRIO_PROTECT",
648 	    SYSCONF, 	NOFLAGS,
649 
650 	_SC_THREAD_PROCESS_SHARED, "POSIX_THREAD_PROCESS_SHARED",
651 	    SYSCONF, 	NOFLAGS,
652 	_SC_THREAD_PROCESS_SHARED, "_POSIX_THREAD_PROCESS_SHARED",
653 	    SYSCONF, 	NOFLAGS,
654 
655 	_SC_THREAD_SAFE_FUNCTIONS, "POSIX_THREAD_SAFE_FUNCTIONS",
656 	    SYSCONF, 	NOFLAGS,
657 	_SC_THREAD_SAFE_FUNCTIONS, "_POSIX_THREAD_SAFE_FUNCTIONS",
658 	    SYSCONF, 	NOFLAGS,
659 
660 	_SC_TTY_NAME_MAX,	"TTY_NAME_MAX",		SYSCONF,	NOFLAGS,
661 	_SC_XOPEN_REALTIME,	"_XOPEN_REALTIME",	SYSCONF, 	NOFLAGS,
662 	_SC_XOPEN_REALTIME_THREADS, "_XOPEN_REALTIME_THREADS", SYSCONF, NOFLAGS,
663 
664 	/*
665 	 * Due to ambiguity in the standard we need
666 	 * to recognize both the underscored name
667 	 * and the non-underscored version in the
668 	 * following variables.
669 	 */
670 	_SC_XBS5_ILP32_OFF32,	"XBS5_ILP32_OFF32",	SYSCONF, 	NOFLAGS,
671 	_SC_XBS5_ILP32_OFF32,	"_XBS5_ILP32_OFF32",	SYSCONF, 	NOFLAGS,
672 
673 	_SC_XBS5_ILP32_OFFBIG,	"XBS5_ILP32_OFFBIG",	SYSCONF, 	NOFLAGS,
674 	_SC_XBS5_ILP32_OFFBIG,	"_XBS5_ILP32_OFFBIG",	SYSCONF, 	NOFLAGS,
675 
676 	_SC_XBS5_LP64_OFF64,	"XBS5_LP64_OFF64",	SYSCONF, 	NOFLAGS,
677 	_SC_XBS5_LP64_OFF64,	"_XBS5_LP64_OFF64",	SYSCONF, 	NOFLAGS,
678 
679 	_SC_XBS5_LPBIG_OFFBIG,	"XBS5_LPBIG_OFFBIG",	SYSCONF, 	NOFLAGS,
680 	_SC_XBS5_LPBIG_OFFBIG,	"_XBS5_LPBIG_OFFBIG",	SYSCONF, 	NOFLAGS,
681 
682 /*
683  * UNIX 03 additions for sysconf() names, and names that are not in interfaces
684  */
685 	_SC_REGEXP,		"_POSIX_REGEXP",	  SYSCONF,	NOFLAGS,
686 	_SC_SHELL,		"_POSIX_SHELL",		  SYSCONF,	NOFLAGS,
687 	_SC_HOST_NAME_MAX,	"HOST_NAME_MAX",	  SYSCONF,	NOFLAGS,
688 	_SC_READER_WRITER_LOCKS, "_POSIX_READER_WRITER_LOCKS", SYSCONF,	NOFLAGS,
689 	_SC_IPV6,		"_POSIX_IPV6",		  SYSCONF,	NOFLAGS,
690 	_SC_RAW_SOCKETS,	"_POSIX_RAW_SOCKETS",	  SYSCONF,	NOFLAGS,
691 	_SC_XOPEN_STREAMS, 	"_XOPEN_STREAMS",	  SYSCONF,	NOFLAGS,
692 	_SC_SYMLOOP_MAX,	"SYMLOOP_MAX",		  SYSCONF,	NOFLAGS,
693 	_SC_2_PBS,		"_POSIX2_PBS",		  SYSCONF,	NOFLAGS,
694 	_SC_2_PBS_ACCOUNTING,   "_POSIX2_PBS_ACCOUNTING", SYSCONF,	NOFLAGS,
695 	_SC_2_PBS_CHECKPOINT,   "_POSIX2_PBS_CHECKPOINT", SYSCONF,	NOFLAGS,
696 	_SC_2_PBS_LOCATE,	"_POSIX2_PBS_LOCATE",	  SYSCONF,	NOFLAGS,
697 	_SC_2_PBS_MESSAGE,	"_POSIX2_PBS_MESSAGE",	  SYSCONF,	NOFLAGS,
698 	_SC_2_PBS_TRACK,	"_POSIX2_PBS_TRACK",	  SYSCONF,	NOFLAGS,
699 
700 	_SC_ADVISORY_INFO,	"_POSIX_ADVISORY_INFO",   SYSCONF,	NOFLAGS,
701 	_SC_BARRIERS,		"_POSIX_BARRIERS",	  SYSCONF,	NOFLAGS,
702 	_SC_CLOCK_SELECTION,	"_POSIX_CLOCK_SELECTION", SYSCONF,	NOFLAGS,
703 	_SC_CPUTIME,		"_POSIX_CPUTIME",	  SYSCONF,	NOFLAGS,
704 	_SC_MONOTONIC_CLOCK,	"_POSIX_MONOTONIC_CLOCK", SYSCONF,	NOFLAGS,
705 	_SC_SPAWN,		"_POSIX_SPAWN",		  SYSCONF,	NOFLAGS,
706 	_SC_SPIN_LOCKS,		"_POSIX_SPIN_LOCKS",	  SYSCONF,	NOFLAGS,
707 	_SC_SPORADIC_SERVER,	"_POSIX_SPORADIC_SERVER", SYSCONF,	NOFLAGS,
708 	_SC_SS_REPL_MAX,	"_POSIX_SS_REPL_MAX",	  SYSCONF,	NOFLAGS,
709 	_SC_THREAD_CPUTIME,	"_POSIX_THREAD_CPUTIME",   SYSCONF,	NOFLAGS,
710 	_SC_THREAD_SPORADIC_SERVER, "_POSIX_THREAD_SPORADIC_SERVER", 	SYSCONF,
711 		NOFLAGS,
712 	_SC_TIMEOUTS,		"_POSIX_TIMEOUTS",	  SYSCONF,	NOFLAGS,
713 	_SC_TRACE,		"_POSIX_TRACE",		  SYSCONF,	NOFLAGS,
714 	_SC_TRACE_EVENT_FILTER, "_POSIX_TRACE_EVENT_FILTER", SYSCONF, 	NOFLAGS,
715 	_SC_TRACE_EVENT_NAME_MAX, "_POSIX_TRACE_EVENT_NAME_MAX", SYSCONF,
716 									NOFLAGS,
717 	_SC_TRACE_INHERIT,	"_POSIX_TRACE_INHERIT",   SYSCONF,	NOFLAGS,
718 	_SC_TRACE_LOG,		"_POSIX_TRACE_LOG",	  SYSCONF,	NOFLAGS,
719 	_SC_TRACE_NAME_MAX,	"_POSIX_TRACE_NAME_MAX",  SYSCONF,	NOFLAGS,
720 	_SC_TRACE_SYS_MAX,	"_POSIX_TRACE_SYS_MAX",	  SYSCONF,	NOFLAGS,
721 	_SC_TRACE_USER_EVENT_MAX, "_POSIX_TRACE_USER_EVENT_MAX", SYSCONF,
722 									NOFLAGS,
723 	_SC_TYPED_MEMORY_OBJECTS, "_POSIX_TYPED_MEMORY_OBJECTS",	SYSCONF,
724 		NOFLAGS,
725 
726 	/*
727 	 * Due to an ambiguity in the specification, we need to recognize both
728 	 * the underscored POSIX name and the non-underscored name. In addition,
729 	 * we need to permit the use of the _V6_* environment names specified
730 	 * in unistd.h.
731 	 */
732 	_SC_V6_ILP32_OFF32,	"_V6_ILP32_OFF32", 	SYSCONF,	NOFLAGS,
733 	_SC_V6_ILP32_OFF32,	"_POSIX_V6_ILP32_OFF32", SYSCONF,	NOFLAGS,
734 	_SC_V6_ILP32_OFF32,	"POSIX_V6_ILP32_OFF32", SYSCONF,	NOFLAGS,
735 
736 	_SC_V6_ILP32_OFFBIG,	"_V6_ILP32_OFFBIG", 	SYSCONF,	NOFLAGS,
737 	_SC_V6_ILP32_OFFBIG,	"_POSIX_V6_ILP32_OFFBIG", SYSCONF,	NOFLAGS,
738 	_SC_V6_ILP32_OFFBIG,	"POSIX_V6_ILP32_OFFBIG", SYSCONF,	NOFLAGS,
739 
740 	_SC_V6_LP64_OFF64,	"_V6_LP64_OFF64", 	SYSCONF,	NOFLAGS,
741 	_SC_V6_LP64_OFF64,	"_POSIX_V6_LP64_OFF64",	SYSCONF,	NOFLAGS,
742 	_SC_V6_LP64_OFF64,	"POSIX_V6_LP64_OFF64", 	SYSCONF,	NOFLAGS,
743 
744 	_SC_V6_LPBIG_OFFBIG,	"_V6_LPBIG_OFFBIG", 	SYSCONF,	NOFLAGS,
745 	_SC_V6_LPBIG_OFFBIG,	"_POSIX_V6_LPBIG_OFFBIG", SYSCONF,	NOFLAGS,
746 	_SC_V6_LPBIG_OFFBIG,	"POSIX_V6_LPBIG_OFFBIG",  SYSCONF,	NOFLAGS,
747 	0,		NULL,	0,	0		/* end of table */
748 };
749 
750 
751 /*
752  * Print usage message.
753  */
754 static int
755 usage()
756 {
757 
758 	(void) fputs(gettext(
759 	    "usage:\tgetconf [-v specification] system_var\n"
760 	    "\tgetconf [-v specification] path_var pathname\n"
761 	    "\tgetconf -a\n"), stderr);
762 	return (2);
763 }
764 
765 
766 static int
767 namecmp(const void *a, const void *b)
768 {
769 	return (strcoll(((const struct sctab *)a)->name,
770 	    ((const struct sctab *)b)->name));
771 }
772 
773 
774 static int
775 getconf(struct sctab *scp, int argc, char *name, char *file)
776 {
777 	register size_t len;
778 	register char *buffer;
779 	long value;
780 
781 	switch (scp->type) {
782 	case SELFCONF:
783 		if (argc > 2)
784 			return (usage());
785 		if (scp->flag & UNDEFINED ||
786 		    (!(scp->flag&UNSIGNED_VALUE) && scp->value == -1)) {
787 			/* DO NOT TRANSLATE */
788 			(void) printf("undefined\n");
789 		} else
790 			if (scp->flag & UNSIGNED_VALUE)
791 				(void) printf("%lu\n", scp->value);
792 			else
793 				(void) printf("%ld\n", scp->value);
794 		break;
795 
796 	case SYSCONF:
797 		if (argc > 2)
798 			return (usage());
799 		errno = 0;
800 		if (scp->flag & UNDEFINED ||
801 		    (value = sysconf((int)scp->value)) == -1) {
802 			if (errno == EINVAL) {
803 				(void) fprintf(stderr,
804 				    gettext(INVAL_ARG), name);
805 				return (1);
806 			} else {
807 				/* DO NOT TRANSLATE */
808 				(void) printf("undefined\n");
809 				return (0);
810 			}
811 		} else
812 			(void) printf("%ld\n", value);
813 		break;
814 
815 	case CONFSTR:
816 		if (argc > 2)
817 			return (usage());
818 		errno = 0;
819 		len = confstr((int)scp->value, NULL, (size_t)0);
820 		if (len == 0)
821 			if (errno == EINVAL) {
822 				(void) fprintf(stderr, gettext(INVAL_ARG),
823 				    name);
824 				return (1);
825 			} else {
826 				/* DO NOT TRANSLATE */
827 				(void) printf("undefined\n");
828 				return (0);
829 			}
830 		/*
831 		 * allocate space to store result of constr() into
832 		 */
833 		if ((buffer = malloc(len)) == NULL) {
834 			(void) fprintf(stderr,
835 			    gettext("insufficient memory available"));
836 			return (1);
837 		}
838 
839 		assert(confstr((int)scp->value, buffer, len) != 0);
840 
841 		(void) printf("%s\n", buffer);
842 		free(buffer);
843 		break;
844 
845 	case PATHCONF:
846 		if (argc != 3)
847 			return (usage());
848 		errno = 0;
849 		if ((value = pathconf(file, (int)scp->value)) == -1) {
850 			if (errno == EINVAL || errno == 0) {
851 				/* Does not support the association */
852 				/* DO NOT TRANSLATE */
853 				(void) printf("undefined\n");
854 				return (0);
855 			} else {
856 				/* Probably problems with the pathname itself */
857 				if (aflag) {
858 					(void) printf("%s\n", file);
859 				} else {
860 					(void) printf("%s", file);
861 				}
862 				return (1);
863 			}
864 		}
865 		(void) printf("%ld\n", value);
866 		break;
867 	}
868 	return (0);
869 }
870 
871 int
872 main(int argc, char **argv)
873 {
874 	register struct sctab *scp;
875 	int c;
876 	int exstat = 0;
877 
878 	(void) setlocale(LC_ALL, "");
879 #if	!defined(TEXT_DOMAIN)	/* Should be defined by cc -D */
880 #define	TEXT_DOMAIN "SYS_TEST"
881 #endif
882 	(void) textdomain(TEXT_DOMAIN);
883 
884 	while ((c = getopt(argc, argv, "av:")) != -1)
885 		switch (c) {
886 		case 'a':
887 			aflag = 1;
888 			break;
889 		case 'v':
890 			/*
891 			 * Unix98 adds the -v option to allow
892 			 * programming 'specifications' to be
893 			 * indicated, for present purposes
894 			 * the specification isn't really
895 			 * doing anything of value, so for
896 			 * the moment getopt just processes the
897 			 * option value and argv[1] is adjusted.
898 			 *
899 			 * At some later date we might want to
900 			 * do specification processing at this
901 			 * point.
902 			 */
903 			break;
904 		case '?':
905 			return (usage());
906 		}
907 	argc -= optind-1;
908 	argv += optind-1;
909 
910 	if ((aflag && argc >= 2) || (!aflag && argc < 2))
911 		return (usage());
912 	if (aflag) {
913 
914 #define	TabStop		8
915 #define	RightColumn	32
916 #define	DefPathName	"."
917 
918 		/*
919 		 * sort the table by the "name" field
920 		 * so we print it in sorted order
921 		 */
922 	qsort(&sctab[0], (sizeof (sctab)/sizeof (struct sctab))-1,
923 	    sizeof (struct sctab), namecmp);
924 
925 		/*
926 		 * print all the known symbols and their values
927 		 */
928 		for (scp = &sctab[0]; scp->name != NULL; ++scp) {
929 			int stat;
930 
931 			/*
932 			 * create 2 columns:
933 			 *   variable name in the left column,
934 			 *   value in the right column.
935 			 * The right column starts at a tab stop.
936 			 */
937 			(void) printf("%s:\t", scp->name);
938 
939 			c = strlen(scp->name) + 1;
940 			c = (c+TabStop) / TabStop, c *= TabStop;
941 			for (; c < RightColumn; c += TabStop)
942 				(void) putchar('\t');
943 
944 			/*
945 			 * for pathconf() related variables that require
946 			 * a pathname, use "."
947 			 */
948 			stat = getconf(scp, scp->type == PATHCONF ? 3 : 2,
949 			    scp->name, DefPathName);
950 
951 			exstat |= stat;
952 
953 			/*
954 			 * if stat != 0, then an error message was already
955 			 * printed in getconf(),
956 			 * so don't need to print one here
957 			 */
958 		}
959 	} else {
960 
961 		/*
962 		 * find the name of the specified variable (argv[1])
963 		 * and print its value.
964 		 */
965 		for (scp = &sctab[0]; scp->name != NULL; ++scp)
966 			if (strcmp(argv[1], scp->name) == 0) {
967 				exstat = getconf(scp, argc, argv[1], argv[2]);
968 				break;
969 			}
970 
971 		/*
972 		 * if at last entry in table, then the user specified
973 		 * variable is invalid
974 		 */
975 		if (scp->name == NULL) {
976 			errno = EINVAL;
977 			(void) fprintf(stderr, gettext(INVAL_ARG), argv[1]);
978 			return (1);
979 		}
980 	}
981 	return (exstat);
982 }
983