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