summaryrefslogtreecommitdiff
path: root/system
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2018-06-14 23:54:41 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2018-06-14 23:54:41 -0500
commit4164d8746a2c0f7b74eee372eea20726fcfd9335 (patch)
tree0af703eea3dca93166a8cc375027cfb771fbb188 /system
parent0416daf6d451f879229e5ae32aa007e1252d0983 (diff)
downloadpackages-4164d8746a2c0f7b74eee372eea20726fcfd9335.tar.gz
packages-4164d8746a2c0f7b74eee372eea20726fcfd9335.tar.bz2
packages-4164d8746a2c0f7b74eee372eea20726fcfd9335.tar.xz
packages-4164d8746a2c0f7b74eee372eea20726fcfd9335.zip
system/musl: lots of fixing
Diffstat (limited to 'system')
-rw-r--r--system/musl/APKBUILD62
-rw-r--r--system/musl/getconf.c338
2 files changed, 13 insertions, 387 deletions
diff --git a/system/musl/APKBUILD b/system/musl/APKBUILD
index 47e1b4e0a..a79d842e9 100644
--- a/system/musl/APKBUILD
+++ b/system/musl/APKBUILD
@@ -2,7 +2,7 @@
# Maintainer: A. Wilcox <awilfox@adelielinux.org>
pkgname=musl
pkgver=1.1.19
-pkgrel=5
+pkgrel=6
pkgdesc="System library (libc) implementation"
url="http://www.musl-libc.org/"
arch="all"
@@ -11,7 +11,7 @@ license="MIT"
depends=""
depends_dev="!uclibc-dev"
makedepends="$depends_dev"
-subpackages="$pkgname-dev $pkgname-dbg libc6-compat:compat:noarch"
+subpackages="$pkgname-dev $pkgname-dbg"
case "$BOOTSTRAP" in
nocc) pkgname="musl-dev"; subpackages=""; options="$options !dbg";;
nolibc) ;;
@@ -32,7 +32,6 @@ source="http://www.musl-libc.org/releases/musl-$pkgver.tar.gz
handle-aux-at_base.patch
ldconfig
- __stack_chk_fail_local.c
getent.c
iconv.c
"
@@ -41,17 +40,11 @@ source="http://www.musl-libc.org/releases/musl-$pkgver.tar.gz
# 1.1.15-r4:
# - CVE-2016-8859
-builddir="$srcdir"/musl-$pkgver
-
build() {
cd "$builddir"
[ "$BOOTSTRAP" = "nocc" ] && return 0
- # provide minimal libssp_nonshared.a so we don't need libssp from gcc
- ${CROSS_COMPILE}gcc $CPPFLAGS $CFLAGS -c "$srcdir"/__stack_chk_fail_local.c -o __stack_chk_fail_local.o
- ${CROSS_COMPILE}ar r libssp_nonshared.a __stack_chk_fail_local.o
-
if [ "$BOOTSTRAP" != "nolibc" ]; then
# getconf/getent/iconv
local i
@@ -89,34 +82,30 @@ package() {
mips*) ARCH="mips" ;;
esac
- make ARCH="$ARCH" prefix=/usr DESTDIR="$pkgdir" install-headers || return 1
+ make ARCH="$ARCH" prefix=/usr DESTDIR="$pkgdir" install-headers
else
- make DESTDIR="$pkgdir" install || return 1
-
- cp libssp_nonshared.a "$pkgdir"/usr/lib || return 1
+ make DESTDIR="$pkgdir" install
# make LDSO the be the real file, and libc the symlink
local LDSO=$(make -f Makefile --eval "$(echo -e 'print-ldso:\n\t@echo $$(basename $(LDSO_PATHNAME))')" print-ldso)
- mv -f "$pkgdir"/usr/lib/libc.so "$pkgdir"/lib/"$LDSO" || return 1
- ln -sf "$LDSO" "$pkgdir"/lib/libc.musl-${CARCH}.so.1 || return 1
- ln -sf ../../lib/"$LDSO" "$pkgdir"/usr/lib/libc.so || return 1
- mkdir -p "$pkgdir"/usr/bin || return 1
- ln -sf ../../lib/"$LDSO" "$pkgdir"/usr/bin/ldd || return 1
+ mv -f "$pkgdir"/usr/lib/libc.so "$pkgdir"/lib/"$LDSO"
+ ln -sf "$LDSO" "$pkgdir"/lib/libc.musl-${CARCH}.so.1
+ ln -sf ../../lib/"$LDSO" "$pkgdir"/usr/lib/libc.so
+ mkdir -p "$pkgdir"/usr/bin
+ ln -sf ../../lib/"$LDSO" "$pkgdir"/usr/bin/ldd
fi
- # remove libintl.h, currently we don't want by default any NLS
- # and use GNU gettext where needed. the plan is to migrate to
- # musl gettext() later on as fully as possible.
- rm "$pkgdir"/usr/include/libintl.h || return 1
+ rm "$pkgdir"/usr/include/utmp.h
+ rm "$pkgdir"/usr/include/utmpx.h
}
utils() {
depends="!uclibc-utils scanelf"
replaces="libiconv uclibc-utils"
- license="MIT BSD GPL2+"
+ license="BSD-2-Clause AND GPL-2.0+"
mkdir -p "$subpkgdir"/usr "$subpkgdir"/sbin
- mv "$pkgdir"/usr/bin "$subpkgdir"/usr/ || return 1
+ mv "$pkgdir"/usr/bin "$subpkgdir"/usr/
install -D \
"$builddir"/getent \
@@ -126,30 +115,6 @@ utils() {
install -D -m755 "$srcdir"/ldconfig "$subpkgdir"/sbin
}
-compat() {
- pkgdesc="compatibility libraries for glibc"
-
- mkdir -p "$subpkgdir"/lib
- case "$CARCH" in
- armel) _ld="ld-linux.so.3" ;;
- armhf | armv7) _ld="ld-linux-armhf.so.3" ;;
- aarch64) _ld="ld-linux-aarch64.so.1" ;;
- x86) _ld="ld-linux.so.2" ;;
- x86_64) _ld="ld-linux-x86-64.so.2"
- # go precompiled binary uses /lib64/ld-linux-x86-64.so.2
- # so we add a symlink
- ln -s lib "$subpkgdir"/lib64
- ;;
- mips* | s390*) _ld="ld.so.1" ;;
- ppc64le) _ld="ld64.so.2" ;;
- esac
- ln -sf "/lib/libc.musl-${CARCH}.so.1" "$subpkgdir/lib/$_ld"
-
- for i in libc.so.6 libcrypt.so.1 libm.so.6 libpthread.so.0 librt.so.1 libutil.so.1; do
- ln -sf "/lib/libc.musl-${CARCH}.so.1" "$subpkgdir/lib/$i"
- done
-}
-
sha512sums="abee52d53af4b3c14c9088866c911a24d2b6ef67dc494f38a7a09dfe77250026f77528c24c52469c89cffa8ced2f0fa95badbdcf8d4460c90faba47e3927bcc5 musl-1.1.19.tar.gz
801e0d8adf1ca3bec1c35ce4fe319be7ce7776967630ec27fea39c896dd0e26f047cae34d1b2702e730815789cdc6bd4df526e9078bf68294bcef35a94c498b1 0001-sysconf-Add-_SC_XOPEN_UUCP.patch
5b648ebfdff20f56c6b82b19361a0045a59be8dfef08f8c37f44e0f780ced5e7f3c4fcee12bb25b0cee62edf8c939bc60530550b4a8fcc2c3b1f40c1744f6307 0002-confstr-Add-_CS_POSIX_V7_THREADS_.patch
@@ -163,6 +128,5 @@ d0d0817a4e1d57b74cb442a3bf8d8efe39a23a387275b75cba1b2fa354d8a7dc2fd843b5b67584aa
c34ae0c8c2b05d82bc6bd341ceb29041f6e1a1d2c7b2f4f289ab620288bfb1e1ddabc4cb2fc85220c1fbe735874c38a9b00af636644584c7cd1e895d54564a22 complex-math2.patch
6a7ff16d95b5d1be77e0a0fbb245491817db192176496a57b22ab037637d97a185ea0b0d19da687da66c2a2f5578e4343d230f399d49fe377d8f008410974238 handle-aux-at_base.patch
8d3a2d5315fc56fee7da9abb8b89bb38c6046c33d154c10d168fb35bfde6b0cf9f13042a3bceee34daf091bc409d699223735dcf19f382eeee1f6be34154f26f ldconfig
-062bb49fa54839010acd4af113e20f7263dde1c8a2ca359b5fb2661ef9ed9d84a0f7c3bc10c25dcfa10bb3c5a4874588dff636ac43d5dbb3d748d75400756d0b __stack_chk_fail_local.c
378d70e65bcc65bb4e1415354cecfa54b0c1146dfb24474b69e418cdbf7ad730472cd09f6f103e1c99ba6c324c9560bccdf287f5889bbc3ef0bdf0e08da47413 getent.c
9d42d66fb1facce2b85dad919be5be819ee290bd26ca2db00982b2f8e055a0196290a008711cbe2b18ec9eee8d2270e3b3a4692c5a1b807013baa5c2b70a2bbf iconv.c"
diff --git a/system/musl/getconf.c b/system/musl/getconf.c
deleted file mode 100644
index c4235242b..000000000
--- a/system/musl/getconf.c
+++ /dev/null
@@ -1,338 +0,0 @@
-/*-
- * 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.
- *
- * 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:
- * 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.
- */
-
-#include <err.h>
-#include <errno.h>
-#include <values.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, 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 },
-
-/* 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 all = 0;
-
-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_long(const char *name, long val)
-{
- if (all) printf("%s = %ld\n", name, val);
- else printf("%ld\n", val);
-}
-
-static void print_ulong(const char *name, unsigned long val)
-{
- if (all) printf("%s = %lu\n", name, val);
- else printf("%lu\n", val);
-}
-
-static void print_string(const char *name, const char *val)
-{
- if (all) printf("%s = %s\n", name, val);
- else printf("%s\n", val);
-}
-
-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)
-{
- long val;
-
- 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;
-
- 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;
-}
-
-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)
-{
- const char *progname = argv[0];
- const struct conf_variable *cp;
- const char *varname, *pathname;
- int ch, found = 0;
-
- (void)setlocale(LC_ALL, "");
- while ((ch = getopt(argc, argv, "a")) != -1) {
- switch (ch) {
- case 'a':
- all = 1;
- break;
- case '?':
- default:
- usage(progname);
- }
- }
- argc -= optind;
- argv += optind;
-
- if (!all) {
- if (argc == 0)
- usage(progname);
- varname = argv[0];
- argc--;
- argv++;
- } else
- varname = NULL;
-
- if (argc > 1)
- usage(progname);
- pathname = argv[0]; /* may be NULL */
-
- for (cp = conf_table; cp->name != NULL; cp++) {
- 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 (!all && !found) errx(EXIT_FAILURE, "%s: unknown variable", varname);
- (void)fflush(stdout);
- return ferror(stdout) ? EXIT_FAILURE : EXIT_SUCCESS;
-}