diff --git a/src/bin/Jamfile b/src/bin/Jamfile index 69357ca3fb..5a8595ff49 100644 --- a/src/bin/Jamfile +++ b/src/bin/Jamfile @@ -265,6 +265,7 @@ SubInclude HAIKU_TOP src bin findutils ; SubInclude HAIKU_TOP src bin fwcontrol ; SubInclude HAIKU_TOP src bin gawk ; SubInclude HAIKU_TOP src bin gdb ; +SubInclude HAIKU_TOP src bin getconf ; SubInclude HAIKU_TOP src bin hid_decode ; SubInclude HAIKU_TOP src bin ideinfo ; SubInclude HAIKU_TOP src bin keymap ; diff --git a/src/bin/getconf/Jamfile b/src/bin/getconf/Jamfile new file mode 100644 index 0000000000..128dbf6f02 --- /dev/null +++ b/src/bin/getconf/Jamfile @@ -0,0 +1,37 @@ +SubDir HAIKU_TOP src bin getconf ; + +UseHeaders [ FDirName $(HAIKU_TOP) headers compatibility bsd ] : true ; + +rule GetConfKeysGen +{ + SEARCH on $(2) = $(SEARCH_SOURCE) ; + SEARCH on $(3) = $(SEARCH_SOURCE) ; + + Depends $(1) : $(2) $(3) ; + MakeLocateArch $(<) ; + GetConfKeysGen1 $(1) : $(2) $(3) ; + LocalClean clean : $(<) ; +} + +actions GetConfKeysGen1 +{ + LC_ALL=C gawk -f $(2[2]) $(2[1]) > $(1) +} + +GetConfKeysGen [ FGristFiles confstr.c ] : confstr.gperf : fake-gperf.awk ; +GetConfKeysGen [ FGristFiles limits.c ] : limits.gperf : fake-gperf.awk ; +GetConfKeysGen [ FGristFiles pathconf.c ] : pathconf.gperf : fake-gperf.awk ; +GetConfKeysGen [ FGristFiles progenv.c ] : progenv.gperf : fake-gperf.awk ; +GetConfKeysGen [ FGristFiles sysconf.c ] : sysconf.gperf : fake-gperf.awk ; + +BinCommand getconf : + getconf.c + confstr.c + limits.c + pathconf.c + progenv.c + sysconf.c + : libbsd.so + ; + + diff --git a/src/bin/getconf/Makefile b/src/bin/getconf/Makefile new file mode 100644 index 0000000000..eaaf628aad --- /dev/null +++ b/src/bin/getconf/Makefile @@ -0,0 +1,37 @@ +# $FreeBSD$ + +PROG= getconf + +SRCS= confstr.c getconf.c limits.c pathconf.c progenv.c sysconf.c +CFLAGS+= -I${.CURDIR} +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 .names +.PHONY: conflicts + +all: conflicts + +.gperf.c: + LC_ALL=C awk -f ${.CURDIR}/fake-gperf.awk ${.IMPSRC} >${.TARGET} + +.gperf.names: + LC_ALL=C awk '/^[_A-Z]/ { print; }' ${.IMPSRC} | \ + sed -e 's/,$$//' >${.TARGET} + +conflicts: conflicting.names unique.names + @if test `wc -l &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 + LC_ALL=C sort -u ${.ALLSRC} >${.TARGET} + +.include diff --git a/src/bin/getconf/confstr.gperf b/src/bin/getconf/confstr.gperf new file mode 100644 index 0000000000..c629987e5c --- /dev/null +++ b/src/bin/getconf/confstr.gperf @@ -0,0 +1,70 @@ +%{ +/* + * Copyright is disclaimed as to the contents of this file. + * + * $FreeBSD$ + */ + +#include + +#include +#include + +#include "getconf.h" + +/* + * Override gperf's built-in external scope. + */ +static const struct map *in_word_set(const char *str); + +/* + * 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; int valid; }; +%% +PATH, _CS_PATH +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 +_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, int *key) +{ + const struct map *rv; + + rv = in_word_set(name); + if (rv != NULL) { + if (rv->valid) { + *key = rv->key; + return 1; + } + return -1; + } + return 0; +} diff --git a/src/bin/getconf/fake-gperf.awk b/src/bin/getconf/fake-gperf.awk new file mode 100644 index 0000000000..96fcd3c997 --- /dev/null +++ b/src/bin/getconf/fake-gperf.awk @@ -0,0 +1,66 @@ +#!/usr/bin/awk -f +# $FreeBSD$ +BEGIN { + state = 0; + struct_seen = ""; +} +/^%{$/ && state == 0 { + state = 1; + next; +} +/^%}$/ && state == 1 { + state = 0; + next; +} +state == 1 { print; next; } +/^struct/ && state == 0 { + print; + struct_seen = $2; + next; +} +/^%%$/ && state == 0 { + state = 2; + 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, 0, 0 }"; + print "};"; + print "#define\tNWORDS\t(sizeof(wordlist)/sizeof(wordlist[0]) - 1)"; + print "static const struct map *"; + print "in_word_set(const char *word)"; + print "{"; + print "\tconst struct", struct_seen, "*mp;"; + print ""; + print "\tfor (mp = wordlist; mp < &wordlist[NWORDS]; mp++) {"; + print "\t\tif (strcmp(word, mp->name) == 0)"; + print "\t\t\treturn (mp);"; + print "\t}"; + print "\treturn (NULL);"; + print "}"; + print ""; + next; +} +state == 2 && NF == 2 { + name = substr($1, 1, length($1) - 1); + 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; } +{ + # eat anything not matched. +} diff --git a/src/bin/getconf/getconf.1 b/src/bin/getconf/getconf.1 new file mode 100644 index 0000000000..c3baed94b1 --- /dev/null +++ b/src/bin/getconf/getconf.1 @@ -0,0 +1,207 @@ +.\" +.\" Copyright 2000 Massachusetts Institute of Technology +.\" +.\" Permission to use, copy, modify, and distribute this software and +.\" its documentation for any purpose and without fee is hereby +.\" granted, provided that both the above copyright notice and this +.\" permission notice appear in all copies, that both the above +.\" copyright notice and this permission notice appear in all +.\" supporting documentation, and that the name of M.I.T. not be used +.\" in advertising or publicity pertaining to distribution of the +.\" software without specific, written prior permission. M.I.T. makes +.\" no representations about the suitability of this software for any +.\" purpose. It is provided "as is" without express or implied +.\" warranty. +.\" +.\" THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS +.\" ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, +.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT +.\" SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +.\" LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +.\" USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +.\" ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd September 18, 2002 +.Dt GETCONF 1 +.Os +.Sh NAME +.Nm getconf +.Nd retrieve standard configuration variables +.Sh SYNOPSIS +.Nm +.Op Fl v Ar environment +.Ar path_var +.Ar file +.Nm +.Op Fl v Ar environment +.Ar system_var +.Sh DESCRIPTION +The +.Nm +utility prints the value of a +.Tn POSIX +or +.Tn X/Open +path or system configuration variable to the standard output. +If the specified variable is undefined, the string +.Dq Li undefined +is output. +.Pp +The first form of the command, with two mandatory +arguments, retrieves file- and file system-specific +configuration variables using +.Xr pathconf 2 . +The second form, with a single argument, retrieves system +configuration variables using +.Xr confstr 3 +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 +.In limits.h . +.Pp +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, +.Ar system_var +might be +.Dv ARG_MAX +or +.Dv _POSIX_VERSION , +as opposed to the +.Xr sysconf 3 +names +.Dv _SC_ARG_MAX +or +.Dv _SC_POSIX_VERSION . +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 . +.Ss Programming Environments +The +.Fl v Ar environment +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: +.Pp +.Dl "getconf POSIX_V6_WIDTH_RESTRICTED_ENVS" +.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 +.Vt 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 EXIT STATUS +.Ex -std +.Sh EXAMPLES +The command: +.Pp +.Dl "getconf PATH" +.Pp +will display the system default setting for the +.Ev PATH +environment variable. +.Pp +The command: +.Pp +.Dl "getconf NAME_MAX /tmp" +.Pp +will display the maximum length of a filename in the +.Pa /tmp +directory. +.Pp +The command: +.Pp +.Dl "getconf -v POSIX_V6_LPBIG_OFFBIG LONG_MAX" +.Pp +will display the maximum value of the C type +.Vt long +in the +.Li POSIX_V6_LPBIG_OFFBIG +programming environment, +if the system supports that environment. +.Sh DIAGNOSTICS +Use of a +.Ar system_var +or +.Ar path_var +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. +The +.Nm +utility recognizes all of the variables defined for +.St -p1003.1-2001 , +including those which are not currently implemented. +.Sh SEE ALSO +.Xr pathconf 2 , +.Xr confstr 3 , +.Xr sysconf 3 +.Sh STANDARDS +The +.Nm +utility is expected to be compliant with +.St -p1003.1-2001 . +.Sh HISTORY +The +.Nm +utility first appeared in +.Fx 5.0 . +.Sh AUTHORS +.An Garrett A. Wollman Aq wollman@lcs.mit.edu diff --git a/src/bin/getconf/getconf.c b/src/bin/getconf/getconf.c new file mode 100644 index 0000000000..5f88db6cbe --- /dev/null +++ b/src/bin/getconf/getconf.c @@ -0,0 +1,190 @@ +/* + * Copyright 2000 Massachusetts Institute of Technology + * + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose and without fee is hereby + * granted, provided that both the above copyright notice and this + * permission notice appear in all copies, that both the above + * copyright notice and this permission notice appear in all + * supporting documentation, and that the name of M.I.T. not be used + * in advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. M.I.T. makes + * no representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied + * warranty. + * + * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS + * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include + +#include +#include +#include +#include +#include +#include + +#include "getconf.h" + +static void do_confstr(const char *name, int key); +static void do_sysconf(const char *name, int key); +static void do_pathconf(const char *name, int key, const char *path); + +static void +usage(void) +{ + fprintf(stderr, +"usage: getconf [-v prog_env] system_var\n" +" getconf [-v prog_env] path_var pathname\n"); + exit(EX_USAGE); +} + +int +main(int argc, char **argv) +{ + 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': + vflag = optarg; + break; + + default: + usage(); + } + } + + if ((name = argv[optind]) == NULL) + usage(); + + 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("%" PRIdMAX "\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 { + valid = find_sysconf(name, &key); + if (valid > 0) { + do_sysconf(name, key); + } else if (valid < 0) { + printf("undefined\n"); + } else + errx(EX_USAGE, + "no such configuration parameter `%s'", + name); + } + } 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); + } + return 0; +} + +static void +do_confstr(const char *name, int key) +{ + size_t len; + int savederr; + + savederr = errno; + errno = 0; + len = confstr(key, 0, 0); + if (len == 0) { + if (errno) + err(EX_OSERR, "confstr: %s", name); + else + printf("undefined\n"); + } else { + char buf[len + 1]; + + confstr(key, buf, len); + printf("%s\n", buf); + } + errno = savederr; +} + +static void +do_sysconf(const char *name, int key) +{ + long value; + + errno = 0; + value = sysconf(key); + if (value == -1 && errno != 0) + err(EX_OSERR, "sysconf: %s", name); + else if (value == -1) + printf("undefined\n"); + else + printf("%ld\n", value); +} + +static void +do_pathconf(const char *name, int key, const char *path) +{ + long value; + + errno = 0; + value = pathconf(path, key); + if (value == -1 && errno != 0) + err(EX_OSERR, "pathconf: %s", name); + else if (value == -1) + printf("undefined\n"); + else + printf("%ld\n", value); +} + diff --git a/src/bin/getconf/getconf.h b/src/bin/getconf/getconf.h new file mode 100644 index 0000000000..266a0ff3b0 --- /dev/null +++ b/src/bin/getconf/getconf.h @@ -0,0 +1,43 @@ +/* + * Copyright 2000 Massachusetts Institute of Technology + * + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose and without fee is hereby + * granted, provided that both the above copyright notice and this + * permission notice appear in all copies, that both the above + * copyright notice and this permission notice appear in all + * supporting documentation, and that the name of M.I.T. not be used + * in advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. M.I.T. makes + * no representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied + * warranty. + * + * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS + * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifdef STABLE +typedef long long intmax_t; +#define PRIdMAX "lld" +#else +#include +#endif + +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/src/bin/getconf/limits.gperf b/src/bin/getconf/limits.gperf new file mode 100644 index 0000000000..68e0d65e78 --- /dev/null +++ b/src/bin/getconf/limits.gperf @@ -0,0 +1,118 @@ +%{ +/* + * Copyright is disclaimed as to the contents of this file. + * + * $FreeBSD$ + */ + +#include + +#include +#include + +#include "getconf.h" + +/* + * Override gperf's built-in external scope. + */ +static const struct map *in_word_set(const char *str); + +%} +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); + if (rv != NULL) { + if (rv->valid) { + *value = rv->value; + return 1; + } + return -1; + } + return 0; +} diff --git a/src/bin/getconf/pathconf.gperf b/src/bin/getconf/pathconf.gperf new file mode 100644 index 0000000000..e8b83659d8 --- /dev/null +++ b/src/bin/getconf/pathconf.gperf @@ -0,0 +1,62 @@ +%{ +/* + * Copyright is disclaimed as to the contents of this file. + * + * $FreeBSD$ + */ + +#include + +#include +#include + +#include "getconf.h" + +/* + * Override gperf's built-in external scope. + */ +static const struct map *in_word_set(const char *str); + +%} +struct map { const char *name; int key; int valid; }; +%% +FILESIZEBITS, _PC_FILESIZEBITS +LINK_MAX, _PC_LINK_MAX +MAX_CANON, _PC_MAX_CANON +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 +SYMLINK_MAX, _PC_SYMLINK_MAX +TRUSTEDBSD_ACL_EXTENDED, _PC_ACL_EXTENDED +TRUSTEDBSD_ACL_PATH_MAX, _PC_ACL_PATH_MAX +TRUSTEDBSD_CAP_PRESENT, _PC_CAP_PRESENT +TRUSTEDBSD_INF_PRESENT, _PC_INF_PRESENT +TRUSTEDBSD_MAC_PRESENT, _PC_MAC_PRESENT +_POSIX_CHOWN_RESTRICTED, _PC_CHOWN_RESTRICTED +_POSIX_NO_TRUNC, _PC_NO_TRUNC +_POSIX_VDISABLE, _PC_VDISABLE +_POSIX_ASYNC_IO, _PC_ASYNC_IO +_POSIX_PRIO_IO, _PC_PRIO_IO +_POSIX_SYNC_IO, _PC_SYNC_IO +%% +int +find_pathconf(const char *name, int *key) +{ + const struct map *rv; + + rv = in_word_set(name); + if (rv != NULL) { + if (rv->valid) { + *key = rv->key; + return 1; + } + return -1; + } + return 0; +} diff --git a/src/bin/getconf/progenv.gperf b/src/bin/getconf/progenv.gperf new file mode 100644 index 0000000000..40ce16a160 --- /dev/null +++ b/src/bin/getconf/progenv.gperf @@ -0,0 +1,67 @@ +%{ +/* + * Copyright is disclaimed as to the contents of this file. + * + * $FreeBSD$ + */ + +#include + +#include +#include + +#include "getconf.h" + +/* + * Override gperf's built-in external scope. + */ +static const struct map *in_word_set(const char *str); + +/* + * 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__) || defined(__amd64__) +#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); + if (rv != NULL) { + if (rv->valid) { + *alt_path = rv->alt_path; + return 1; + } + return -1; + } + return 0; +} diff --git a/src/bin/getconf/sysconf.gperf b/src/bin/getconf/sysconf.gperf new file mode 100644 index 0000000000..ae88464a0b --- /dev/null +++ b/src/bin/getconf/sysconf.gperf @@ -0,0 +1,149 @@ +%{ +/* + * Copyright is disclaimed as to the contents of this file. + * + * $FreeBSD$ + */ + +#include + +#include +#include + +#include "getconf.h" + +/* + * Override gperf's built-in external scope. + */ +static const struct map *in_word_set(const char *str); + +%} +struct map { const char *name; int key; int valid; }; +%% +AIO_LISTIO_MAX, _SC_AIO_LISTIO_MAX +AIO_MAX, _SC_AIO_MAX +AIO_PRIO_DELTA_MAX, _SC_AIO_PRIO_DELTA_MAX +ARG_MAX, _SC_ARG_MAX +ATEXIT_MAX, _SC_ATEXIT_MAX +BC_BASE_MAX, _SC_BC_BASE_MAX +BC_DIM_MAX, _SC_BC_DIM_MAX +BC_SCALE_MAX, _SC_BC_SCALE_MAX +BC_STRING_MAX, _SC_BC_STRING_MAX +CHILD_MAX, _SC_CHILD_MAX +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 +PASS_MAX, _SC_PASS_MAX +PTHREAD_DESTRUCTOR_ITERATIONS, _SC_THREAD_DESTRUCTOR_ITERATIONS +PTHREAD_KEYS_MAX, _SC_THREAD_KEYS_MAX +PTHREAD_STACK_MIN, _SC_THREAD_STACK_MIN +PTHREAD_THREADS_MAX, _SC_THREAD_THREADS_MAX +RE_DUP_MAX, _SC_RE_DUP_MAX +RTSIG_MAX, _SC_RTSIG_MAX +SEM_NSEMS_MAX, _SC_SEM_NSEMS_MAX +SEM_VALUE_MAX, _SC_SEM_VALUE_MAX +SIGQUEUE_MAX, _SC_SIGQUEUE_MAX +STREAM_MAX, _SC_STREAM_MAX +SYMLOOP_MAX, _SC_SYMLOOP_MAX +TIMER_MAX, _SC_TIMER_MAX +TTY_NAME_MAX, _SC_TTY_NAME_MAX +TZNAME_MAX, _SC_TZNAME_MAX +_POSIX2_CHAR_TERM, _SC_2_CHAR_TERM +_POSIX2_C_BIND, _SC_2_C_BIND +_POSIX2_C_DEV, _SC_2_C_DEV +_POSIX2_C_VERSION, _SC_2_C_VERSION +_POSIX2_FORT_DEV, _SC_2_FORT_DEV +_POSIX2_FORT_RUN, _SC_2_FORT_RUN +_POSIX2_LOCALEDEF, _SC_2_LOCALEDEF +_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_IPV6, _SC_IPV6 +_POSIX_JOB_CONTROL, _SC_JOB_CONTROL +_POSIX_MAPPED_FILES, _SC_MAPPED_FILES +_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_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 +_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 +_XOPEN_REALTIME, _SC_XOPEN_REALTIME +_XOPEN_REALTIME_THREADS, _SC_XOPEN_REALTIME_THREADS +_XOPEN_SHM, _SC_XOPEN_SHM +_XOPEN_UNIX, _SC_XOPEN_UNIX +_XOPEN_VERSION, _SC_XOPEN_VERSION +_XOPEN_XCU_VERSION, _SC_XCU_VERSION +%% +int +find_sysconf(const char *name, int *key) +{ + const struct map *rv; + + rv = in_word_set(name); + if (rv != NULL) { + if (rv->valid) { + *key = rv->key; + return 1; + } + return -1; + } + return 0; +}