/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright 1985, 1993 by Mortice Kern Systems Inc. All rights reserved.
*
*/
/*
* getconf -- POSIX.2 compatible utility to query configuration specific
* parameters.
* -- XPG4 support added June/93
*
* -- XPG5 support added Dec/97
*
* -- XPG6 support added May/2003
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <limits.h>
#include <locale.h>
#include <libintl.h>
#include <assert.h>
static int aflag = 0;
/*
* Notes:
* The sctab.value field is defined to be a long.
* There are some values that are "unsigned long"; these values
* can be stored in a "long" field but when output, must be printed
* as an unsigned value. Thus, these values must have UNSIGNED_VALUE bit
* set in sctab.flag field.
*
* There are 2 different ways to indicate a symbol is undefined:
* 1) sctab.flag = UNDEFINED
* 2) or sctab.value = -1 (and if !UNDEFINED and !UNSIGNED_VALUE)
*
* There are a group of symbols (e.g CHAR_MIN, INT_MAX, INT_MIN, LONG_BIT ...)
* which we may set to -1 if they are not pre-defined in a system header file.
* This is used to indicate that these symbols are "undefined".
* We are assuming that these symbols cannot reasonably have a value of -1
* if they were defined in a system header file.
* (Unless of course -1 can be used to indicate "undefined" for that symbol)
*/
static struct sctab {
long value;
char *name;
int flag;
/* bit fields for sctab.flag member */
} sctab[] = {
/*
* Some entries in this structure have both leading _ and non leading _
* versions for compatibility with various versions of the specifications.
* It is not expected that both forms will be required for new entries.
*/
/* POSIX.2-1992 table 2-17 */
/* See limits.h section below for _POSIX_RE_DUP_MAX */
/* UNIX 98 */
/* UNIX 03 */
/* POSIX.2-1992 table 2-17 */
/* POSIX.2-1992 table 2-18 */
/* POSIX.2-1992 table 2-19 */
/* POSIX.1-1990 table 2-3 */
/* POSIX.1-1990 table 4-2 */
/* pathconf() variables */
/* POSIX.1-1990 table 5-2 */
/* UNIX 98 additions */
/* Large File Summit name (UNIX 98) */
/* UNIX 03 Additions */
/* Advisory Information (ADV) */
/* UNIX 08 additions */
_PC_TIMESTAMP_RESOLUTION, "_POSIX_TIMESTAMP_RESOLUTION",
/* confstr() variables */
/* POSIX.2-1992 description of getconf utility */
/* POSIX.2-1992 table B-18 */
/* command names for large file configuration information */
/* large file compilation environment configuration */
/* transitional large file interface configuration */
/*
* UNIX 98:
* confstr additions, these support
* programming specifications/environments.
*
* Unfortunately there is some uncertainty with
* the standard at this point about the constant
* name, thus we need to recognize BOTH with and
* without the initial underscore.
*/
_CS_XBS5_ILP32_OFF32_CFLAGS, "XBS5_ILP32_OFF32_CFLAGS",
_CS_XBS5_ILP32_OFF32_CFLAGS, "_XBS5_ILP32_OFF32_CFLAGS",
_CS_XBS5_ILP32_OFF32_LDFLAGS, "XBS5_ILP32_OFF32_LDFLAGS",
_CS_XBS5_ILP32_OFF32_LDFLAGS, "_XBS5_ILP32_OFF32_LDFLAGS",
_CS_XBS5_ILP32_OFF32_LIBS, "XBS5_ILP32_OFF32_LIBS",
_CS_XBS5_ILP32_OFF32_LIBS, "_XBS5_ILP32_OFF32_LIBS",
_CS_XBS5_ILP32_OFF32_LINTFLAGS, "XBS5_ILP32_OFF32_LINTFLAGS",
_CS_XBS5_ILP32_OFF32_LINTFLAGS, "_XBS5_ILP32_OFF32_LINTFLAGS",
_CS_XBS5_ILP32_OFFBIG_CFLAGS, "XBS5_ILP32_OFFBIG_CFLAGS",
_CS_XBS5_ILP32_OFFBIG_CFLAGS, "_XBS5_ILP32_OFFBIG_CFLAGS",
_CS_XBS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, "_XBS5_LPBIG_OFFBIG_LIBS",
_CS_XBS5_LPBIG_OFFBIG_LINTFLAGS, "XBS5_LPBIG_OFFBIG_LINTFLAGS",
_CS_XBS5_LPBIG_OFFBIG_LINTFLAGS, "_XBS5_LPBIG_OFFBIG_LINTFLAGS",
/*
* UNIX 03 confstr() additions for compilation environments
*/
_CS_POSIX_V6_ILP32_OFF32_CFLAGS, "POSIX_V6_ILP32_OFF32_CFLAGS",
_CS_POSIX_V6_ILP32_OFF32_LDFLAGS, "POSIX_V6_ILP32_OFF32_LDFLAGS",
_CS_POSIX_V6_ILP32_OFF32_LIBS, "POSIX_V6_ILP32_OFF32_LIBS",
_CS_POSIX_V6_ILP32_OFFBIG_CFLAGS, "POSIX_V6_ILP32_OFFBIG_CFLAGS",
_CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS, "POSIX_V6_ILP32_OFFBIG_LDFLAGS",
_CS_POSIX_V6_ILP32_OFFBIG_LIBS, "POSIX_V6_ILP32_OFFBIG_LIBS",
_CS_POSIX_V6_LP64_OFF64_CFLAGS, "POSIX_V6_LP64_OFF64_CFLAGS",
_CS_POSIX_V6_LP64_OFF64_LDFLAGS, "POSIX_V6_LP64_OFF64_LDFLAGS",
_CS_POSIX_V6_LP64_OFF64_LIBS, "POSIX_V6_LP64_OFF64_LIBS",
_CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS, "POSIX_V6_LPBIG_OFFBIG_CFLAGS",
_CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS, "POSIX_V6_LPBIG_OFFBIG_LDFLAGS",
_CS_POSIX_V6_LPBIG_OFFBIG_LIBS, "POSIX_V6_LPBIG_OFFBIG_LIBS",
_CS_POSIX_V6_WIDTH_RESTRICTED_ENVS, "POSIX_V6_WIDTH_RESTRICTED_ENVS",
/* End of UNIX 03 compilation environments */
#ifdef _SC_2_C_VERSION /* POSIX.2 table B-4 */
#else
#endif
/*
* XPG4 support BEGINS
*/
#ifndef CHARCLASS_NAME_MAX
#endif
#ifndef CHAR_BIT
#endif
#ifndef CHAR_MAX
#endif
#ifndef CHAR_MIN
#endif
#ifndef INT_MAX
#endif
#ifndef INT_MIN
#endif
#ifndef LONG_BIT
#endif
#ifndef LONG_MAX
#endif
#ifndef LONG_MIN
#endif
#ifndef MB_LEN_MAX
#endif
#ifndef NL_NMAX
#endif
#ifndef NL_ARGMAX
#endif
#ifndef NL_LANGMAX
#endif
#ifndef NL_MSGMAX
#endif
#ifndef NL_SETMAX
#endif
#ifndef NL_TEXTMAX
#endif
#ifndef NZERO
#endif
#ifndef SCHAR_MAX
#endif
#ifndef SCHAR_MIN
#endif
#ifndef SHRT_MAX
#endif
#ifndef SHRT_MIN
#endif
#ifndef TMP_MAX
#endif
#ifndef WORD_BIT
#endif
#ifndef _XOPEN_XPG2
#endif
#ifndef _XOPEN_XPG3
#endif
#ifndef _XOPEN_XPG4
#endif
/*
* the following are values that we should find in <limits.h>
* so we use SELFCONF here.
*
*/
/* POSIX.1-1990 */
/* POSIX.1-1988 */
/*
* for the unsigned maximums, we cannot rely on the value -1
* to indicate "undefined".
*/
#ifndef UCHAR_MAX
#else
#endif /* UCHAR_MAX */
#ifndef UINT_MAX
#else
#endif /* UINT_MAX */
#ifndef ULONG_MAX
#else
#endif /* ULONG_MAX */
#ifndef USHRT_MAX
#else
#endif /* USHRT_MAX */
#ifndef SIZE_MAX
#else
#endif /* SIZE_MAX */
/* XPG4 Version 2 */
/* UNIX 03 */
/*
* The following are defined via sysconf(). These are considered
* an extension to sysconf().
* The -0 is needed if _XOPEN_XPG? is defined to be an empty string.
*/
/*
* The following should be provided by sysconf() (e.g use SYSCONF),
* so we look for the appropriate _SC_* symbol in <unistd.h>.
* If it is not defined, then we use SELFCONF with the value of -1.
*/
/*
* XPG4 support ends
*/
/* XPG4, Version 2 support */
/*
* UNIX 98 - XPG5 additions
*/
_SC_SHARED_MEMORY_OBJECTS, "_POSIX_SHARED_MEMORY_OBJECTS",
_SC_THREAD_DESTRUCTOR_ITERATIONS, "PTHREAD_DESTRUCTOR_ITERATIONS",
_SC_THREAD_ATTR_STACKADDR, "POSIX_THREAD_ATTR_STACKADDR",
_SC_THREAD_ATTR_STACKADDR, "_POSIX_THREAD_ATTR_STACKADDR",
_SC_THREAD_ATTR_STACKSIZE, "POSIX_THREAD_ATTR_STACKSIZE",
_SC_THREAD_ATTR_STACKSIZE, "_POSIX_THREAD_ATTR_STACKSIZE",
_SC_THREAD_PRIORITY_SCHEDULING, "POSIX_THREAD_PRIORITY_SCHEDULING",
_SC_THREAD_PRIORITY_SCHEDULING, "_POSIX_THREAD_PRIORITY_SCHEDULING",
_SC_THREAD_PRIO_INHERIT, "POSIX_THREAD_PRIO_INHERIT",
_SC_THREAD_PRIO_INHERIT, "_POSIX_THREAD_PRIO_INHERIT",
_SC_THREAD_PRIO_PROTECT, "POSIX_THREAD_PRIO_PROTECT",
_SC_THREAD_PRIO_PROTECT, "_POSIX_THREAD_PRIO_PROTECT",
_SC_THREAD_PROCESS_SHARED, "POSIX_THREAD_PROCESS_SHARED",
_SC_THREAD_PROCESS_SHARED, "_POSIX_THREAD_PROCESS_SHARED",
_SC_THREAD_SAFE_FUNCTIONS, "POSIX_THREAD_SAFE_FUNCTIONS",
_SC_THREAD_SAFE_FUNCTIONS, "_POSIX_THREAD_SAFE_FUNCTIONS",
/*
* Due to ambiguity in the standard we need
* to recognize both the underscored name
* and the non-underscored version in the
* following variables.
*/
/*
* UNIX 03 additions for sysconf() names, and names that are not in interfaces
*/
/*
* Due to an ambiguity in the specification, we need to recognize both
* the underscored POSIX name and the non-underscored name. In addition,
* we need to permit the use of the _V6_* environment names specified
* in unistd.h.
*/
/*
* System V Interface Definition
*/
0, NULL, 0, 0 /* end of table */
};
/*
* Print usage message.
*/
static int
usage()
{
"usage:\tgetconf [-v specification] system_var\n"
"\tgetconf [-v specification] path_var pathname\n"
"\tgetconf -a\n"), stderr);
return (2);
}
static int
namecmp(const void *a, const void *b)
{
}
static int
{
register char *buffer;
long value;
case SELFCONF:
if (argc > 2)
return (usage());
/* DO NOT TRANSLATE */
(void) printf("undefined\n");
} else
else
break;
case SYSCONF:
if (argc > 2)
return (usage());
errno = 0;
return (1);
} else {
/* DO NOT TRANSLATE */
(void) printf("undefined\n");
return (0);
}
} else
break;
case CONFSTR:
if (argc > 2)
return (usage());
errno = 0;
if (len == 0) {
name);
return (1);
} else {
/* DO NOT TRANSLATE */
(void) printf("undefined\n");
return (0);
}
}
/*
* allocate space to store result of constr() into
*/
gettext("insufficient memory available"));
return (1);
}
break;
case PATHCONF:
if (argc != 3)
return (usage());
errno = 0;
/* Does not support the association */
/* DO NOT TRANSLATE */
(void) printf("undefined\n");
return (0);
} else {
/* Probably problems with the pathname itself */
if (aflag) {
} else {
}
return (1);
}
}
break;
}
return (0);
}
int
{
int c;
int exstat = 0;
#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
#endif
(void) textdomain(TEXT_DOMAIN);
switch (c) {
case 'a':
aflag = 1;
break;
case 'v':
/*
* Unix98 adds the -v option to allow
* programming 'specifications' to be
* indicated, for present purposes
* the specification isn't really
* doing anything of value, so for
* the moment getopt just processes the
* option value and argv[1] is adjusted.
*
* At some later date we might want to
* do specification processing at this
* point.
*/
break;
case '?':
return (usage());
}
return (usage());
if (aflag) {
/*
* sort the table by the "name" field
* so we print it in sorted order
*/
/*
* print all the known symbols and their values
*/
int stat;
/*
* create 2 columns:
* variable name in the left column,
* value in the right column.
* The right column starts at a tab stop.
*/
for (; c < RightColumn; c += TabStop)
(void) putchar('\t');
/*
* for pathconf() related variables that require
* a pathname, use "."
*/
/*
* if stat != 0, then an error message was already
* printed in getconf(),
* so don't need to print one here
*/
}
} else {
/*
* find the name of the specified variable (argv[1])
* and print its value.
*/
break;
}
/*
* if at last entry in table, then the user specified
* variable is invalid
*/
return (1);
}
}
return (exstat);
}