Home | History | Annotate | Line # | Download | only in gen
sysconf.c revision 1.33.6.2
      1  1.33.6.2  matt /*	$NetBSD: sysconf.c,v 1.33.6.2 2008/08/06 17:17:05 matt Exp $	*/
      2  1.33.6.2  matt 
      3  1.33.6.2  matt /*-
      4  1.33.6.2  matt  * Copyright (c) 1993
      5  1.33.6.2  matt  *	The Regents of the University of California.  All rights reserved.
      6  1.33.6.2  matt  *
      7  1.33.6.2  matt  * This code is derived from software contributed to Berkeley by
      8  1.33.6.2  matt  * Sean Eric Fagan of Cygnus Support.
      9  1.33.6.2  matt  *
     10  1.33.6.2  matt  * Redistribution and use in source and binary forms, with or without
     11  1.33.6.2  matt  * modification, are permitted provided that the following conditions
     12  1.33.6.2  matt  * are met:
     13  1.33.6.2  matt  * 1. Redistributions of source code must retain the above copyright
     14  1.33.6.2  matt  *    notice, this list of conditions and the following disclaimer.
     15  1.33.6.2  matt  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.33.6.2  matt  *    notice, this list of conditions and the following disclaimer in the
     17  1.33.6.2  matt  *    documentation and/or other materials provided with the distribution.
     18  1.33.6.2  matt  * 3. Neither the name of the University nor the names of its contributors
     19  1.33.6.2  matt  *    may be used to endorse or promote products derived from this software
     20  1.33.6.2  matt  *    without specific prior written permission.
     21  1.33.6.2  matt  *
     22  1.33.6.2  matt  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23  1.33.6.2  matt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  1.33.6.2  matt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  1.33.6.2  matt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26  1.33.6.2  matt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  1.33.6.2  matt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  1.33.6.2  matt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  1.33.6.2  matt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  1.33.6.2  matt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  1.33.6.2  matt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  1.33.6.2  matt  * SUCH DAMAGE.
     33  1.33.6.2  matt  */
     34  1.33.6.2  matt 
     35  1.33.6.2  matt #include <sys/cdefs.h>
     36  1.33.6.2  matt #if defined(LIBC_SCCS) && !defined(lint)
     37  1.33.6.2  matt #if 0
     38  1.33.6.2  matt static char sccsid[] = "@(#)sysconf.c	8.2 (Berkeley) 3/20/94";
     39  1.33.6.2  matt #else
     40  1.33.6.2  matt __RCSID("$NetBSD: sysconf.c,v 1.33.6.2 2008/08/06 17:17:05 matt Exp $");
     41  1.33.6.2  matt #endif
     42  1.33.6.2  matt #endif /* LIBC_SCCS and not lint */
     43  1.33.6.2  matt 
     44  1.33.6.2  matt #include "namespace.h"
     45  1.33.6.2  matt #include <sys/param.h>
     46  1.33.6.2  matt #include <sys/sysctl.h>
     47  1.33.6.2  matt #include <sys/time.h>
     48  1.33.6.2  matt #include <sys/resource.h>
     49  1.33.6.2  matt 
     50  1.33.6.2  matt #include <errno.h>
     51  1.33.6.2  matt #include <limits.h>
     52  1.33.6.2  matt #include <time.h>
     53  1.33.6.2  matt #include <unistd.h>
     54  1.33.6.2  matt #include <paths.h>
     55  1.33.6.2  matt #include <pwd.h>
     56  1.33.6.2  matt 
     57  1.33.6.2  matt #ifdef __weak_alias
     58  1.33.6.2  matt __weak_alias(sysconf,__sysconf)
     59  1.33.6.2  matt #endif
     60  1.33.6.2  matt 
     61  1.33.6.2  matt /*
     62  1.33.6.2  matt  * sysconf --
     63  1.33.6.2  matt  *	get configurable system variables.
     64  1.33.6.2  matt  *
     65  1.33.6.2  matt  * XXX
     66  1.33.6.2  matt  * POSIX 1003.1 (ISO/IEC 9945-1, 4.8.1.3) states that the variable values
     67  1.33.6.2  matt  * not change during the lifetime of the calling process.  This would seem
     68  1.33.6.2  matt  * to require that any change to system limits kill all running processes.
     69  1.33.6.2  matt  * A workaround might be to cache the values when they are first retrieved
     70  1.33.6.2  matt  * and then simply return the cached value on subsequent calls.  This is
     71  1.33.6.2  matt  * less useful than returning up-to-date values, however.
     72  1.33.6.2  matt  */
     73  1.33.6.2  matt long
     74  1.33.6.2  matt sysconf(int name)
     75  1.33.6.2  matt {
     76  1.33.6.2  matt 	struct rlimit rl;
     77  1.33.6.2  matt 	size_t len;
     78  1.33.6.2  matt 	int mib[CTL_MAXNAME], value;
     79  1.33.6.2  matt 	unsigned int mib_len;
     80  1.33.6.2  matt 	struct clockinfo tmpclock;
     81  1.33.6.2  matt 	static int clk_tck;
     82  1.33.6.2  matt 
     83  1.33.6.2  matt 	len = sizeof(value);
     84  1.33.6.2  matt 
     85  1.33.6.2  matt 	/* Default length of the MIB */
     86  1.33.6.2  matt 	mib_len = 2;
     87  1.33.6.2  matt 
     88  1.33.6.2  matt 	switch (name) {
     89  1.33.6.2  matt 
     90  1.33.6.2  matt /* 1003.1 */
     91  1.33.6.2  matt 	case _SC_ARG_MAX:
     92  1.33.6.2  matt 		mib[0] = CTL_KERN;
     93  1.33.6.2  matt 		mib[1] = KERN_ARGMAX;
     94  1.33.6.2  matt 		break;
     95  1.33.6.2  matt 	case _SC_CHILD_MAX:
     96  1.33.6.2  matt 		return (getrlimit(RLIMIT_NPROC, &rl) ? -1 : (long)rl.rlim_cur);
     97  1.33.6.2  matt 	case _O_SC_CLK_TCK:
     98  1.33.6.2  matt 		/*
     99  1.33.6.2  matt 		 * For applications compiled when CLK_TCK was a compile-time
    100  1.33.6.2  matt 		 * constant.
    101  1.33.6.2  matt 		 */
    102  1.33.6.2  matt 		return 100;
    103  1.33.6.2  matt 	case _SC_CLK_TCK:
    104  1.33.6.2  matt 		/*
    105  1.33.6.2  matt 		 * Has to be handled specially because it returns a
    106  1.33.6.2  matt 		 * struct clockinfo instead of an integer. Also, since
    107  1.33.6.2  matt 		 * this might be called often by some things that
    108  1.33.6.2  matt 		 * don't grok CLK_TCK can be a macro expanding to a
    109  1.33.6.2  matt 		 * function, cache the value.
    110  1.33.6.2  matt 		 */
    111  1.33.6.2  matt 		if (clk_tck == 0) {
    112  1.33.6.2  matt 			mib[0] = CTL_KERN;
    113  1.33.6.2  matt 			mib[1] = KERN_CLOCKRATE;
    114  1.33.6.2  matt 			len = sizeof(struct clockinfo);
    115  1.33.6.2  matt 			clk_tck = sysctl(mib, 2, &tmpclock, &len, NULL, 0)
    116  1.33.6.2  matt 			    == -1 ? -1 : tmpclock.hz;
    117  1.33.6.2  matt 		}
    118  1.33.6.2  matt 		return(clk_tck);
    119  1.33.6.2  matt 	case _SC_JOB_CONTROL:
    120  1.33.6.2  matt 		mib[0] = CTL_KERN;
    121  1.33.6.2  matt 		mib[1] = KERN_JOB_CONTROL;
    122  1.33.6.2  matt 		goto yesno;
    123  1.33.6.2  matt 	case _SC_NGROUPS_MAX:
    124  1.33.6.2  matt 		mib[0] = CTL_KERN;
    125  1.33.6.2  matt 		mib[1] = KERN_NGROUPS;
    126  1.33.6.2  matt 		break;
    127  1.33.6.2  matt 	case _SC_OPEN_MAX:
    128  1.33.6.2  matt 		return (getrlimit(RLIMIT_NOFILE, &rl) ? -1 : (long)rl.rlim_cur);
    129  1.33.6.2  matt 	case _SC_STREAM_MAX:
    130  1.33.6.2  matt 		mib[0] = CTL_USER;
    131  1.33.6.2  matt 		mib[1] = USER_STREAM_MAX;
    132  1.33.6.2  matt 		break;
    133  1.33.6.2  matt 	case _SC_TZNAME_MAX:
    134  1.33.6.2  matt 		mib[0] = CTL_USER;
    135  1.33.6.2  matt 		mib[1] = USER_TZNAME_MAX;
    136  1.33.6.2  matt 		break;
    137  1.33.6.2  matt 	case _SC_SAVED_IDS:
    138  1.33.6.2  matt 		mib[0] = CTL_KERN;
    139  1.33.6.2  matt 		mib[1] = KERN_SAVED_IDS;
    140  1.33.6.2  matt 		goto yesno;
    141  1.33.6.2  matt 	case _SC_VERSION:
    142  1.33.6.2  matt 		mib[0] = CTL_KERN;
    143  1.33.6.2  matt 		mib[1] = KERN_POSIX1;
    144  1.33.6.2  matt 		break;
    145  1.33.6.2  matt 
    146  1.33.6.2  matt /* 1003.1b */
    147  1.33.6.2  matt 	case _SC_PAGESIZE:
    148  1.33.6.2  matt 		return _getpagesize();
    149  1.33.6.2  matt 	case _SC_FSYNC:
    150  1.33.6.2  matt 		mib[0] = CTL_KERN;
    151  1.33.6.2  matt 		mib[1] = KERN_FSYNC;
    152  1.33.6.2  matt 		goto yesno;
    153  1.33.6.2  matt 	case _SC_SYNCHRONIZED_IO:
    154  1.33.6.2  matt 		mib[0] = CTL_KERN;
    155  1.33.6.2  matt 		mib[1] = KERN_SYNCHRONIZED_IO;
    156  1.33.6.2  matt 		goto yesno;
    157  1.33.6.2  matt 	case _SC_MAPPED_FILES:
    158  1.33.6.2  matt 		mib[0] = CTL_KERN;
    159  1.33.6.2  matt 		mib[1] = KERN_MAPPED_FILES;
    160  1.33.6.2  matt 		goto yesno;
    161  1.33.6.2  matt 	case _SC_MEMLOCK:
    162  1.33.6.2  matt 		mib[0] = CTL_KERN;
    163  1.33.6.2  matt 		mib[1] = KERN_MEMLOCK;
    164  1.33.6.2  matt 		goto yesno;
    165  1.33.6.2  matt 	case _SC_MEMLOCK_RANGE:
    166  1.33.6.2  matt 		mib[0] = CTL_KERN;
    167  1.33.6.2  matt 		mib[1] = KERN_MEMLOCK_RANGE;
    168  1.33.6.2  matt 		goto yesno;
    169  1.33.6.2  matt 	case _SC_MEMORY_PROTECTION:
    170  1.33.6.2  matt 		mib[0] = CTL_KERN;
    171  1.33.6.2  matt 		mib[1] = KERN_MEMORY_PROTECTION;
    172  1.33.6.2  matt 		goto yesno;
    173  1.33.6.2  matt 	case _SC_MONOTONIC_CLOCK:
    174  1.33.6.2  matt 		mib[0] = CTL_KERN;
    175  1.33.6.2  matt 		mib[1] = KERN_MONOTONIC_CLOCK;
    176  1.33.6.2  matt 		goto yesno;
    177  1.33.6.2  matt 	case _SC_SEMAPHORES:
    178  1.33.6.2  matt 		mib[0] = CTL_KERN;
    179  1.33.6.2  matt 		mib[1] = KERN_POSIX_SEMAPHORES;
    180  1.33.6.2  matt 		goto yesno;
    181  1.33.6.2  matt 	case _SC_TIMERS:
    182  1.33.6.2  matt 		mib[0] = CTL_KERN;
    183  1.33.6.2  matt 		mib[1] = KERN_POSIX_TIMERS;
    184  1.33.6.2  matt 		goto yesno;
    185  1.33.6.2  matt 
    186  1.33.6.2  matt /* 1003.1c */
    187  1.33.6.2  matt 	case _SC_LOGIN_NAME_MAX:
    188  1.33.6.2  matt 		mib[0] = CTL_KERN;
    189  1.33.6.2  matt 		mib[1] = KERN_LOGIN_NAME_MAX;
    190  1.33.6.2  matt 		break;
    191  1.33.6.2  matt 	case _SC_THREADS:
    192  1.33.6.2  matt 		mib[0] = CTL_KERN;
    193  1.33.6.2  matt 		mib[1] = KERN_POSIX_THREADS;
    194  1.33.6.2  matt 		goto yesno;
    195  1.33.6.2  matt 
    196  1.33.6.2  matt /* 1003.1j */
    197  1.33.6.2  matt 	case _SC_BARRIERS:
    198  1.33.6.2  matt 		mib[0] = CTL_KERN;
    199  1.33.6.2  matt 		mib[1] = KERN_POSIX_BARRIERS;
    200  1.33.6.2  matt 		goto yesno;
    201  1.33.6.2  matt 	case _SC_SPIN_LOCKS:
    202  1.33.6.2  matt 		mib[0] = CTL_KERN;
    203  1.33.6.2  matt 		mib[1] = KERN_POSIX_SPIN_LOCKS;
    204  1.33.6.2  matt 		goto yesno;
    205  1.33.6.2  matt 	/* Historical; Threads option in 1003.1-2001 */
    206  1.33.6.2  matt 	case _SC_READER_WRITER_LOCKS:
    207  1.33.6.2  matt 		mib[0] = CTL_KERN;
    208  1.33.6.2  matt 		mib[1] = KERN_POSIX_READER_WRITER_LOCKS;
    209  1.33.6.2  matt 		goto yesno;
    210  1.33.6.2  matt 
    211  1.33.6.2  matt /* 1003.2 */
    212  1.33.6.2  matt 	case _SC_BC_BASE_MAX:
    213  1.33.6.2  matt 		mib[0] = CTL_USER;
    214  1.33.6.2  matt 		mib[1] = USER_BC_BASE_MAX;
    215  1.33.6.2  matt 		break;
    216  1.33.6.2  matt 	case _SC_BC_DIM_MAX:
    217  1.33.6.2  matt 		mib[0] = CTL_USER;
    218  1.33.6.2  matt 		mib[1] = USER_BC_DIM_MAX;
    219  1.33.6.2  matt 		break;
    220  1.33.6.2  matt 	case _SC_BC_SCALE_MAX:
    221  1.33.6.2  matt 		mib[0] = CTL_USER;
    222  1.33.6.2  matt 		mib[1] = USER_BC_SCALE_MAX;
    223  1.33.6.2  matt 		break;
    224  1.33.6.2  matt 	case _SC_BC_STRING_MAX:
    225  1.33.6.2  matt 		mib[0] = CTL_USER;
    226  1.33.6.2  matt 		mib[1] = USER_BC_STRING_MAX;
    227  1.33.6.2  matt 		break;
    228  1.33.6.2  matt 	case _SC_COLL_WEIGHTS_MAX:
    229  1.33.6.2  matt 		mib[0] = CTL_USER;
    230  1.33.6.2  matt 		mib[1] = USER_COLL_WEIGHTS_MAX;
    231  1.33.6.2  matt 		break;
    232  1.33.6.2  matt 	case _SC_EXPR_NEST_MAX:
    233  1.33.6.2  matt 		mib[0] = CTL_USER;
    234  1.33.6.2  matt 		mib[1] = USER_EXPR_NEST_MAX;
    235  1.33.6.2  matt 		break;
    236  1.33.6.2  matt 	case _SC_LINE_MAX:
    237  1.33.6.2  matt 		mib[0] = CTL_USER;
    238  1.33.6.2  matt 		mib[1] = USER_LINE_MAX;
    239  1.33.6.2  matt 		break;
    240  1.33.6.2  matt 	case _SC_RE_DUP_MAX:
    241  1.33.6.2  matt 		mib[0] = CTL_USER;
    242  1.33.6.2  matt 		mib[1] = USER_RE_DUP_MAX;
    243  1.33.6.2  matt 		break;
    244  1.33.6.2  matt 	case _SC_2_VERSION:
    245  1.33.6.2  matt 		mib[0] = CTL_USER;
    246  1.33.6.2  matt 		mib[1] = USER_POSIX2_VERSION;
    247  1.33.6.2  matt 		break;
    248  1.33.6.2  matt 	case _SC_2_C_BIND:
    249  1.33.6.2  matt 		mib[0] = CTL_USER;
    250  1.33.6.2  matt 		mib[1] = USER_POSIX2_C_BIND;
    251  1.33.6.2  matt 		goto yesno;
    252  1.33.6.2  matt 	case _SC_2_C_DEV:
    253  1.33.6.2  matt 		mib[0] = CTL_USER;
    254  1.33.6.2  matt 		mib[1] = USER_POSIX2_C_DEV;
    255  1.33.6.2  matt 		goto yesno;
    256  1.33.6.2  matt 	case _SC_2_CHAR_TERM:
    257  1.33.6.2  matt 		mib[0] = CTL_USER;
    258  1.33.6.2  matt 		mib[1] = USER_POSIX2_CHAR_TERM;
    259  1.33.6.2  matt 		goto yesno;
    260  1.33.6.2  matt 	case _SC_2_FORT_DEV:
    261  1.33.6.2  matt 		mib[0] = CTL_USER;
    262  1.33.6.2  matt 		mib[1] = USER_POSIX2_FORT_DEV;
    263  1.33.6.2  matt 		goto yesno;
    264  1.33.6.2  matt 	case _SC_2_FORT_RUN:
    265  1.33.6.2  matt 		mib[0] = CTL_USER;
    266  1.33.6.2  matt 		mib[1] = USER_POSIX2_FORT_RUN;
    267  1.33.6.2  matt 		goto yesno;
    268  1.33.6.2  matt 	case _SC_2_LOCALEDEF:
    269  1.33.6.2  matt 		mib[0] = CTL_USER;
    270  1.33.6.2  matt 		mib[1] = USER_POSIX2_LOCALEDEF;
    271  1.33.6.2  matt 		goto yesno;
    272  1.33.6.2  matt 	case _SC_2_SW_DEV:
    273  1.33.6.2  matt 		mib[0] = CTL_USER;
    274  1.33.6.2  matt 		mib[1] = USER_POSIX2_SW_DEV;
    275  1.33.6.2  matt 		goto yesno;
    276  1.33.6.2  matt 	case _SC_2_UPE:
    277  1.33.6.2  matt 		mib[0] = CTL_USER;
    278  1.33.6.2  matt 		mib[1] = USER_POSIX2_UPE;
    279  1.33.6.2  matt 		goto yesno;
    280  1.33.6.2  matt 
    281  1.33.6.2  matt /* XPG 4.2 */
    282  1.33.6.2  matt 	case _SC_IOV_MAX:
    283  1.33.6.2  matt 		mib[0] = CTL_KERN;
    284  1.33.6.2  matt 		mib[1] = KERN_IOV_MAX;
    285  1.33.6.2  matt 		break;
    286  1.33.6.2  matt 	case _SC_XOPEN_SHM:
    287  1.33.6.2  matt 		mib[0] = CTL_KERN;
    288  1.33.6.2  matt 		mib[1] = KERN_SYSVIPC;
    289  1.33.6.2  matt 		mib[2] = KERN_SYSVIPC_SHM;
    290  1.33.6.2  matt 		mib_len = 3;
    291  1.33.6.2  matt 		goto yesno;
    292  1.33.6.2  matt 
    293  1.33.6.2  matt /* 1003.1-2001, XSI Option Group */
    294  1.33.6.2  matt 	case _SC_AIO_LISTIO_MAX:
    295  1.33.6.2  matt 		if (sysctlgetmibinfo("kern.aio_listio_max", &mib[0], &mib_len,
    296  1.33.6.2  matt 		    NULL, NULL, NULL, SYSCTL_VERSION))
    297  1.33.6.2  matt 			return -1;
    298  1.33.6.2  matt 		break;
    299  1.33.6.2  matt 	case _SC_AIO_MAX:
    300  1.33.6.2  matt 		if (sysctlgetmibinfo("kern.aio_max", &mib[0], &mib_len,
    301  1.33.6.2  matt 		    NULL, NULL, NULL, SYSCTL_VERSION))
    302  1.33.6.2  matt 			return -1;
    303  1.33.6.2  matt 		break;
    304  1.33.6.2  matt 	case _SC_ASYNCHRONOUS_IO:
    305  1.33.6.2  matt 		if (sysctlgetmibinfo("kern.posix_aio", &mib[0], &mib_len,
    306  1.33.6.2  matt 		    NULL, NULL, NULL, SYSCTL_VERSION))
    307  1.33.6.2  matt 			return -1;
    308  1.33.6.2  matt 		goto yesno;
    309  1.33.6.2  matt 	case _SC_MESSAGE_PASSING:
    310  1.33.6.2  matt 		if (sysctlgetmibinfo("kern.posix_msg", &mib[0], &mib_len,
    311  1.33.6.2  matt 		    NULL, NULL, NULL, SYSCTL_VERSION))
    312  1.33.6.2  matt 			return -1;
    313  1.33.6.2  matt 		goto yesno;
    314  1.33.6.2  matt 	case _SC_MQ_OPEN_MAX:
    315  1.33.6.2  matt 		if (sysctlgetmibinfo("kern.mqueue.mq_open_max", &mib[0],
    316  1.33.6.2  matt 		    &mib_len, NULL, NULL, NULL, SYSCTL_VERSION))
    317  1.33.6.2  matt 			return -1;
    318  1.33.6.2  matt 		break;
    319  1.33.6.2  matt 	case _SC_MQ_PRIO_MAX:
    320  1.33.6.2  matt 		if (sysctlgetmibinfo("kern.mqueue.mq_prio_max", &mib[0],
    321  1.33.6.2  matt 		    &mib_len, NULL, NULL, NULL, SYSCTL_VERSION))
    322  1.33.6.2  matt 			return -1;
    323  1.33.6.2  matt 		break;
    324  1.33.6.2  matt 	case _SC_PRIORITY_SCHEDULING:
    325  1.33.6.2  matt 		if (sysctlgetmibinfo("kern.posix_sched", &mib[0], &mib_len,
    326  1.33.6.2  matt 		    NULL, NULL, NULL, SYSCTL_VERSION))
    327  1.33.6.2  matt 			return -1;
    328  1.33.6.2  matt 		goto yesno;
    329  1.33.6.2  matt 	case _SC_ATEXIT_MAX:
    330  1.33.6.2  matt 		mib[0] = CTL_USER;
    331  1.33.6.2  matt 		mib[1] = USER_ATEXIT_MAX;
    332  1.33.6.2  matt 		break;
    333  1.33.6.2  matt 
    334  1.33.6.2  matt /* 1003.1-2001, TSF */
    335  1.33.6.2  matt 	case _SC_GETGR_R_SIZE_MAX:
    336  1.33.6.2  matt 		return _GETGR_R_SIZE_MAX;
    337  1.33.6.2  matt 	case _SC_GETPW_R_SIZE_MAX:
    338  1.33.6.2  matt 		return _GETPW_R_SIZE_MAX;
    339  1.33.6.2  matt 
    340  1.33.6.2  matt /* Unsorted */
    341  1.33.6.2  matt 	case _SC_HOST_NAME_MAX:
    342  1.33.6.2  matt 		return MAXHOSTNAMELEN;
    343  1.33.6.2  matt 	case _SC_PASS_MAX:
    344  1.33.6.2  matt 		return _PASSWORD_LEN;
    345  1.33.6.2  matt 	case _SC_REGEXP:
    346  1.33.6.2  matt 		return _POSIX_REGEXP;
    347  1.33.6.2  matt 	case _SC_SHELL:
    348  1.33.6.2  matt 		return _POSIX_SHELL;
    349  1.33.6.2  matt 	case _SC_SYMLOOP_MAX:
    350  1.33.6.2  matt 		return MAXSYMLINKS;
    351  1.33.6.2  matt 
    352  1.33.6.2  matt yesno:		if (sysctl(mib, mib_len, &value, &len, NULL, 0) == -1)
    353  1.33.6.2  matt 			return (-1);
    354  1.33.6.2  matt 		if (value == 0)
    355  1.33.6.2  matt 			return (-1);
    356  1.33.6.2  matt 		return (value);
    357  1.33.6.2  matt 
    358  1.33.6.2  matt /* Extensions */
    359  1.33.6.2  matt 	case _SC_NPROCESSORS_CONF:
    360  1.33.6.2  matt 		mib[0] = CTL_HW;
    361  1.33.6.2  matt 		mib[1] = HW_NCPU;
    362  1.33.6.2  matt 		break;
    363  1.33.6.2  matt 	case _SC_NPROCESSORS_ONLN:
    364  1.33.6.2  matt 		mib[0] = CTL_HW;
    365  1.33.6.2  matt 		mib[1] = HW_NCPUONLINE;
    366  1.33.6.2  matt 		break;
    367  1.33.6.2  matt 
    368  1.33.6.2  matt /* Native */
    369  1.33.6.2  matt 	case _SC_SCHED_RT_TS:
    370  1.33.6.2  matt 		if (sysctlgetmibinfo("kern.sched.rtts", &mib[0], &mib_len,
    371  1.33.6.2  matt 		    NULL, NULL, NULL, SYSCTL_VERSION))
    372  1.33.6.2  matt 			return -1;
    373  1.33.6.2  matt 		break;
    374  1.33.6.2  matt 	case _SC_SCHED_PRI_MIN:
    375  1.33.6.2  matt 		if (sysctlgetmibinfo("kern.sched.pri_min", &mib[0], &mib_len,
    376  1.33.6.2  matt 		    NULL, NULL, NULL, SYSCTL_VERSION))
    377  1.33.6.2  matt 			return -1;
    378  1.33.6.2  matt 		break;
    379  1.33.6.2  matt 	case _SC_SCHED_PRI_MAX:
    380  1.33.6.2  matt 		if (sysctlgetmibinfo("kern.sched.pri_max", &mib[0], &mib_len,
    381  1.33.6.2  matt 		    NULL, NULL, NULL, SYSCTL_VERSION))
    382  1.33.6.2  matt 			return -1;
    383  1.33.6.2  matt 		break;
    384  1.33.6.2  matt 	case _SC_THREAD_DESTRUCTOR_ITERATIONS:
    385  1.33.6.2  matt 		return _POSIX_THREAD_DESTRUCTOR_ITERATIONS;
    386  1.33.6.2  matt 	case _SC_THREAD_KEYS_MAX:
    387  1.33.6.2  matt 		return _POSIX_THREAD_KEYS_MAX;
    388  1.33.6.2  matt 	case _SC_THREAD_STACK_MIN:
    389  1.33.6.2  matt 		return _getpagesize();
    390  1.33.6.2  matt 	case _SC_THREAD_THREADS_MAX:
    391  1.33.6.2  matt 		if (sysctlgetmibinfo("kern.maxproc", &mib[0], &mib_len,
    392  1.33.6.2  matt 		    NULL, NULL, NULL, SYSCTL_VERSION))	/* XXX */
    393  1.33.6.2  matt 			return -1;
    394  1.33.6.2  matt 		goto yesno;
    395  1.33.6.2  matt 	case _SC_THREAD_ATTR_STACKADDR:
    396  1.33.6.2  matt 		return _POSIX_THREAD_ATTR_STACKADDR;
    397  1.33.6.2  matt 	case _SC_THREAD_ATTR_STACKSIZE:
    398  1.33.6.2  matt 		return _POSIX_THREAD_ATTR_STACKSIZE;
    399  1.33.6.2  matt 	case _SC_THREAD_SAFE_FUNCTIONS:
    400  1.33.6.2  matt 		return _POSIX_THREAD_SAFE_FUNCTIONS;
    401  1.33.6.2  matt 	case _SC_THREAD_PRIORITY_SCHEDULING:
    402  1.33.6.2  matt 	case _SC_THREAD_PRIO_INHERIT:
    403  1.33.6.2  matt 	case _SC_THREAD_PRIO_PROTECT:
    404  1.33.6.2  matt 	case _SC_THREAD_PROCESS_SHARED:
    405  1.33.6.2  matt 		return -1;
    406  1.33.6.2  matt 	case _SC_TTY_NAME_MAX:
    407  1.33.6.2  matt 		return pathconf(_PATH_DEV, _PC_NAME_MAX);
    408  1.33.6.2  matt 	default:
    409  1.33.6.2  matt 		errno = EINVAL;
    410  1.33.6.2  matt 		return (-1);
    411  1.33.6.2  matt 	}
    412  1.33.6.2  matt 	return (sysctl(mib, mib_len, &value, &len, NULL, 0) == -1 ? -1 : value);
    413  1.33.6.2  matt }
    414