diff options
author | Timo Teräs <timo.teras@iki.fi> | 2014-04-26 22:53:26 +0300 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2014-04-26 22:55:42 +0300 |
commit | db244b3b618df0c7e451f2a5eeefa0e167b813f9 (patch) | |
tree | 0ce352335d9d98eaefb0912fbae898d890daee01 | |
parent | 761bfcda159e2c226f63239c4d10c8cfbd88b01a (diff) | |
download | aports-db244b3b618df0c7e451f2a5eeefa0e167b813f9.tar.bz2 aports-db244b3b618df0c7e451f2a5eeefa0e167b813f9.tar.xz |
main/musl: add LONG_BIT and other extensions to getconf
-rw-r--r-- | main/musl/APKBUILD | 8 | ||||
-rw-r--r-- | main/musl/getconf.c | 467 |
2 files changed, 244 insertions, 231 deletions
diff --git a/main/musl/APKBUILD b/main/musl/APKBUILD index f37d49b87..60f33a594 100644 --- a/main/musl/APKBUILD +++ b/main/musl/APKBUILD @@ -2,7 +2,7 @@ # Maintainer: Timo Teräs <timo.teras@iki.fi> pkgname=musl pkgver=1.1.0 -pkgrel=4 +pkgrel=5 pkgdesc="the musl c library (libc) implementation" url="http://www.musl-libc.org/" arch="all" @@ -133,7 +133,7 @@ a3810683ef61ac27e2f6ec9801280c81 1001-add-basic-dns-record-parsing-functions.pa e936297ceb484b2160a4cd8a3a4eb291 2001-default-to-localtime-timezone-if-TZ-is-undefined.patch 61c6c1e84ed1df82abbe6d75e90cf21c getopt_long.c 0df687757221bbb0fc1aa67f1bd646f9 __stack_chk_fail_local.c -dae8a31f47488273d8465c785bd77a00 getconf.c +cb82d21fed17a116b44b830adba71c5a getconf.c 2b941c4251cac44988a4abfc50e21267 getent.c 170ce44d0eca4bcfebdf402f21af5f71 iconv.c" sha256sums="de1b43019e5361d7577e5e0213e9dde591853e9da5d4a7cd75e2e0d78bf60820 musl-1.1.0.tar.gz @@ -143,7 +143,7 @@ sha256sums="de1b43019e5361d7577e5e0213e9dde591853e9da5d4a7cd75e2e0d78bf60820 mu 60d7aa78040ee664681e507475129f76e445291863137e568c9a3d11ae8436ce 2001-default-to-localtime-timezone-if-TZ-is-undefined.patch d9b644ec20bc33e81a7c52b9fcf7973d835923a69faf50f03db45534b811bd96 getopt_long.c 299a7d75a09de3e2e11e7fb4acc3182e4a14e868093d2f30938fce9bfcff13da __stack_chk_fail_local.c -e3d1e1f82d1319d9be4726a32dfbe08ab8c23aceaa5e6b667cb391f70a467a1e getconf.c +1b540709f83b7b9a03073b39066810fdb90537d840b50c2016a84bedce038606 getconf.c 68373a55e89ce85c562d941ccf588337d6cc6c9c17689d695f65cd7607134bbe getent.c c24f1da0bdb201d0689efcf257d2146209cb036c313436d76ca80984ace01b0c iconv.c" sha512sums="72dab085fa56a2f02d407074b9a4c1d409624df74924ed385b174a767113aa0a4112bd22d3eaf465b31a14b8e60a15997d6042421994673977de306ee8738b3d musl-1.1.0.tar.gz @@ -153,6 +153,6 @@ dad965258daf69371b844f76bfe5a914b0eca0ca76f3fc340b8fd7acf598b5f87bbe6d68b1f43ed0 8d4cae760895a18e83b5fcbdc925705a6dd98acd2270562ee6c905363096a4111cf3aa324b52a16066e30bddc9ab104883e2b25b5c68396ea27f1c50cb939f0a 2001-default-to-localtime-timezone-if-TZ-is-undefined.patch 140f3f20d30bd95ebce8c41b8cc7f616c6cbedf4ea06c729c21014e74f6043796825cc40ebc5180620ea38173afdba23f09ebf6d8b11fa05440b14d23764fca9 getopt_long.c 062bb49fa54839010acd4af113e20f7263dde1c8a2ca359b5fb2661ef9ed9d84a0f7c3bc10c25dcfa10bb3c5a4874588dff636ac43d5dbb3d748d75400756d0b __stack_chk_fail_local.c -04ead14ff557d71153457b7f55c4b3ecb7594f91e01a9319a6ad0056010570cbc69680d82a7bf9c977c8bb382cfbb7cd6bf79f8fbceadf0a0f9f77812f32a324 getconf.c +06064adfb4dfb45257857113b3f342f77201685f6d3b8e64e203ff618dbb254e7ecb65ecc2d108395f27154825396251b3cfbc678d197d590d93cf79ac5cb56d getconf.c b35de9847353b273516162ed4828a810c6130fc5b7de44ee4433003b3f99647b25792d9b1c40dfc67069add11f3fb850e5c35d4f1912dccac108059bbbdfd5a2 getent.c cef7a6c35c909c70f49935cc84d9e675ff7b63979c222e08f3a70e3f7792607c73f28e8048d61c89f34e13b0144e79e374b73d1727419f6b7c98471c2c338077 iconv.c" diff --git a/main/musl/getconf.c b/main/musl/getconf.c index 0c698bc5e..0c511c085 100644 --- a/main/musl/getconf.c +++ b/main/musl/getconf.c @@ -5,6 +5,9 @@ * This code is derived from software contributed to The NetBSD Foundation * by J.T. Conklin. * + * Mostly rewritten to be used in Alpine Linux (with musl c-library) + * by Timo Teräs. + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -27,10 +30,9 @@ * POSSIBILITY OF SUCH DAMAGE. */ -/* Fixed to be used with musl in Alpine Linux by Timo Teräs. */ - #include <err.h> #include <errno.h> +#include <values.h> #include <limits.h> #include <locale.h> #include <stdio.h> @@ -38,145 +40,163 @@ #include <unistd.h> #include <string.h> -struct conf_variable -{ - const char *name; - enum { SYSCONF, CONFSTR, PATHCONF, CONSTANT } type; - long value; +struct conf_variable { + const char *name; + enum { SYSCONF, CONFSTR, PATHCONF, CONSTANT, UCONSTANT, NUM_TYPES } type; + long value; }; -static const struct conf_variable conf_table[] = -{ - { "PATH", CONFSTR, _CS_PATH }, - - /* Utility Limit Minimum Values */ - { "POSIX2_BC_BASE_MAX", CONSTANT, _POSIX2_BC_BASE_MAX }, - { "POSIX2_BC_DIM_MAX", CONSTANT, _POSIX2_BC_DIM_MAX }, - { "POSIX2_BC_SCALE_MAX", CONSTANT, _POSIX2_BC_SCALE_MAX }, - { "POSIX2_BC_STRING_MAX", CONSTANT, _POSIX2_BC_STRING_MAX }, - { "POSIX2_COLL_WEIGHTS_MAX", CONSTANT, _POSIX2_COLL_WEIGHTS_MAX }, - { "POSIX2_EXPR_NEST_MAX", CONSTANT, _POSIX2_EXPR_NEST_MAX }, - { "POSIX2_LINE_MAX", CONSTANT, _POSIX2_LINE_MAX }, - { "POSIX2_RE_DUP_MAX", CONSTANT, _POSIX2_RE_DUP_MAX }, - { "POSIX2_VERSION", CONSTANT, _POSIX2_VERSION }, - - /* POSIX.1 Minimum Values */ - { "_POSIX_AIO_LISTIO_MAX", CONSTANT, _POSIX_AIO_LISTIO_MAX }, - { "_POSIX_AIO_MAX", CONSTANT, _POSIX_AIO_MAX }, - { "_POSIX_ARG_MAX", CONSTANT, _POSIX_ARG_MAX }, - { "_POSIX_CHILD_MAX", CONSTANT, _POSIX_CHILD_MAX }, - { "_POSIX_LINK_MAX", CONSTANT, _POSIX_LINK_MAX }, - { "_POSIX_MAX_CANON", CONSTANT, _POSIX_MAX_CANON }, - { "_POSIX_MAX_INPUT", CONSTANT, _POSIX_MAX_INPUT }, - { "_POSIX_MQ_OPEN_MAX", CONSTANT, _POSIX_MQ_OPEN_MAX }, - { "_POSIX_MQ_PRIO_MAX", CONSTANT, _POSIX_MQ_PRIO_MAX }, - { "_POSIX_NAME_MAX", CONSTANT, _POSIX_NAME_MAX }, - { "_POSIX_NGROUPS_MAX", CONSTANT, _POSIX_NGROUPS_MAX }, - { "_POSIX_OPEN_MAX", CONSTANT, _POSIX_OPEN_MAX }, - { "_POSIX_PATH_MAX", CONSTANT, _POSIX_PATH_MAX }, - { "_POSIX_PIPE_BUF", CONSTANT, _POSIX_PIPE_BUF }, - { "_POSIX_SSIZE_MAX", CONSTANT, _POSIX_SSIZE_MAX }, - { "_POSIX_STREAM_MAX", CONSTANT, _POSIX_STREAM_MAX }, - { "_POSIX_TZNAME_MAX", CONSTANT, _POSIX_TZNAME_MAX }, - - /* Symbolic Utility Limits */ - { "BC_BASE_MAX", SYSCONF, _SC_BC_BASE_MAX }, - { "BC_DIM_MAX", SYSCONF, _SC_BC_DIM_MAX }, - { "BC_SCALE_MAX", SYSCONF, _SC_BC_SCALE_MAX }, - { "BC_STRING_MAX", SYSCONF, _SC_BC_STRING_MAX }, - { "COLL_WEIGHTS_MAX", SYSCONF, _SC_COLL_WEIGHTS_MAX }, - { "EXPR_NEST_MAX", SYSCONF, _SC_EXPR_NEST_MAX }, - { "LINE_MAX", SYSCONF, _SC_LINE_MAX }, - { "RE_DUP_MAX", SYSCONF, _SC_RE_DUP_MAX }, - - /* Optional Facility Configuration Values */ - { "_POSIX2_C_BIND", SYSCONF, _SC_2_C_BIND }, - { "POSIX2_C_DEV", SYSCONF, _SC_2_C_DEV }, - { "POSIX2_CHAR_TERM", SYSCONF, _SC_2_CHAR_TERM }, - { "POSIX2_FORT_DEV", SYSCONF, _SC_2_FORT_DEV }, - { "POSIX2_FORT_RUN", SYSCONF, _SC_2_FORT_RUN }, - { "POSIX2_LOCALEDEF", SYSCONF, _SC_2_LOCALEDEF }, - { "POSIX2_SW_DEV", SYSCONF, _SC_2_SW_DEV }, - { "POSIX2_UPE", SYSCONF, _SC_2_UPE }, - - /* POSIX.1 Configurable System Variables */ - { "AIO_LISTIO_MAX", SYSCONF, _SC_AIO_LISTIO_MAX }, - { "AIO_MAX", SYSCONF, _SC_AIO_MAX }, - { "ARG_MAX", SYSCONF, _SC_ARG_MAX }, - { "CHILD_MAX", SYSCONF, _SC_CHILD_MAX }, - { "CLK_TCK", SYSCONF, _SC_CLK_TCK }, - { "MQ_OPEN_MAX", SYSCONF, _SC_MQ_OPEN_MAX }, - { "MQ_PRIO_MAX", SYSCONF, _SC_MQ_PRIO_MAX }, - { "NGROUPS_MAX", SYSCONF, _SC_NGROUPS_MAX }, - { "OPEN_MAX", SYSCONF, _SC_OPEN_MAX }, - { "STREAM_MAX", SYSCONF, _SC_STREAM_MAX }, - { "TZNAME_MAX", SYSCONF, _SC_TZNAME_MAX }, - { "_POSIX_JOB_CONTROL", SYSCONF, _SC_JOB_CONTROL }, - { "_POSIX_SAVED_IDS", SYSCONF, _SC_SAVED_IDS }, - { "_POSIX_VERSION", SYSCONF, _SC_VERSION }, - - { "LINK_MAX", PATHCONF, _PC_LINK_MAX }, - { "MAX_CANON", PATHCONF, _PC_MAX_CANON }, - { "MAX_INPUT", PATHCONF, _PC_MAX_INPUT }, - { "NAME_MAX", PATHCONF, _PC_NAME_MAX }, - { "PATH_MAX", PATHCONF, _PC_PATH_MAX }, - { "PIPE_BUF", PATHCONF, _PC_PIPE_BUF }, - { "_POSIX_CHOWN_RESTRICTED", PATHCONF, _PC_CHOWN_RESTRICTED }, - { "_POSIX_NO_TRUNC", PATHCONF, _PC_NO_TRUNC }, - { "_POSIX_VDISABLE", PATHCONF, _PC_VDISABLE }, - - /* POSIX.1b Configurable System Variables */ - { "PAGESIZE", SYSCONF, _SC_PAGESIZE }, - { "_POSIX_ASYNCHRONOUS_IO", SYSCONF, _SC_ASYNCHRONOUS_IO }, - { "_POSIX_FSYNC", SYSCONF, _SC_FSYNC }, - { "_POSIX_MAPPED_FILES", SYSCONF, _SC_MAPPED_FILES }, - { "_POSIX_MEMLOCK", SYSCONF, _SC_MEMLOCK }, - { "_POSIX_MEMLOCK_RANGE", SYSCONF, _SC_MEMLOCK_RANGE }, - { "_POSIX_MEMORY_PROTECTION", SYSCONF, _SC_MEMORY_PROTECTION }, - { "_POSIX_MESSAGE_PASSING", SYSCONF, _SC_MESSAGE_PASSING }, - { "_POSIX_MONOTONIC_CLOCK", SYSCONF, _SC_MONOTONIC_CLOCK }, - { "_POSIX_PRIORITY_SCHEDULING", SYSCONF, _SC_PRIORITY_SCHEDULING }, - { "_POSIX_SEMAPHORES", SYSCONF, _SC_SEMAPHORES }, - { "_POSIX_SHARED_MEMORY_OBJECTS", SYSCONF, _SC_SHARED_MEMORY_OBJECTS }, - { "_POSIX_SYNCHRONIZED_IO", SYSCONF, _SC_SYNCHRONIZED_IO }, - { "_POSIX_TIMERS", SYSCONF, _SC_TIMERS }, - - { "_POSIX_SYNC_IO", PATHCONF, _PC_SYNC_IO }, - - /* POSIX.1c Configurable System Variables */ - { "LOGIN_NAME_MAX", SYSCONF, _SC_LOGIN_NAME_MAX }, - { "_POSIX_THREADS", SYSCONF, _SC_THREADS }, - - /* POSIX.1j Configurable System Variables */ - { "_POSIX_BARRIERS", SYSCONF, _SC_BARRIERS }, - { "_POSIX_READER_WRITER_LOCKS", SYSCONF, _SC_READER_WRITER_LOCKS }, - { "_POSIX_SPIN_LOCKS", SYSCONF, _SC_SPIN_LOCKS }, - - /* XPG4.2 Configurable System Variables */ - { "IOV_MAX", SYSCONF, _SC_IOV_MAX }, - { "PAGE_SIZE", SYSCONF, _SC_PAGE_SIZE }, - { "_XOPEN_SHM", SYSCONF, _SC_XOPEN_SHM }, - - /* X/Open CAE Spec. Issue 5 Version 2 Configurable System Variables */ - { "FILESIZEBITS", PATHCONF, _PC_FILESIZEBITS }, - - /* POSIX.1-2001 XSI Option Group Configurable System Variables */ - { "ATEXIT_MAX", SYSCONF, _SC_ATEXIT_MAX }, - - /* POSIX.1-2001 TSF Configurable System Variables */ - { "GETGR_R_SIZE_MAX", SYSCONF, _SC_GETGR_R_SIZE_MAX }, - { "GETPW_R_SIZE_MAX", SYSCONF, _SC_GETPW_R_SIZE_MAX }, - - /* Commonly provided extensions */ - { "_PHYS_PAGES", SYSCONF, _SC_PHYS_PAGES }, - { "_AVPHYS_PAGES", SYSCONF, _SC_AVPHYS_PAGES }, - { "_NPROCESSORS_CONF", SYSCONF, _SC_NPROCESSORS_CONF }, - { "_NPROCESSORS_ONLN", SYSCONF, _SC_NPROCESSORS_ONLN }, - - { NULL, CONSTANT, 0L } +static const struct conf_variable conf_table[] = { +{ "PATH", CONFSTR, _CS_PATH }, + +/* Utility Limit Minimum Values */ +{ "POSIX2_BC_BASE_MAX", CONSTANT, _POSIX2_BC_BASE_MAX }, +{ "POSIX2_BC_DIM_MAX", CONSTANT, _POSIX2_BC_DIM_MAX }, +{ "POSIX2_BC_SCALE_MAX", CONSTANT, _POSIX2_BC_SCALE_MAX }, +{ "POSIX2_BC_STRING_MAX", CONSTANT, _POSIX2_BC_STRING_MAX }, +{ "POSIX2_COLL_WEIGHTS_MAX", CONSTANT, _POSIX2_COLL_WEIGHTS_MAX }, +{ "POSIX2_EXPR_NEST_MAX", CONSTANT, _POSIX2_EXPR_NEST_MAX }, +{ "POSIX2_LINE_MAX", CONSTANT, _POSIX2_LINE_MAX }, +{ "POSIX2_RE_DUP_MAX", CONSTANT, _POSIX2_RE_DUP_MAX }, +{ "POSIX2_VERSION", CONSTANT, _POSIX2_VERSION }, + +/* POSIX.1 Minimum Values */ +{ "_POSIX_AIO_LISTIO_MAX", CONSTANT, _POSIX_AIO_LISTIO_MAX }, +{ "_POSIX_AIO_MAX", CONSTANT, _POSIX_AIO_MAX }, +{ "_POSIX_ARG_MAX", CONSTANT, _POSIX_ARG_MAX }, +{ "_POSIX_CHILD_MAX", CONSTANT, _POSIX_CHILD_MAX }, +{ "_POSIX_LINK_MAX", CONSTANT, _POSIX_LINK_MAX }, +{ "_POSIX_MAX_CANON", CONSTANT, _POSIX_MAX_CANON }, +{ "_POSIX_MAX_INPUT", CONSTANT, _POSIX_MAX_INPUT }, +{ "_POSIX_MQ_OPEN_MAX", CONSTANT, _POSIX_MQ_OPEN_MAX }, +{ "_POSIX_MQ_PRIO_MAX", CONSTANT, _POSIX_MQ_PRIO_MAX }, +{ "_POSIX_NAME_MAX", CONSTANT, _POSIX_NAME_MAX }, +{ "_POSIX_NGROUPS_MAX", CONSTANT, _POSIX_NGROUPS_MAX }, +{ "_POSIX_OPEN_MAX", CONSTANT, _POSIX_OPEN_MAX }, +{ "_POSIX_PATH_MAX", CONSTANT, _POSIX_PATH_MAX }, +{ "_POSIX_PIPE_BUF", CONSTANT, _POSIX_PIPE_BUF }, +{ "_POSIX_SSIZE_MAX", CONSTANT, _POSIX_SSIZE_MAX }, +{ "_POSIX_STREAM_MAX", CONSTANT, _POSIX_STREAM_MAX }, +{ "_POSIX_TZNAME_MAX", CONSTANT, _POSIX_TZNAME_MAX }, + +/* Symbolic Utility Limits */ +{ "BC_BASE_MAX", SYSCONF, _SC_BC_BASE_MAX }, +{ "BC_DIM_MAX", SYSCONF, _SC_BC_DIM_MAX }, +{ "BC_SCALE_MAX", SYSCONF, _SC_BC_SCALE_MAX }, +{ "BC_STRING_MAX", SYSCONF, _SC_BC_STRING_MAX }, +{ "COLL_WEIGHTS_MAX", SYSCONF, _SC_COLL_WEIGHTS_MAX }, +{ "EXPR_NEST_MAX", SYSCONF, _SC_EXPR_NEST_MAX }, +{ "LINE_MAX", SYSCONF, _SC_LINE_MAX }, +{ "RE_DUP_MAX", SYSCONF, _SC_RE_DUP_MAX }, + +/* Optional Facility Configuration Values */ +{ "_POSIX2_C_BIND", SYSCONF, _SC_2_C_BIND }, +{ "POSIX2_C_DEV", SYSCONF, _SC_2_C_DEV }, +{ "POSIX2_CHAR_TERM", SYSCONF, _SC_2_CHAR_TERM }, +{ "POSIX2_FORT_DEV", SYSCONF, _SC_2_FORT_DEV }, +{ "POSIX2_FORT_RUN", SYSCONF, _SC_2_FORT_RUN }, +{ "POSIX2_LOCALEDEF", SYSCONF, _SC_2_LOCALEDEF }, +{ "POSIX2_SW_DEV", SYSCONF, _SC_2_SW_DEV }, +{ "POSIX2_UPE", SYSCONF, _SC_2_UPE }, + +/* POSIX.1 Configurable System Variables */ +{ "AIO_LISTIO_MAX", SYSCONF, _SC_AIO_LISTIO_MAX }, +{ "AIO_MAX", SYSCONF, _SC_AIO_MAX }, +{ "ARG_MAX", SYSCONF, _SC_ARG_MAX }, +{ "CHILD_MAX", SYSCONF, _SC_CHILD_MAX }, +{ "CLK_TCK", SYSCONF, _SC_CLK_TCK }, +{ "MQ_OPEN_MAX", SYSCONF, _SC_MQ_OPEN_MAX }, +{ "MQ_PRIO_MAX", SYSCONF, _SC_MQ_PRIO_MAX }, +{ "NGROUPS_MAX", SYSCONF, _SC_NGROUPS_MAX }, +{ "OPEN_MAX", SYSCONF, _SC_OPEN_MAX }, +{ "STREAM_MAX", SYSCONF, _SC_STREAM_MAX }, +{ "TZNAME_MAX", SYSCONF, _SC_TZNAME_MAX }, +{ "_POSIX_JOB_CONTROL", SYSCONF, _SC_JOB_CONTROL }, +{ "_POSIX_SAVED_IDS", SYSCONF, _SC_SAVED_IDS }, +{ "_POSIX_VERSION", SYSCONF, _SC_VERSION }, + +{ "LINK_MAX", PATHCONF, _PC_LINK_MAX }, +{ "MAX_CANON", PATHCONF, _PC_MAX_CANON }, +{ "MAX_INPUT", PATHCONF, _PC_MAX_INPUT }, +{ "NAME_MAX", PATHCONF, _PC_NAME_MAX }, +{ "PATH_MAX", PATHCONF, _PC_PATH_MAX }, +{ "PIPE_BUF", PATHCONF, _PC_PIPE_BUF }, +{ "_POSIX_CHOWN_RESTRICTED", PATHCONF, _PC_CHOWN_RESTRICTED }, +{ "_POSIX_NO_TRUNC", PATHCONF, _PC_NO_TRUNC }, +{ "_POSIX_VDISABLE", PATHCONF, _PC_VDISABLE }, + +/* POSIX.1b Configurable System Variables */ +{ "PAGESIZE", SYSCONF, _SC_PAGESIZE }, +{ "_POSIX_ASYNCHRONOUS_IO", SYSCONF, _SC_ASYNCHRONOUS_IO }, +{ "_POSIX_FSYNC", SYSCONF, _SC_FSYNC }, +{ "_POSIX_MAPPED_FILES", SYSCONF, _SC_MAPPED_FILES }, +{ "_POSIX_MEMLOCK", SYSCONF, _SC_MEMLOCK }, +{ "_POSIX_MEMLOCK_RANGE", SYSCONF, _SC_MEMLOCK_RANGE }, +{ "_POSIX_MEMORY_PROTECTION", SYSCONF, _SC_MEMORY_PROTECTION }, +{ "_POSIX_MESSAGE_PASSING", SYSCONF, _SC_MESSAGE_PASSING }, +{ "_POSIX_MONOTONIC_CLOCK", SYSCONF, _SC_MONOTONIC_CLOCK }, +{ "_POSIX_PRIORITY_SCHEDULING", SYSCONF, _SC_PRIORITY_SCHEDULING }, +{ "_POSIX_SEMAPHORES", SYSCONF, _SC_SEMAPHORES }, +{ "_POSIX_SHARED_MEMORY_OBJECTS", SYSCONF, _SC_SHARED_MEMORY_OBJECTS }, +{ "_POSIX_SYNCHRONIZED_IO", SYSCONF, _SC_SYNCHRONIZED_IO }, +{ "_POSIX_TIMERS", SYSCONF, _SC_TIMERS }, + +{ "_POSIX_SYNC_IO", PATHCONF, _PC_SYNC_IO }, + +/* POSIX.1c Configurable System Variables */ +{ "LOGIN_NAME_MAX", SYSCONF, _SC_LOGIN_NAME_MAX }, +{ "_POSIX_THREADS", SYSCONF, _SC_THREADS }, + +/* POSIX.1j Configurable System Variables */ +{ "_POSIX_BARRIERS", SYSCONF, _SC_BARRIERS }, +{ "_POSIX_READER_WRITER_LOCKS", SYSCONF, _SC_READER_WRITER_LOCKS }, +{ "_POSIX_SPIN_LOCKS", SYSCONF, _SC_SPIN_LOCKS }, + +/* XPG4.2 Configurable System Variables */ +{ "IOV_MAX", SYSCONF, _SC_IOV_MAX }, +{ "PAGE_SIZE", SYSCONF, _SC_PAGE_SIZE }, +{ "_XOPEN_SHM", SYSCONF, _SC_XOPEN_SHM }, + +/* X/Open CAE Spec. Issue 5 Version 2 Configurable System Variables */ +{ "FILESIZEBITS", PATHCONF, _PC_FILESIZEBITS }, + +/* POSIX.1-2001 XSI Option Group Configurable System Variables */ +{ "ATEXIT_MAX", SYSCONF, _SC_ATEXIT_MAX }, + +/* POSIX.1-2001 TSF Configurable System Variables */ +{ "GETGR_R_SIZE_MAX", SYSCONF, _SC_GETGR_R_SIZE_MAX }, +{ "GETPW_R_SIZE_MAX", SYSCONF, _SC_GETPW_R_SIZE_MAX }, + +/* Commonly provided extensions */ +{ "_PHYS_PAGES", SYSCONF, _SC_PHYS_PAGES }, +{ "_AVPHYS_PAGES", SYSCONF, _SC_AVPHYS_PAGES }, +{ "_NPROCESSORS_CONF", SYSCONF, _SC_NPROCESSORS_CONF }, +{ "_NPROCESSORS_ONLN", SYSCONF, _SC_NPROCESSORS_ONLN }, + +/* Data type related extensions */ +{ "CHAR_BIT", CONSTANT, CHAR_BIT }, +{ "CHAR_MAX", CONSTANT, CHAR_MAX }, +{ "CHAR_MIN", CONSTANT, CHAR_MIN }, +{ "INT_MAX", CONSTANT, INT_MAX }, +{ "INT_MIN", CONSTANT, INT_MIN }, +{ "LONG_BIT", CONSTANT, LONG_BIT }, +{ "LONG_MAX", CONSTANT, LONG_MAX }, +{ "LONG_MIN", CONSTANT, LONG_MIN }, +{ "SCHAR_MAX", CONSTANT, SCHAR_MAX }, +{ "SCHAR_MIN", CONSTANT, SCHAR_MIN }, +{ "SHRT_MAX", CONSTANT, SHRT_MAX }, +{ "SHRT_MIN", CONSTANT, SHRT_MIN }, +{ "SSIZE_MAX", CONSTANT, SSIZE_MAX }, +{ "UCHAR_MAX", UCONSTANT, (long) UCHAR_MAX }, +{ "UINT_MAX", UCONSTANT, (long) UINT_MAX }, +{ "ULONG_MAX", UCONSTANT, (long) ULONG_MAX }, +{ "USHRT_MAX", UCONSTANT, (long) USHRT_MAX }, +{ "WORD_BIT", CONSTANT, WORD_BIT }, + +{ NULL, CONSTANT, 0L } }; -static int a_flag = 0; /* list all variables */ +static int all = 0; static void usage(const char *p) { @@ -185,104 +205,102 @@ static void usage(const char *p) exit(EXIT_FAILURE); } -static void print_longvar(const char *name, long value) +static void print_long(const char *name, long val) +{ + static const char * const fmtstr[] = { "%2$ld\n", "%s = %ld\n" }; + printf(fmtstr[all], name, val); +} + +static void print_ulong(const char *name, unsigned long val) { - if (a_flag) - (void)printf("%s = %ld\n", name, value); - else - (void)printf("%ld\n", value); + static const char * const fmtstr[] = { "%2$lu\n", "%s = %lu\n" }; + printf(fmtstr[all], name, val); } -static void print_strvar(const char *name, const char *sval) +static void print_string(const char *name, const char *val) { - if (a_flag) - (void)printf("%s = %s\n", name, sval); - else - (void)printf("%s\n", sval); + static const char * const fmtstr[] = { "%2$s\n", "%s = %s\n" }; + printf(fmtstr[all], name, val); } -static void -printvar(const struct conf_variable *cp, const char *pathname) +static int print_constant(const struct conf_variable *cp, const char *pathname) +{ + print_long(cp->name, cp->value); + return 0; +} + +static int print_uconstant(const struct conf_variable *cp, const char *pathname) +{ + print_ulong(cp->name, (unsigned long) cp->value); + return 0; +} + +static int print_sysconf(const struct conf_variable *cp, const char *pathname) { - size_t slen; - char *sval; long val; - switch (cp->type) { - case CONSTANT: - print_longvar(cp->name, cp->value); - break; - - case CONFSTR: - errno = 0; - slen = confstr((int)cp->value, NULL, 0); - if (slen == 0) { - if (errno != 0) -out: err(EXIT_FAILURE, "confstr(%ld)", cp->value); - else - print_strvar(cp->name, "undefined"); - } + errno = 0; + if ((val = sysconf((int)cp->value)) == -1) { + if (errno != 0) err(EXIT_FAILURE, "sysconf(%ld)", cp->value); + return -1; + } + print_long(cp->name, val); + return 0; +} + +static int print_confstr(const struct conf_variable *cp, const char *pathname) +{ + size_t len; + char *val; + + errno = 0; + if ((len = confstr((int)cp->value, NULL, 0)) == 0) goto error; + if ((val = malloc(len)) == NULL) err(EXIT_FAILURE, "Can't allocate %zu bytes", len); + errno = 0; + if (confstr((int)cp->value, val, len) == 0) goto error; + print_string(cp->name, val); + free(val); + return 0; +error: + if (errno != EINVAL) err(EXIT_FAILURE, "confstr(%ld)", cp->value); + return -1; +} + +static int print_pathconf(const struct conf_variable *cp, const char *pathname) +{ + long val; - if ((sval = malloc(slen)) == NULL) - err(EXIT_FAILURE, "Can't allocate %zu bytes", slen); - - errno = 0; - if (confstr((int)cp->value, sval, slen) == 0) { - if (errno != 0) - goto out; - else - print_strvar(cp->name, "undefined"); - } else - print_strvar(cp->name, sval); - - free(sval); - break; - - case SYSCONF: - errno = 0; - if ((val = sysconf((int)cp->value)) == -1) { - if (errno != 0) - err(EXIT_FAILURE, "sysconf(%ld)", cp->value); - print_strvar(cp->name, "undefined"); - } else - print_longvar(cp->name, val); - break; - - case PATHCONF: - errno = 0; - if ((val = pathconf(pathname, (int)cp->value)) == -1) { - if (errno != 0) { - if (a_flag && errno == EINVAL) { - /* Just skip invalid variables */ - return; - } - err(EXIT_FAILURE, "pathconf(%s, %ld)", - pathname, cp->value); - /* NOTREACHED */ - } - - print_strvar(cp->name, "undefined"); - } else - print_longvar(cp->name, val); - break; + errno = 0; + if ((val = pathconf(pathname, (int)cp->value)) == -1) { + if (all && errno == EINVAL) return 0; + if (errno != 0) err(EXIT_FAILURE, "pathconf(%s, %ld)", pathname, cp->value); + return -1; } + print_long(cp->name, val); + return 0; } -int -main(int argc, char **argv) +typedef int (*handler_t)(const struct conf_variable *cp, const char *pathname); +static const handler_t type_handlers[NUM_TYPES] = { + [SYSCONF] = print_sysconf, + [CONFSTR] = print_confstr, + [PATHCONF] = print_pathconf, + [CONSTANT] = print_constant, + [UCONSTANT] = print_uconstant, +}; + +int main(int argc, char **argv) { - int ch; const char *progname = argv[0]; const struct conf_variable *cp; const char *varname, *pathname; - int found; + int ch, found = 0; (void)setlocale(LC_ALL, ""); - while ((ch = getopt(argc, argv, "a")) != -1) { switch (ch) { case 'a': - a_flag = 1; + all = 1; break; case '?': default: @@ -292,7 +310,7 @@ main(int argc, char **argv) argc -= optind; argv += optind; - if (!a_flag) { + if (!all) { if (argc == 0) usage(progname); varname = argv[0]; @@ -305,21 +323,16 @@ main(int argc, char **argv) usage(progname); pathname = argv[0]; /* may be NULL */ - found = 0; for (cp = conf_table; cp->name != NULL; cp++) { - if (a_flag || strcmp(varname, cp->name) == 0) { - if ((cp->type == PATHCONF) == (pathname != NULL)) { - printvar(cp, pathname); - found = 1; - } else if (!a_flag) - errx(EXIT_FAILURE, - "%s: invalid variable type", cp->name); - } + if (!all && strcmp(varname, cp->name) != 0) continue; + if ((cp->type == PATHCONF) == (pathname != NULL)) { + if (type_handlers[cp->type](cp, pathname) < 0) + print_string(cp->name, "undefined"); + found = 1; + } else if (!all) + errx(EXIT_FAILURE, "%s: invalid variable type", cp->name); } - - if (!a_flag && !found) - errx(EXIT_FAILURE, "%s: unknown variable", varname); - + if (!all && !found) errx(EXIT_FAILURE, "%s: unknown variable", varname); (void)fflush(stdout); return ferror(stdout) ? EXIT_FAILURE : EXIT_SUCCESS; } |