summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwollman <wollman@FreeBSD.org>2002-09-19 03:39:03 +0000
committerwollman <wollman@FreeBSD.org>2002-09-19 03:39:03 +0000
commitcb45d14fee8f6330b3fbc791aea9eaa571b019f9 (patch)
treeab1f0dc71db78e794da3665ed9b795e82d90c7aa
parenta059a58a99b6e22aecf174427806403adc8d6cf6 (diff)
downloadFreeBSD-src-cb45d14fee8f6330b3fbc791aea9eaa571b019f9.zip
FreeBSD-src-cb45d14fee8f6330b3fbc791aea9eaa571b019f9.tar.gz
Completely revamp the way getconf(1) works, for better adherence to the
intent of the Standard. - Make getconf able to distinguish between configuration variables which are entirely unknown and those which are merely not defined in the compilation environment. The latter now get a more appropriate "undefined\n" result rather than a diagnostic. This may not be exactly right, but it's closer to the intent of the Standard than the previous behavior. - Support ``programming environments'' by validating that the environment requested with the `-v' flag is the one-and-only execution environment. (If more environments are supported for some platforms in the future, multiple getconf(1) executables will be required, but a simple edit in progenv.gperf will enable automatic support for it.) Document POSIX standard programming environments. - Add all of the 1003.1-2001 configuration variables. FreeBSD does not support all of these (including some that are mandatory); getconf will later be fixed to break the world should a required variable not be defined. As a result of all these changes, gperf is no longer adequate. Keep the overall format and names of the files for now, to preserve revision history. Use an awk script to process the .gperf files into C source, which does a few things that gperf, as a more general tool, cannot do. The keyword recognition function is no longer a perfect hash function. This may obviate the need for gperf in the source tree. - Add a small compile-time regression test to break the build if any of the .gperf files declare conflicting token sets. (gperf itself would have done this for the simple case of duplicate tokens in the same input file.)
-rw-r--r--usr.bin/getconf/Makefile30
-rw-r--r--usr.bin/getconf/confstr.gperf32
-rw-r--r--usr.bin/getconf/fake-gperf.awk35
-rw-r--r--usr.bin/getconf/getconf.1103
-rw-r--r--usr.bin/getconf/getconf.c76
-rw-r--r--usr.bin/getconf/getconf.h9
-rw-r--r--usr.bin/getconf/limits.gperf118
-rw-r--r--usr.bin/getconf/pathconf.gperf27
-rw-r--r--usr.bin/getconf/progenv.gperf67
-rw-r--r--usr.bin/getconf/sysconf.gperf149
10 files changed, 457 insertions, 189 deletions
diff --git a/usr.bin/getconf/Makefile b/usr.bin/getconf/Makefile
index 23122b3..275b4f2 100644
--- a/usr.bin/getconf/Makefile
+++ b/usr.bin/getconf/Makefile
@@ -2,13 +2,35 @@
PROG= getconf
-SRCS= confstr.c getconf.c pathconf.c sysconf.c
+SRCS= confstr.c getconf.c limits.c pathconf.c progenv.c sysconf.c
CFLAGS+= -I${.CURDIR}
-CLEANFILES+= confstr.c pathconf.c sysconf.c
+CLEANFILES+= confstr.c limits.c pathconf.c progenv.c sysconf.c \
+ confstr.names limits.names pathconf.names sysconf.names \
+ conflicting.names unique.names
-.SUFFIXES: .gperf
+.SUFFIXES: .gperf .names
+.PHONY: conflicts
+
+all: conflicts
.gperf.c:
- gperf -t -L ANSI-C -C -k 1,2,7-10,21,'$$' ${.IMPSRC} >${.TARGET}
+ awk -f ${.CURDIR}/fake-gperf.awk ${.IMPSRC} >${.TARGET}
+
+.gperf.names:
+ awk '/^[_A-Z]/ { print; }' ${.IMPSRC} | sed -e 's/,$$//' >${.TARGET}
+
+conflicts: conflicting.names unique.names
+ @if test `wc -l <conflicting.names` != `wc -l <unique.names`; then \
+ echo "Name conflicts found!" >&2; \
+ exit 1; \
+ fi
+
+# pathconf.names is not included here because pathconf names are
+# syntactically distinct from the other kinds.
+conflicting.names: confstr.names limits.names sysconf.names
+ cat ${.ALLSRC} >${.TARGET}
+
+unique.names: conflicting.names
+ sort -u ${.ALLSRC} >${.TARGET}
.include <bsd.prog.mk>
diff --git a/usr.bin/getconf/confstr.gperf b/usr.bin/getconf/confstr.gperf
index ad2f509..14ad5f2 100644
--- a/usr.bin/getconf/confstr.gperf
+++ b/usr.bin/getconf/confstr.gperf
@@ -17,8 +17,13 @@
*/
static const struct map *in_word_set(const char *str, unsigned int len);
+/*
+ * The Standard seems a bit ambiguous over whether the POSIX_V6_*
+ * are specified with or without a leading underscore, so we just
+ * use both.
+ */
%}
-struct map { const char *name; int key; };
+struct map { const char *name; int key; int valid; };
%%
PATH, _CS_PATH
POSIX_V6_ILP32_OFF32_CFLAGS, _CS_POSIX_V6_ILP32_OFF32_CFLAGS
@@ -34,15 +39,32 @@ POSIX_V6_LPBIG_OFFBIG_CFLAGS, _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS
POSIX_V6_LPBIG_OFFBIG_LDFLAGS, _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS
POSIX_V6_LPBIG_OFFBIG_LIBS, _CS_POSIX_V6_LPBIG_OFFBIG_LIBS
POSIX_V6_WIDTH_RESTRICTED_ENVS, _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS
+_POSIX_V6_ILP32_OFF32_CFLAGS, _CS_POSIX_V6_ILP32_OFF32_CFLAGS
+_POSIX_V6_ILP32_OFF32_LDFLAGS, _CS_POSIX_V6_ILP32_OFF32_LDFLAGS
+_POSIX_V6_ILP32_OFF32_LIBS, _CS_POSIX_V6_ILP32_OFF32_LIBS
+_POSIX_V6_ILP32_OFFBIG_CFLAGS, _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS
+_POSIX_V6_ILP32_OFFBIG_LDFLAGS, _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS
+_POSIX_V6_ILP32_OFFBIG_LIBS, _CS_POSIX_V6_ILP32_OFFBIG_LIBS
+_POSIX_V6_LP64_OFF64_CFLAGS, _CS_POSIX_V6_LP64_OFF64_CFLAGS
+_POSIX_V6_LP64_OFF64_LDFLAGS, _CS_POSIX_V6_LP64_OFF64_LDFLAGS
+_POSIX_V6_LP64_OFF64_LIBS, _CS_POSIX_V6_LP64_OFF64_LIBS
+_POSIX_V6_LPBIG_OFFBIG_CFLAGS, _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS
+_POSIX_V6_LPBIG_OFFBIG_LDFLAGS, _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS
+_POSIX_V6_LPBIG_OFFBIG_LIBS, _CS_POSIX_V6_LPBIG_OFFBIG_LIBS
+_POSIX_V6_WIDTH_RESTRICTED_ENVS, _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS
%%
int
-find_confstr(const char *name)
+find_confstr(const char *name, int *key)
{
const struct map *rv;
rv = in_word_set(name, strlen(name));
- if (rv != 0)
- return rv->key;
- else
+ if (rv != NULL) {
+ if (rv->valid) {
+ *key = rv->key;
+ return 1;
+ }
return -1;
+ }
+ return 0;
}
diff --git a/usr.bin/getconf/fake-gperf.awk b/usr.bin/getconf/fake-gperf.awk
index bffa508..2705d6a 100644
--- a/usr.bin/getconf/fake-gperf.awk
+++ b/usr.bin/getconf/fake-gperf.awk
@@ -1,12 +1,8 @@
#!/usr/bin/awk -f
-#
-# This file is in the public domain. Written by Garrett A. Wollman,
-# 2002-09-17.
-#
# $FreeBSD$
-#
BEGIN {
state = 0;
+ struct_seen = "";
}
/^%{$/ && state == 0 {
state = 1;
@@ -17,25 +13,36 @@ BEGIN {
next;
}
state == 1 { print; next; }
+/^struct/ && state == 0 {
+ print;
+ struct_seen = $2;
+ next;
+}
/^%%$/ && state == 0 {
state = 2;
print "#include <stddef.h>";
print "#include <string.h>";
- print "static const struct map {";
- print "\tconst char *name;";
- print "\tint key;";
- print "} wordlist[] = {";
+ if (struct_seen !~ /^$/) {
+ print "static const struct", struct_seen, "wordlist[] = {";
+ } else {
+ print "static const struct map {";
+ print "\tconst char *name;";
+ print "\tint key;";
+ print "\tint valid;";
+ print "} wordlist[] = {";
+ struct_seen = "map";
+ }
next;
}
/^%%$/ && state == 2 {
state = 3;
print "\t{ NULL }";
print "};";
- print "#define\tNWORDS\t(sizeof(wordlist)/sizeof(wordlist[0]))";
+ print "#define\tNWORDS\t(sizeof(wordlist)/sizeof(wordlist[0]) - 1)";
print "static const struct map *";
print "in_word_set(const char *word, unsigned int len)";
print "{";
- print "\tconst struct map *mp;";
+ print "\tconst struct", struct_seen, "*mp;";
print "";
print "\tfor (mp = wordlist; mp < &wordlist[NWORDS]; mp++) {";
print "\t\tif (strcmp(word, mp->name) == 0)";
@@ -48,7 +55,11 @@ state == 1 { print; next; }
}
state == 2 && NF == 2 {
name = substr($1, 1, length($1) - 1);
- printf "\t{ \"%s\", %s },\n", name, $2;
+ printf "#ifdef %s\n", $2;
+ printf "\t{ \"%s\", %s, 1 },\n", name, $2;
+ print "#else";
+ printf "\t{ \"%s\", 0, 0 },\n", name, $2;
+ print "#endif"
next;
}
state == 3 { print; next; }
diff --git a/usr.bin/getconf/getconf.1 b/usr.bin/getconf/getconf.1
index c69f625..f98d6e8 100644
--- a/usr.bin/getconf/getconf.1
+++ b/usr.bin/getconf/getconf.1
@@ -28,7 +28,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd April 25, 2000
+.Dd September 18, 2002
.Dt GETCONF 1
.Os
.Sh NAME
@@ -65,8 +65,14 @@ configuration variables using
and
.Xr sysconf 3 ,
depending on the type of variable.
+As an extension, the second form can also be used to query static limits from
+.Aq Pa limits.h .
.Pp
-All variables use the same name as the manifest constants defined in
+All
+.Xr sysconf 3
+and
+.Xr pathconf 2
+variables use the same name as the manifest constants defined in
the relevant standard C-language bindings, including any leading
underscore or prefix.
That is to say,
@@ -81,33 +87,82 @@ names
.Dv _SC_ARG_MAX
or
.Dv _SC_POSIX_VERSION .
-(There is one exception: there is no corresponding manifest constant
-to
-.Dv _CS_PATH ,
-so a
+Variables retrieved from
+.Xr confstr 3
+have the leading
+.Ql _CS_
+stripped off; thus,
+.Dv _CS_PATH
+is queried by a
.Ar system_var
of
-.Dq Li PATH
-is used.)
-.Pp
+.Dq Li PATH .
+.Ss Programming Environments
The
.Fl v Ar environment
-option is not supported, but provided for compatibility purposes.
+option specifies a
+.St -p1003.1-2001
+programming environment under which the values are to be queried.
+This option currently does nothing, but may in the future be used
+to select between 32-bit and 64-bit execution environments on platforms
+which support both.
+Specifying an environment which is not supported on the current execution
+platform gives undefined results.
+.Pp
+The standard programming environments are as follows:
+.Bl -tag -width ".Li POSIX_V6_LPBIG_OFFBIG" -offset indent
+.It Li POSIX_V6_ILP32_OFF32
+Exactly 32-bit integer, long, pointer, and file offset.
+.Sy Supported platforms :
+None.
+.It Li POSIX_V6_ILP32_OFFBIG
+Exactly 32-bit integer, long, and pointer; at least 64-bit file offset.
+.Sy Supported platforms :
+.Tn IA32 ,
+.Tn PowerPC .
+.It Li POSIX_V6_LP64_OFF64
+Exactly 32-bit integer; exactly 64-bit long, pointer, and file offset.
+.Sy Supported platforms :
+.Tn Alpha ,
+.Tn SPARC64 .
+.It Li POSIX_V6_LPBIG_OFFBIG
+At least 32-bit integer; at least 64-bit long, pointer, and file offset.
+.Sy Supported platforms :
+None.
+.El
+.Pp
+The command:
+.Bd -literal -offset indent
+getconf POSIX_V6_WIDTH_RESTRICTED_ENVS
+.Ed
+.Pp
+returns a newline-separated list of environments in which the width
+of certain fundamental types is no greater than the width of the native
+C type
+.Ql long .
+At present, all programming environments supported by
+.Fx
+have this property.
+Several of the
+.Xr confstr 3
+variables provide information on the necessary compiler and linker flags
+to use the standard programming environments described above.
.Sh DIAGNOSTICS
.Ex -std
Use of a
.Ar system_var
or
.Ar path_var
-which is completely unknown to the system is considered an error,
-causing a diagnostic message to be written to standard error; one
+which is completely unrecognized is considered an error,
+causing a diagnostic message to be written to standard error.
+One
which is known but merely undefined does not result in an error
indication.
-.Pp
-Use of the unsupported
-.Fl v Ar environment
-option will result in a diagnostic message indicating that it is not
-supported.
+The
+.Nm
+command recognizes all of the variables defined for
+.St -p1003.1-2001 ,
+including those which are not currently implemented.
.Sh EXAMPLES
The command:
.Bd -literal -offset indent
@@ -126,6 +181,18 @@ getconf NAME_MAX /tmp
will display the maximum length of a filename in the
.Pa /tmp
directory.
+.Pp
+The command:
+.Bd -literal -offset indent
+getconf -v POSIX_V6_LPBIG_OFFBIG LONG_MAX
+.Ed
+.Pp
+will display the maximum value of the C type
+.Ql long
+in the
+.Li POSIX_V6_LPBIG_OFFBIG
+programming environment,
+if the system supports that environment.
.Sh SEE ALSO
.Xr pathconf 2 ,
.Xr confstr 3 ,
@@ -134,7 +201,7 @@ directory.
The
.Nm
utility is expected to be compliant with
-.St -susv2 .
+.St -p1003.1-2001 .
.Sh HISTORY
The
.Nm
diff --git a/usr.bin/getconf/getconf.c b/usr.bin/getconf/getconf.c
index fba5bf1..1e991b6 100644
--- a/usr.bin/getconf/getconf.c
+++ b/usr.bin/getconf/getconf.c
@@ -49,20 +49,19 @@ static void
usage(void)
{
fprintf(stderr, "usage:\n"
- "\tgetconf [-v prog_model] system_var\n"
- "\tgetconf [-v prog_model] path_var pathname\n");
+ "\tgetconf [-v prog_env] system_var\n"
+ "\tgetconf [-v prog_env] path_var pathname\n");
exit(EX_USAGE);
}
int
main(int argc, char **argv)
{
- int c;
- const char *name, *vflag;
- int key;
-
- vflag = 0;
+ int c, key, valid;
+ const char *name, *vflag, *alt_path;
+ intmax_t limitval;
+ vflag = NULL;
while ((c = getopt(argc, argv, "v:")) != -1) {
switch (c) {
case 'v':
@@ -74,31 +73,61 @@ main(int argc, char **argv)
}
}
- if (vflag)
- warnx("-v %s ignored", vflag);
-
- /* No arguments... */
- if ((name = argv[optind]) == 0)
+ if ((name = argv[optind]) == NULL)
usage();
- if (argv[optind + 1] == 0) { /* confstr or sysconf */
- key = find_confstr(name);
- if (key >= 0) {
- do_confstr(name, key);
+ if (vflag != NULL) {
+ if ((valid = find_progenv(vflag, &alt_path)) == 0)
+ errx(EX_USAGE, "invalid programming environment %s",
+ vflag);
+ if (valid > 0 && alt_path != NULL) {
+ if (argv[optind + 1] == NULL)
+ execl(alt_path, "getconf", argv[optind],
+ (char *)NULL);
+ else
+ execl(alt_path, "getconf", argv[optind],
+ argv[optind + 1], (char *)NULL);
+
+ err(EX_OSERR, "execl: %s", alt_path);
+ }
+ if (valid < 0)
+ errx(EX_UNAVAILABLE, "environment %s is not available",
+ vflag);
+ }
+
+ if (argv[optind + 1] == NULL) { /* confstr or sysconf */
+ if ((valid = find_limit(name, &limitval)) != 0) {
+ if (valid > 0)
+ printf("%jd\n", limitval);
+ else
+ printf("undefined\n");
+
+ return 0;
+ }
+ if ((valid = find_confstr(name, &key)) != 0) {
+ if (valid > 0)
+ do_confstr(name, key);
+ else
+ printf("undefined\n");
} else {
- key = find_sysconf(name);
- if (key >= 0)
+ valid = find_sysconf(name, &key);
+ if (valid > 0) {
do_sysconf(name, key);
- else
+ } else if (valid < 0) {
+ printf("undefined\n");
+ } else
errx(EX_USAGE,
"no such configuration parameter `%s'",
name);
}
} else {
- key = find_pathconf(name);
- if (key >= 0)
- do_pathconf(name, key, argv[optind + 1]);
- else
+ valid = find_pathconf(name, &key);
+ if (valid != 0) {
+ if (valid > 0)
+ do_pathconf(name, key, argv[optind + 1]);
+ else
+ printf("undefined\n");
+ } else
errx(EX_USAGE,
"no such path configuration parameter `%s'",
name);
@@ -154,3 +183,4 @@ do_pathconf(const char *name, int key, const char *path)
else
printf("%ld\n", value);
}
+
diff --git a/usr.bin/getconf/getconf.h b/usr.bin/getconf/getconf.h
index 0cb13c4..60d10d2 100644
--- a/usr.bin/getconf/getconf.h
+++ b/usr.bin/getconf/getconf.h
@@ -29,7 +29,10 @@
* $FreeBSD$
*/
-int find_confstr(const char *name);
-int find_sysconf(const char *name);
-int find_pathconf(const char *name);
+#include <stdint.h>
+int find_confstr(const char *name, int *key);
+int find_limit(const char *name, intmax_t *value);
+int find_pathconf(const char *name, int *key);
+int find_progenv(const char *name, const char **alt_path);
+int find_sysconf(const char *name, int *key);
diff --git a/usr.bin/getconf/limits.gperf b/usr.bin/getconf/limits.gperf
new file mode 100644
index 0000000..bb8ef0d
--- /dev/null
+++ b/usr.bin/getconf/limits.gperf
@@ -0,0 +1,118 @@
+%{
+/*
+ * Copyright is disclaimed as to the contents of this file.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/types.h>
+
+#include <string.h>
+#include <limits.h>
+
+#include "getconf.h"
+
+/*
+ * Override gperf's built-in external scope.
+ */
+static const struct map *in_word_set(const char *str, unsigned int len);
+
+%}
+struct map { const char *name; intmax_t value; int valid; };
+%%
+_POSIX_CLOCKRES_MIN, _POSIX_CLOCKRES_MIN
+_POSIX_AIO_LISTIO_MAX, _POSIX_AIO_LISTIO_MAX
+_POSIX_AIO_MAX, _POSIX_AIO_MAX
+_POSIX_ARG_MAX, _POSIX_ARG_MAX
+_POSIX_CHILD_MAX, _POSIX_CHILD_MAX
+_POSIX_DELAYTIMER_MAX, _POSIX_DELAYTIMER_MAX
+_POSIX_HOST_NAME_MAX, _POSIX_HOST_NAME_MAX
+_POSIX_LINK_MAX, _POSIX_LINK_MAX
+_POSIX_LOGIN_NAME_MAX, _POSIX_LOGIN_NAME_MAX
+_POSIX_MAX_CANON, _POSIX_MAX_CANON
+_POSIX_MAX_INPUT, _POSIX_MAX_INPUT
+_POSIX_MQ_OPEN_MAX, _POSIX_MQ_OPEN_MAX
+_POSIX_MQ_PRIO_MAX, _POSIX_MQ_PRIO_MAX
+_POSIX_NAME_MAX, _POSIX_NAME_MAX
+_POSIX_NGROUPS_MAX, _POSIX_NGROUPS_MAX
+_POSIX_OPEN_MAX, _POSIX_OPEN_MAX
+_POSIX_PATH_MAX, _POSIX_PATH_MAX
+_POSIX_PIPE_BUF, __POSIX_PIPE_BUF
+_POSIX_RE_DUP_MAX, _POSIX_RE_DUP_MAX
+_POSIX_RTSIG_MAX, _POSIX_RTSIG_MAX
+_POSIX_SEM_NSEMS_MAX, _POSIX_SEM_NSEMS_MAX
+_POSIX_SEM_VALUE_MAX, _POSIX_SEM_VALUE_MAX
+_POSIX_SIGQUEUE_MAX, _POSIX_SIGQUEUE_MAX
+_POSIX_SSIZE_MAX, _POSIX_SSIZE_MAX
+_POSIX_STREAM_MAX, _POSIX_STREAM_MAX
+_POSIX_SS_REPL_MAX, _POSIX_SS_REPL_MAX
+_POSIX_SYMLINK_MAX, _POSIX_SYMLINK_MAX
+_POSIX_SYMLOOP_MAX, _POSIX_SYMLOOP_MAX
+_POSIX_THREAD_DESTRUCTOR_ITERATIONS, _POSIX_THREAD_DESTRUCTOR_ITERATIONS
+_POSIX_THREAD_KEYS_MAX, _POSIX_THREAD_KEYS_MAX
+_POSIX_THREAD_THREADS_MAX, _POSIX_THREAD_THREADS_MAX
+_POSIX_TIMER_MAX, _POSIX_TIMER_MAX
+_POSIX_TRACE_EVENT_NAME_MAX, _POSIX_TRACE_EVENT_NAME_MAX
+_POSIX_TRACE_NAME_MAX, _POSIX_TRACE_NAME_MAX
+_POSIX_TRACE_SYS_MAX, _POSIX_TRACE_SYS_MAX
+_POSIX_TRACE_USER_EVENT_MAX, _POSIX_TRACE_USER_EVENT_MAX
+_POSIX_TTY_NAME_MAX, _POSIX_TTY_NAME_MAX
+_POSIX_TZNAME_MAX, _POSIX_TZNAME_MAX
+_POSIX2_BC_BASE_MAX, _POSIX2_BC_BASE_MAX
+_POSIX2_BC_DIM_MAX, _POSIX2_BC_DIM_MAX
+_POSIX2_BC_SCALE_MAX, _POSIX2_BC_SCALE_MAX
+_POSIX2_BC_STRING_MAX, _POSIX2_BC_STRING_MAX
+_POSIX2_CHARCLASS_NAME_MAX, _POSIX2_CHARCLASS_NAME_MAX
+_POSIX2_COLL_WEIGHTS_MAX, _POSIX2_COLL_WEIGHTS_MAX
+_POSIX2_EXPR_NEXT_MAX, _POSIX2_EXPR_NEST_MAX
+_POSIX2_LINE_MAX, _POSIX2_LINE_MAX
+_POSIX2_RE_DUP_MAX, _POSIX2_RE_DUP_MAX
+_XOPEN_IOV_MAX, _XOPEN_IOV_MAX
+_XOPEN_NAME_MAX, _XOPEN_NAME_MAX
+_XOPEN_PATH_MAX, _XOPEN_PATH_MAX
+CHAR_BIT, CHAR_BIT
+CHAR_MAX, CHAR_MAX
+CHAR_MIN, CHAR_MIN
+INT_MAX, INT_MAX
+INT_MIN, INT_MIN
+LLONG_MIN, LLONG_MIN
+LLONG_MAX, LLONG_MAX
+LONG_BIT, LONG_BIT
+LONG_MAX, LONG_MAX
+LONG_MIN, LONG_MIN
+MB_LEN_MAX, MB_LEN_MAX
+SCHAR_MAX, SCHAR_MAX
+SCHAR_MIN, SCHAR_MIN
+SHRT_MAX, SHRT_MAX
+SHRT_MIN, SHRT_MIN
+SSIZE_MAX, SSIZE_MAX
+UCHAR_MAX, UCHAR_MAX
+UINT_MAX, UINT_MAX
+ULLONG_MAX, ULLONG_MAX
+ULONG_MAX, ULONG_MAX
+USHRT_MAX, USHRT_MAX
+WORD_BIT, WORD_BIT
+CHARCLASS_NAME_MAX, CHARCLASS_NAME_MAX
+NL_ARGMAX, NL_ARGMAX
+ML_LANGMAX, NL_LANGMAX
+NL_MSGMAX, NL_MSGMAX
+NL_NMAX, NL_NMAX
+NL_SETMAX, NL_SETMAX
+NL_TEXTMAX, NL_TEXTMAX
+NZERO, NZERO
+%%
+int
+find_limit(const char *name, intmax_t *value)
+{
+ const struct map *rv;
+
+ rv = in_word_set(name, strlen(name));
+ if (rv != NULL) {
+ if (rv->valid) {
+ *value = rv->value;
+ return 1;
+ }
+ return -1;
+ }
+ return 0;
+}
diff --git a/usr.bin/getconf/pathconf.gperf b/usr.bin/getconf/pathconf.gperf
index 17ca458..b44e824 100644
--- a/usr.bin/getconf/pathconf.gperf
+++ b/usr.bin/getconf/pathconf.gperf
@@ -14,20 +14,12 @@
#include "getconf.h"
/*
- * Stuff that isn't defined right now -- we want this file to work
- * unmodified once it is defined.
- */
-#ifndef _PC_FILESIZEBITS
-#define _PC_FILESIZEBITS -1
-#endif
-
-/*
* Override gperf's built-in external scope.
*/
static const struct map *in_word_set(const char *str, unsigned int len);
%}
-struct map { char *name; int key; };
+struct map { char *name; int key; int valid; };
%%
FILESIZEBITS, _PC_FILESIZEBITS
LINK_MAX, _PC_LINK_MAX
@@ -36,6 +28,11 @@ MAX_INPUT, _PC_MAX_INPUT
NAME_MAX, _PC_NAME_MAX
PATH_MAX, _PC_PATH_MAX
PIPE_BUF, _PC_PIPE_BUF
+POSIX_ALLOC_SIZE_MIN, _PC_ALLOC_SIZE_MIN
+POSIX_REC_INCR_XFER_SIZE, _PC_REC_INCR_XFER_SIZE
+POSIX_REC_MAX_XFER_SIZE, _PC_REC_MAX_XFER_SIZE
+POSIX_REC_MIN_XFER_SIZE, _PC_REC_MIN_XFER_SIZE
+POSIX_REC_XFER_ALIGN, _PC_REC_XFER_ALIGN
_POSIX_CHOWN_RESTRICTED, _PC_CHOWN_RESTRICTED
_POSIX_NO_TRUNC, _PC_NO_TRUNC
_POSIX_VDISABLE, _PC_VDISABLE
@@ -44,13 +41,17 @@ _POSIX_PRIO_IO, _PC_PRIO_IO
_POSIX_SYNC_IO, _PC_SYNC_IO
%%
int
-find_pathconf(const char *name)
+find_pathconf(const char *name, int *key)
{
const struct map *rv;
rv = in_word_set(name, strlen(name));
- if (rv != 0)
- return rv->key;
- else
+ if (rv != NULL) {
+ if (rv->valid) {
+ *key = rv->key;
+ return 1;
+ }
return -1;
+ }
+ return 0;
}
diff --git a/usr.bin/getconf/progenv.gperf b/usr.bin/getconf/progenv.gperf
new file mode 100644
index 0000000..64c9b4c
--- /dev/null
+++ b/usr.bin/getconf/progenv.gperf
@@ -0,0 +1,67 @@
+%{
+/*
+ * Copyright is disclaimed as to the contents of this file.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/types.h>
+
+#include <string.h>
+#include <unistd.h>
+
+#include "getconf.h"
+
+/*
+ * Override gperf's built-in external scope.
+ */
+static const struct map *in_word_set(const char *str, unsigned int len);
+
+/*
+ * The Standard seems a bit ambiguous over whether the POSIX_V6_*
+ * are specified with or without a leading underscore, so we just
+ * use both.
+ */
+/*
+ * The alt_path member gives the path containing another `getconf'
+ * executable which was compiled using the specified programming
+ * environment. If it is NULL, the current executable is good enough.
+ * If we ever support multiple environments, this table will need to
+ * be updated. (We cheat here and define the supported environments
+ * statically.)
+ */
+#if defined(__alpha__) || defined(__sparc64__)
+#define have_LP64_OFF64 NULL
+#endif
+
+#if defined(__i386__) || defined(__powerpc__)
+#define have_ILP32_OFFBIG NULL
+#endif
+
+%}
+struct map { const char *name; const char *alt_path; int valid; };
+%%
+POSIX_V6_ILP32_OFF32, notdef
+POSIX_V6_ILP32_OFFBIG, have_ILP32_OFFBIG
+POSIX_V6_LP64_OFF64, have_LP64_OFF64
+POSIX_V6_LPBIG_OFFBIG, notdef
+_POSIX_V6_ILP32_OFF32, notdef
+_POSIX_V6_ILP32_OFFBIG, have_ILP32_OFFBIG
+_POSIX_V6_LP64_OFF64, have_LP64_OFF64
+_POSIX_V6_LPBIG_OFFBIG, notdef
+%%
+int
+find_progenv(const char *name, const char **alt_path)
+{
+ const struct map *rv;
+
+ rv = in_word_set(name, strlen(name));
+ if (rv != NULL) {
+ if (rv->valid) {
+ *alt_path = rv->alt_path;
+ return 1;
+ }
+ return -1;
+ }
+ return 0;
+}
diff --git a/usr.bin/getconf/sysconf.gperf b/usr.bin/getconf/sysconf.gperf
index b917000..5467d11 100644
--- a/usr.bin/getconf/sysconf.gperf
+++ b/usr.bin/getconf/sysconf.gperf
@@ -14,113 +14,12 @@
#include "getconf.h"
/*
- * Stuff that isn't defined right now -- we want this file to work
- * unmodified once it is defined.
- */
-#ifndef _SC_ATEXIT_MAX
-#define _SC_ATEXIT_MAX -1
-#endif
-#ifndef _SC_TTY_NAME_MAX
-#define _SC_TTY_NAME_MAX -1
-#endif
-#ifndef _SC_MQ_PRIO_MAX
-#define _SC_MQ_PRIO_MAX -1
-#endif
-#ifndef _SC_IOV_MAX
-#define _SC_IOV_MAX -1
-#endif
-#ifndef _SC_XOPEN_REALTIME
-#define _SC_XOPEN_REALTIME -1
-#endif
-#ifndef _SC_XOPEN_LEGACY
-#define _SC_XOPEN_LEGACY -1
-#endif
-#ifndef _SC_XCU_VERSION
-#define _SC_XCU_VERSION -1
-#endif
-#ifndef _SC_PASS_MAX
-#define _SC_PASS_MAX -1
-#endif
-#ifndef _SC_XOPEN_REALTIME_THREADS
-#define _SC_XOPEN_REALTIME_THREADS -1
-#endif
-#ifndef _SC_LOGIN_NAME_MAX
-#define _SC_LOGIN_NAME_MAX -1
-#endif
-#ifndef _SC_XBS5_LP64_OFF64
-#define _SC_XBS5_LP64_OFF64 -1
-#endif
-#ifndef _SC_XOPEN_SHM
-#define _SC_XOPEN_SHM -1
-#endif
-#ifndef _SC_XOPEN_CRYPT
-#define _SC_XOPEN_CRYPT -1
-#endif
-#ifndef _SC_XOPEN_UNIX
-#define _SC_XOPEN_UNIX -1
-#endif
-#ifndef _SC_XOPEN_VERSION
-#define _SC_XOPEN_VERSION -1
-#endif
-#ifndef _SC_THREAD_DESTRUCTOR_ITERATIONS
-#define _SC_THREAD_DESTRUCTOR_ITERATIONS -1
-#endif
-#ifndef _SC_THREAD_KEYS_MAX
-#define _SC_THREAD_KEYS_MAX -1
-#endif
-#ifndef _SC_2_C_VERSION
-#define _SC_2_C_VERSION -1
-#endif
-#ifndef _SC_XBS5_LPBIG_OFFBIG
-#define _SC_XBS5_LPBIG_OFFBIG -1
-#endif
-#ifndef _SC_THREAD_THREADS_MAX
-#define _SC_THREAD_THREADS_MAX -1
-#endif
-#ifndef _SC_XBS5_ILP32_OFF32
-#define _SC_XBS5_ILP32_OFF32 -1
-#endif
-#ifndef _SC_XBS5_ILP32_OFFBIG
-#define _SC_XBS5_ILP32_OFFBIG -1
-#endif
-#ifndef _SC_THREAD_STACK_MIN
-#define _SC_THREAD_STACK_MIN -1
-#endif
-#ifndef _SC_XOPEN_ENH_I18N
-#define _SC_XOPEN_ENH_I18N -1
-#endif
-#ifndef _SC_THREAD_ATTR_STACKSIZE
-#define _SC_THREAD_ATTR_STACKSIZE -1
-#endif
-#ifndef _SC_THREAD_PRIORITY_SCHEDULING
-#define _SC_THREAD_PRIORITY_SCHEDULING -1
-#endif
-#ifndef _SC_THREADS
-#define _SC_THREADS -1
-#endif
-#ifndef _SC_THREAD_PROCESS_SHARED
-#define _SC_THREAD_PROCESS_SHARED -1
-#endif
-#ifndef _SC_THREAD_SAFE_FUNCTIONS
-#define _SC_THREAD_SAFE_FUNCTIONS -1
-#endif
-#ifndef _SC_THREAD_PRIO_PROTECT
-#define _SC_THREAD_PRIO_PROTECT -1
-#endif
-#ifndef _SC_THREAD_ATTR_STACKADDR
-#define _SC_THREAD_ATTR_STACKADDR -1
-#endif
-#ifndef _SC_THREAD_PRIO_INHERIT
-#define _SC_THREAD_PRIO_INHERIT -1
-#endif
-
-/*
* Override gperf's built-in external scope.
*/
static const struct map *in_word_set(const char *str, unsigned int len);
%}
-struct map { const char *name; int key; };
+struct map { const char *name; int key; int valid; };
%%
AIO_LISTIO_MAX, _SC_AIO_LISTIO_MAX
AIO_MAX, _SC_AIO_MAX
@@ -136,12 +35,17 @@ CLK_TCK, _SC_CLK_TCK
COLL_WEIGHTS_MAX, _SC_COLL_WEIGHTS_MAX
DELAYTIMER_MAX, _SC_DELAYTIMER_MAX
EXPR_NEST_MAX, _SC_EXPR_NEST_MAX
+GETGR_R_SIZE_MAX, _SC_GETGR_R_SIZE_MAX
+GETPW_R_SIZE_MAX, _SC_GETPW_R_SIZE_MAX
+HOST_NAME_MAX, _SC_HOST_NAME_MAX
IOV_MAX, _SC_IOV_MAX
LINE_MAX, _SC_LINE_MAX
LOGIN_NAME_MAX, _SC_LOGIN_NAME_MAX
MQ_OPEN_MAX, _SC_MQ_OPEN_MAX
MQ_PRIO_MAX, _SC_MQ_PRIO_MAX
NGROUPS_MAX, _SC_NGROUPS_MAX
+NPROCESSORS_CONF, _SC_NPROCESSORS_CONF
+NPROCESSORS_ONLN, _SC_NPROCESSORS_ONLN
OPEN_MAX, _SC_OPEN_MAX
PAGESIZE, _SC_PAGESIZE
PAGE_SIZE, _SC_PAGESIZE
@@ -170,6 +74,10 @@ _POSIX2_SW_DEV, _SC_2_SW_DEV
_POSIX2_UPE, _SC_2_UPE
_POSIX2_VERSION, _SC_2_VERSION
_POSIX_ASYNCHRONOUS_IO, _SC_ASYNCHRONOUS_IO
+_POSIX_BARRIERS, _SC_BARRIERS
+_POSIX_CLOCK_SELECTION, _SC_CLOCK_SELECTION
+_POSIX_CPUTIME, _SC_CPUTIME
+_POSIX_FILE_LOCKING, _SC_FILE_LOCKING
_POSIX_FSYNC, _SC_FSYNC
_POSIX_JOB_CONTROL, _SC_JOB_CONTROL
_POSIX_MAPPED_FILES, _SC_MAPPED_FILES
@@ -177,27 +85,42 @@ _POSIX_MEMLOCK, _SC_MEMLOCK
_POSIX_MEMLOCK_RANGE, _SC_MEMLOCK_RANGE
_POSIX_MEMORY_PROTECTION, _SC_MEMORY_PROTECTION
_POSIX_MESSAGE_PASSING, _SC_MESSAGE_PASSING
+_POSIX_MONOTONIC_CLOCK, _SC_MONOTONIC_CLOCK
_POSIX_PRIORITIZED_IO, _SC_PRIORITIZED_IO
_POSIX_PRIORITY_SCHEDULING, _SC_PRIORITY_SCHEDULING
+_POSIX_READER_WRITER_LOCKS, _SC_READER_WRITER_LOCKS
_POSIX_REALTIME_SIGNALS, _SC_REALTIME_SIGNALS
+_POSIX_REGEXP, _SC_REGEXP
_POSIX_SAVED_IDS, _SC_SAVED_IDS
_POSIX_SEMAPHORES, _SC_SEMAPHORES
_POSIX_SHARED_MEMORY_OBJECTS, _SC_SHARED_MEMORY_OBJECTS
+_POSIX_SHELL, _SC_SHELL
+_POSIX_SPAWN, _SC_SPAWN
+_POSIX_SPIN_LOCKS, _SC_SPIN_LOCKS
+_POSIX_SPORADIC_SERVER, _SC_SPORADIC_SERVER
_POSIX_SYNCHRONIZED_IO, _SC_SYNCHRONIZED_IO
_POSIX_THREADS, _SC_THREADS
_POSIX_THREAD_ATTR_STACKADDR, _SC_THREAD_ATTR_STACKADDR
_POSIX_THREAD_ATTR_STACKSIZE, _SC_THREAD_ATTR_STACKSIZE
+_POSIX_THREAD_CPUTIME, _SC_THREAD_CPUTIME
_POSIX_THREAD_PRIORITY_SCHEDULING, _SC_THREAD_PRIORITY_SCHEDULING
_POSIX_THREAD_PRIO_INHERIT, _SC_THREAD_PRIO_INHERIT
_POSIX_THREAD_PRIO_PROTECT, _SC_THREAD_PRIO_PROTECT
_POSIX_THREAD_PROCESS_SHARED, _SC_THREAD_PROCESS_SHARED
-_POSIX_THREAD_SAFE_FUNCTIONS, _SC_THREAD_SAFE_FUNCTIONS
+_POSIX_THREAD_SAFE_FUNCTIONS, _SC_THREAD_SAFE_FUNCTIONS
+_POSIX_THREAD_SPORADIC_SERVER, _SC_THREAD_SPORADIC_SERVER
+_POSIX_TIMEOUTS, _SC_TIMEOUTS
+_POSIX_TRACE, _SC_TRACE
+_POSIX_TRACE_EVENT_FILTER, _SC_TRACE_EVENT_FILTER
+_POSIX_TRACE_INHERIT, _SC_TRACE_INHERIT
+_POSIX_TRACE_LOG, _SC_TRACE_LOG
_POSIX_TIMERS, _SC_TIMERS
+_POSIX_TYPED_MEMORY_OBJECTS, _SC_TYPED_MEMORY_OBJECTS
_POSIX_VERSION, _SC_VERSION
-_XBS5_ILP32_OFF32, _SC_XBS5_ILP32_OFF32
-_XBS5_ILP32_OFFBIG, _SC_XBS5_ILP32_OFFBIG
-_XBS5_LP64_OFF64, _SC_XBS5_LP64_OFF64
-_XBS5_LPBIG_OFFBIG, _SC_XBS5_LPBIG_OFFBIG
+_POSIX_V6_ILP32_OFF32, _SC_V6_ILP32_OFF32
+_POSIX_V6_ILP32_OFFBIG, _SC_V6_ILP32_OFFBIG
+_POSIX_V6_LP64_OFF64, _SC_V6_LP64_OFF64
+_POSIX_V6_LP64_OFFBIG, _SC_V6_LP64_OFFBIG
_XOPEN_CRYPT, _SC_XOPEN_CRYPT
_XOPEN_ENH_I18N, _SC_XOPEN_ENH_I18N
_XOPEN_LEGACY, _SC_XOPEN_LEGACY
@@ -209,13 +132,17 @@ _XOPEN_VERSION, _SC_XOPEN_VERSION
_XOPEN_XCU_VERSION, _SC_XCU_VERSION
%%
int
-find_sysconf(const char *name)
+find_sysconf(const char *name, int *key)
{
const struct map *rv;
rv = in_word_set(name, strlen(name));
- if (rv != 0)
- return rv->key;
- else
+ if (rv != NULL) {
+ if (rv->valid) {
+ *key = rv->key;
+ return 1;
+ }
return -1;
+ }
+ return 0;
}
OpenPOWER on IntegriCloud