sysctl.c revision 1573
11573Srgrimes/*-
21573Srgrimes * Copyright (c) 1993
31573Srgrimes *	The Regents of the University of California.  All rights reserved.
41573Srgrimes *
51573Srgrimes * Redistribution and use in source and binary forms, with or without
61573Srgrimes * modification, are permitted provided that the following conditions
71573Srgrimes * are met:
81573Srgrimes * 1. Redistributions of source code must retain the above copyright
91573Srgrimes *    notice, this list of conditions and the following disclaimer.
101573Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111573Srgrimes *    notice, this list of conditions and the following disclaimer in the
121573Srgrimes *    documentation and/or other materials provided with the distribution.
131573Srgrimes * 3. All advertising materials mentioning features or use of this software
141573Srgrimes *    must display the following acknowledgement:
151573Srgrimes *	This product includes software developed by the University of
161573Srgrimes *	California, Berkeley and its contributors.
171573Srgrimes * 4. Neither the name of the University nor the names of its contributors
181573Srgrimes *    may be used to endorse or promote products derived from this software
191573Srgrimes *    without specific prior written permission.
201573Srgrimes *
211573Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221573Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231573Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241573Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251573Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261573Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271573Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281573Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291573Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301573Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311573Srgrimes * SUCH DAMAGE.
321573Srgrimes */
331573Srgrimes
341573Srgrimes#if defined(LIBC_SCCS) && !defined(lint)
351573Srgrimesstatic char sccsid[] = "@(#)sysctl.c	8.2 (Berkeley) 1/4/94";
361573Srgrimes#endif /* LIBC_SCCS and not lint */
371573Srgrimes
381573Srgrimes#include <sys/param.h>
391573Srgrimes#include <sys/sysctl.h>
401573Srgrimes
411573Srgrimes#include <errno.h>
421573Srgrimes#include <limits.h>
431573Srgrimes#include <paths.h>
441573Srgrimes#include <stdio.h>
451573Srgrimes#include <unistd.h>
461573Srgrimes
471573Srgrimesint
481573Srgrimessysctl(name, namelen, oldp, oldlenp, newp, newlen)
491573Srgrimes	int *name;
501573Srgrimes	u_int namelen;
511573Srgrimes	void *oldp, *newp;
521573Srgrimes	size_t *oldlenp, newlen;
531573Srgrimes{
541573Srgrimes	if (name[0] != CTL_USER)
551573Srgrimes		return (__sysctl(name, namelen, oldp, oldlenp, newp, newlen));
561573Srgrimes
571573Srgrimes	if (newp != NULL) {
581573Srgrimes		errno = EPERM;
591573Srgrimes		return (-1);
601573Srgrimes	}
611573Srgrimes	if (namelen != 2) {
621573Srgrimes		errno = EINVAL;
631573Srgrimes		return (-1);
641573Srgrimes	}
651573Srgrimes
661573Srgrimes	switch (name[1]) {
671573Srgrimes	case USER_CS_PATH:
681573Srgrimes		if (oldp && *oldlenp < sizeof(_PATH_STDPATH))
691573Srgrimes			return (ENOMEM);
701573Srgrimes		*oldlenp = sizeof(_PATH_STDPATH);
711573Srgrimes		if (oldp != NULL)
721573Srgrimes			memmove(oldp, _PATH_STDPATH, sizeof(_PATH_STDPATH));
731573Srgrimes		return (0);
741573Srgrimes	}
751573Srgrimes
761573Srgrimes	if (oldp && *oldlenp < sizeof(int))
771573Srgrimes		return (ENOMEM);
781573Srgrimes	*oldlenp = sizeof(int);
791573Srgrimes	if (oldp == NULL)
801573Srgrimes		return (0);
811573Srgrimes
821573Srgrimes	switch (name[1]) {
831573Srgrimes	case USER_BC_BASE_MAX:
841573Srgrimes		*(int *)oldp = BC_BASE_MAX;
851573Srgrimes		return (0);
861573Srgrimes	case USER_BC_DIM_MAX:
871573Srgrimes		*(int *)oldp = BC_DIM_MAX;
881573Srgrimes		return (0);
891573Srgrimes	case USER_BC_SCALE_MAX:
901573Srgrimes		*(int *)oldp = BC_SCALE_MAX;
911573Srgrimes		return (0);
921573Srgrimes	case USER_BC_STRING_MAX:
931573Srgrimes		*(int *)oldp = BC_STRING_MAX;
941573Srgrimes		return (0);
951573Srgrimes	case USER_COLL_WEIGHTS_MAX:
961573Srgrimes		*(int *)oldp = COLL_WEIGHTS_MAX;
971573Srgrimes		return (0);
981573Srgrimes	case USER_EXPR_NEST_MAX:
991573Srgrimes		*(int *)oldp = EXPR_NEST_MAX;
1001573Srgrimes		return (0);
1011573Srgrimes	case USER_LINE_MAX:
1021573Srgrimes		*(int *)oldp = LINE_MAX;
1031573Srgrimes		return (0);
1041573Srgrimes	case USER_RE_DUP_MAX:
1051573Srgrimes		*(int *)oldp = RE_DUP_MAX;
1061573Srgrimes		return (0);
1071573Srgrimes	case USER_POSIX2_VERSION:
1081573Srgrimes		*(int *)oldp = _POSIX2_VERSION;
1091573Srgrimes		return (0);
1101573Srgrimes	case USER_POSIX2_C_BIND:
1111573Srgrimes#ifdef POSIX2_C_BIND
1121573Srgrimes		*(int *)oldp = 1;
1131573Srgrimes#else
1141573Srgrimes		*(int *)oldp = 0;
1151573Srgrimes#endif
1161573Srgrimes		return (0);
1171573Srgrimes	case USER_POSIX2_C_DEV:
1181573Srgrimes#ifdef	POSIX2_C_DEV
1191573Srgrimes		*(int *)oldp = 1;
1201573Srgrimes#else
1211573Srgrimes		*(int *)oldp = 0;
1221573Srgrimes#endif
1231573Srgrimes		return (0);
1241573Srgrimes	case USER_POSIX2_CHAR_TERM:
1251573Srgrimes#ifdef	POSIX2_CHAR_TERM
1261573Srgrimes		*(int *)oldp = 1;
1271573Srgrimes#else
1281573Srgrimes		*(int *)oldp = 0;
1291573Srgrimes#endif
1301573Srgrimes		return (0);
1311573Srgrimes	case USER_POSIX2_FORT_DEV:
1321573Srgrimes#ifdef	POSIX2_FORT_DEV
1331573Srgrimes		*(int *)oldp = 1;
1341573Srgrimes#else
1351573Srgrimes		*(int *)oldp = 0;
1361573Srgrimes#endif
1371573Srgrimes		return (0);
1381573Srgrimes	case USER_POSIX2_FORT_RUN:
1391573Srgrimes#ifdef	POSIX2_FORT_RUN
1401573Srgrimes		*(int *)oldp = 1;
1411573Srgrimes#else
1421573Srgrimes		*(int *)oldp = 0;
1431573Srgrimes#endif
1441573Srgrimes		return (0);
1451573Srgrimes	case USER_POSIX2_LOCALEDEF:
1461573Srgrimes#ifdef	POSIX2_LOCALEDEF
1471573Srgrimes		*(int *)oldp = 1;
1481573Srgrimes#else
1491573Srgrimes		*(int *)oldp = 0;
1501573Srgrimes#endif
1511573Srgrimes		return (0);
1521573Srgrimes	case USER_POSIX2_SW_DEV:
1531573Srgrimes#ifdef	POSIX2_SW_DEV
1541573Srgrimes		*(int *)oldp = 1;
1551573Srgrimes#else
1561573Srgrimes		*(int *)oldp = 0;
1571573Srgrimes#endif
1581573Srgrimes		return (0);
1591573Srgrimes	case USER_POSIX2_UPE:
1601573Srgrimes#ifdef	POSIX2_UPE
1611573Srgrimes		*(int *)oldp = 1;
1621573Srgrimes#else
1631573Srgrimes		*(int *)oldp = 0;
1641573Srgrimes#endif
1651573Srgrimes		return (0);
1661573Srgrimes	case USER_STREAM_MAX:
1671573Srgrimes		*(int *)oldp = FOPEN_MAX;
1681573Srgrimes		return (0);
1691573Srgrimes	case USER_TZNAME_MAX:
1701573Srgrimes		*(int *)oldp = NAME_MAX;
1711573Srgrimes		return (0);
1721573Srgrimes	default:
1731573Srgrimes		errno = EINVAL;
1741573Srgrimes		return (-1);
1751573Srgrimes	}
1761573Srgrimes	/* NOTREACHED */
1771573Srgrimes}
178