aboutsummaryrefslogtreecommitdiffstats
path: root/main/musl
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2014-02-19 07:36:12 +0000
committerTimo Teräs <timo.teras@iki.fi>2014-02-19 07:50:34 +0000
commit3a5340eca2273ccb3f8e3b38e40283c56e6cbaf8 (patch)
tree785698c24812846bb77f9326452253faa61041e7 /main/musl
parent054c297c3ee32d6b584bc2bcb3477d646bc30167 (diff)
downloadaports-3a5340eca2273ccb3f8e3b38e40283c56e6cbaf8.tar.bz2
aports-3a5340eca2273ccb3f8e3b38e40283c56e6cbaf8.tar.xz
main/musl: cherry-pick flock64 fix from upstream, add getconf
needed for openjdk6/icedtea building
Diffstat (limited to 'main/musl')
-rw-r--r--main/musl/0002-add-flock64-alias-for-struct-flock-in-fcntl.h.patch26
-rw-r--r--main/musl/1002-fix-confstr-return-value.patch24
-rw-r--r--main/musl/APKBUILD18
-rw-r--r--main/musl/getconf.c323
4 files changed, 390 insertions, 1 deletions
diff --git a/main/musl/0002-add-flock64-alias-for-struct-flock-in-fcntl.h.patch b/main/musl/0002-add-flock64-alias-for-struct-flock-in-fcntl.h.patch
new file mode 100644
index 0000000000..c2ec46f1d1
--- /dev/null
+++ b/main/musl/0002-add-flock64-alias-for-struct-flock-in-fcntl.h.patch
@@ -0,0 +1,26 @@
+From fdb3efa5ddfa7120de98f8ae78b5f5dc9e8e2e71 Mon Sep 17 00:00:00 2001
+From: Rich Felker <dalias@aerifal.cx>
+Date: Tue, 18 Feb 2014 11:04:15 -0500
+Subject: [PATCH] add flock64 alias for (struct) flock in fcntl.h
+
+this was a missing part of the LFS64 API; it's "needed" for use with
+fcntl and the corresponding lock commands.
+---
+ include/fcntl.h | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/include/fcntl.h b/include/fcntl.h
+index e01a4d1..2d8fa6e 100644
+--- a/include/fcntl.h
++++ b/include/fcntl.h
+@@ -161,6 +161,7 @@ ssize_t tee(int, int, size_t, unsigned);
+ #define F_GETLK64 F_GETLK
+ #define F_SETLK64 F_SETLK
+ #define F_SETLKW64 F_SETLKW
++#define flock64 flock
+ #define open64 open
+ #define openat64 openat
+ #define creat64 creat
+--
+1.8.5.4
+
diff --git a/main/musl/1002-fix-confstr-return-value.patch b/main/musl/1002-fix-confstr-return-value.patch
new file mode 100644
index 0000000000..ff8f5426b8
--- /dev/null
+++ b/main/musl/1002-fix-confstr-return-value.patch
@@ -0,0 +1,24 @@
+From edb7cd561b8df14eac5ce6a62acd1c4f9f12bb03 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Timo=20Ter=C3=A4s?= <timo.teras@iki.fi>
+Date: Wed, 19 Feb 2014 09:40:35 +0200
+Subject: [PATCH] fix confstr return value
+
+man page says the terminating null byte is counted.
+---
+ src/conf/confstr.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/src/conf/confstr.c b/src/conf/confstr.c
+index 4332f72..6e9c23a 100644
+--- a/src/conf/confstr.c
++++ b/src/conf/confstr.c
+@@ -13,5 +13,5 @@ size_t confstr(int name, char *buf, size_t len)
+ }
+ // snprintf is overkill but avoid wasting code size to implement
+ // this completely useless function and its truncation semantics
+- return snprintf(buf, len, "%s", s);
++ return snprintf(buf, len, "%s", s) + 1;
+ }
+--
+1.8.5.4
+
diff --git a/main/musl/APKBUILD b/main/musl/APKBUILD
index d9dd4056b2..1518990bc3 100644
--- a/main/musl/APKBUILD
+++ b/main/musl/APKBUILD
@@ -2,7 +2,7 @@
# Maintainer: Timo Teräs <timo.teras@iki.fi>
pkgname=musl
pkgver=0.9.15
-pkgrel=3
+pkgrel=4
pkgdesc="the musl c library (libc) implementation"
url="http://www.musl-libc.org/"
arch="all"
@@ -15,11 +15,14 @@ subpackages="$pkgname-dev $pkgname-utils"
[ "${CTARGET#*musl}" = "$CTARGET" ] && subpackages="$subpackages musl-gcc:crosstool"
source="http://www.musl-libc.org/releases/musl-$pkgver.tar.gz
0001-git-0.9.15-to-3e02ce1b411.patch
+ 0002-add-flock64-alias-for-struct-flock-in-fcntl.h.patch
1001-add-basic-dns-record-parsing-functions.patch
+ 1002-fix-confstr-return-value.patch
2001-workaround-gcc-pr58245.patch
getopt_long.c
__stack_chk_fail_local.c
+ getconf.c
getent
ldconfig
"
@@ -63,6 +66,9 @@ build() {
${CROSS_COMPILE}gcc $CPPFLAGS $CFLAGS -c "$srcdir"/__stack_chk_fail_local.c -o __stack_chk_fail_local.o || return 1
${CROSS_COMPILE}ar r libssp_nonshared.a __stack_chk_fail_local.o || return 1
+ # getconf
+ ${CROSS_COMPILE}gcc $CPPFLAGS $CFLAGS "$srcdir"/getconf.c -o getconf || return 1
+
# note: not autotools
LDFLAGS="$LDFLAGS -Wl,-soname,libc.musl-${CARCH}.so.1" \
./configure \
@@ -97,6 +103,7 @@ utils() {
mv "$pkgdir"/usr/bin/ldd "$subpkgdir"/usr/bin
find "$pkgdir" -type d -delete 2>/dev/null
install -D "$srcdir"/getent "$subpkgdir"/usr/bin/getent
+ install -D "$_builddir"/getconf "$subpkgdir"/usr/bin/getconf
install -D "$srcdir"/ldconfig "$subpkgdir"/sbin/ldconfig
}
@@ -109,25 +116,34 @@ crosstool() {
md5sums="06f590a38c85722ee9343db2416425f4 musl-0.9.15.tar.gz
06ec0e41d9b426acbd47869038ba0588 0001-git-0.9.15-to-3e02ce1b411.patch
+2275f7138a7dc6869122cc68f7f7c710 0002-add-flock64-alias-for-struct-flock-in-fcntl.h.patch
a3810683ef61ac27e2f6ec9801280c81 1001-add-basic-dns-record-parsing-functions.patch
+499bced87843940199898d1508ef58df 1002-fix-confstr-return-value.patch
7a09c5cd7b3e9532e6902f54a5e928bb 2001-workaround-gcc-pr58245.patch
61c6c1e84ed1df82abbe6d75e90cf21c getopt_long.c
0df687757221bbb0fc1aa67f1bd646f9 __stack_chk_fail_local.c
+7b391300396e58fe9073866b5a80cfe8 getconf.c
ef81489a6258501cf45db58dfc6d5211 getent
33e4fd94e2560e008e2c3b431d0e3419 ldconfig"
sha256sums="4a7baab8f295511196dee48d33b8b82a159a81233facb89433707c792033cbe7 musl-0.9.15.tar.gz
8c03e089985384e2fc2765db3b7c09c91bce1144f5ebf2456ce8ca642104e4b0 0001-git-0.9.15-to-3e02ce1b411.patch
+d2146fcf11b2bf7b55b02dccadf4539fdf5b300777bfca6dc98a8188e9c6b1e2 0002-add-flock64-alias-for-struct-flock-in-fcntl.h.patch
758390768b1bc4159d56908ca332b9640cd0552ed3b4b2b8d4a6d499c54c11a1 1001-add-basic-dns-record-parsing-functions.patch
+dba7e5155efab40829ec0202f1135942004e8e79cff287cbb455355a0d67705f 1002-fix-confstr-return-value.patch
45d6efda7450809e4e68f6e951431dcadf6cb7f0260930d50a9f1a8667aca49f 2001-workaround-gcc-pr58245.patch
d9b644ec20bc33e81a7c52b9fcf7973d835923a69faf50f03db45534b811bd96 getopt_long.c
299a7d75a09de3e2e11e7fb4acc3182e4a14e868093d2f30938fce9bfcff13da __stack_chk_fail_local.c
+530ea449f93d53fafcb377fa0a23a7564f2961e49c07a8fdef6c960110317301 getconf.c
d6996273f5aaaed429058257e4646b243d9e3a4d8609522f802762453f5be4cb getent
306c6ca7407560340797866e077e053627ad409277d1b9da58106fce4cf717cb ldconfig"
sha512sums="2c5f3e742cf29fd76db8079b6012b1b359eda635593995ea8add008abc9744f0ca504e915f7828692aeafc3bddc66e0716492182cd5696e2fa24d9a2289601b8 musl-0.9.15.tar.gz
b721a91b5ff520b5406ecf43f033a82dc71686ccf2d025293b6457d6e77f3a6619fefeb3f3af620d8297b79f820d2bb7c94ca5695b0a284e19305bd4e54c8bed 0001-git-0.9.15-to-3e02ce1b411.patch
+4167de98c13661c0be2eb83bd36f123f0ab52744dae6bdeb41f793021b0fd8a001280bddba3411093a5c17067261679bb0e9c6c2e9fef8c537c6f0f91627266d 0002-add-flock64-alias-for-struct-flock-in-fcntl.h.patch
dad965258daf69371b844f76bfe5a914b0eca0ca76f3fc340b8fd7acf598b5f87bbe6d68b1f43ed0293ee0ed3bfd85d5173ccc169aa6265646248d5b8a906708 1001-add-basic-dns-record-parsing-functions.patch
+d4c5f3c5a8ab3a9f1f63a22933bf4dcc67d6aff630066c9e3bb0edf9f46ab8b6e228ded906e4f82b7849d3b7e84ca25c9322bf5c5787fca10203482a38176700 1002-fix-confstr-return-value.patch
69ad3fc851b44f33dd7c98b83fd0adbd149b37263d17b989f4d7338ee0703dfe8994f4299744e2509492300227d652de6f21b6cdba9b633fcefd3d9f7ca0cf20 2001-workaround-gcc-pr58245.patch
140f3f20d30bd95ebce8c41b8cc7f616c6cbedf4ea06c729c21014e74f6043796825cc40ebc5180620ea38173afdba23f09ebf6d8b11fa05440b14d23764fca9 getopt_long.c
062bb49fa54839010acd4af113e20f7263dde1c8a2ca359b5fb2661ef9ed9d84a0f7c3bc10c25dcfa10bb3c5a4874588dff636ac43d5dbb3d748d75400756d0b __stack_chk_fail_local.c
+d638cdd02371351190fd0545fb83f44b822fa8c930e9fb47ef93d32a1aaee27641f875e10fa2e9833f1a56dfc2055fb89932a89c88da3e2eb17529bca58f5182 getconf.c
4d92f934d760cf5157d80f19fd766be6b673c65317229b32ac824d9d192f6abcc414e2382b2416dfd5c2f757b46ced98c18e4762bf91f5a48647e0ee61813b06 getent
69f097faa9ccb981e78c3a914ad68a51771637d9aecd2dbc807003ac30663e6d921091a48ff529dfff27a6cd55b0808f91683118acf7acdf406d37266e622b17 ldconfig"
diff --git a/main/musl/getconf.c b/main/musl/getconf.c
new file mode 100644
index 0000000000..67b894f86b
--- /dev/null
+++ b/main/musl/getconf.c
@@ -0,0 +1,323 @@
+/*-
+ * Copyright (c) 1996, 1998 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by J.T. Conklin.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * 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.
+ */
+
+/* Fixed to be used with musl in Alpine Linux by Timo Teräs. */
+
+#include <err.h>
+#include <errno.h>
+#include <limits.h>
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+struct conf_variable
+{
+ const char *name;
+ enum { SYSCONF, CONFSTR, PATHCONF, CONSTANT } 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 */
+ { "_NPROCESSORS_CONF", SYSCONF, _SC_NPROCESSORS_CONF },
+ { "_NPROCESSORS_ONLN", SYSCONF, _SC_NPROCESSORS_ONLN },
+
+ { NULL, CONSTANT, 0L }
+};
+
+static int a_flag = 0; /* list all variables */
+
+static void usage(const char *p)
+{
+ (void)fprintf(stderr, "Usage: %s system_var\n\t%s -a\n"
+ "\t%s path_var pathname\n\t%s -a pathname\n", p, p, p, p);
+ exit(EXIT_FAILURE);
+}
+
+static void print_longvar(const char *name, long value)
+{
+ if (a_flag)
+ (void)printf("%s = %ld\n", name, value);
+ else
+ (void)printf("%ld\n", value);
+}
+
+static void print_strvar(const char *name, const char *sval)
+{
+ if (a_flag)
+ (void)printf("%s = %s\n", name, sval);
+ else
+ (void)printf("%s\n", sval);
+}
+
+static void
+printvar(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");
+ }
+
+ 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;
+ }
+}
+
+int
+main(int argc, char **argv)
+{
+ int ch;
+ const char *progname = argv[0];
+ const struct conf_variable *cp;
+ const char *varname, *pathname;
+ int found;
+
+ (void)setlocale(LC_ALL, "");
+
+ while ((ch = getopt(argc, argv, "a")) != -1) {
+ switch (ch) {
+ case 'a':
+ a_flag = 1;
+ break;
+ case '?':
+ default:
+ usage(progname);
+ }
+ }
+ argc -= optind;
+ argv += optind;
+
+ if (!a_flag) {
+ if (argc == 0)
+ usage(progname);
+ varname = argv[0];
+ argc--;
+ argv++;
+ } else
+ varname = NULL;
+
+ if (argc > 1)
+ 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 (!a_flag && !found)
+ errx(EXIT_FAILURE, "%s: unknown variable", varname);
+
+ (void)fflush(stdout);
+ return ferror(stdout) ? EXIT_FAILURE : EXIT_SUCCESS;
+}