sysctl.c revision 42353
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> 4611659Sphk#include <string.h> 471573Srgrimes 481573Srgrimesint 491573Srgrimessysctl(name, namelen, oldp, oldlenp, newp, newlen) 501573Srgrimes int *name; 511573Srgrimes u_int namelen; 521573Srgrimes void *oldp, *newp; 531573Srgrimes size_t *oldlenp, newlen; 541573Srgrimes{ 551573Srgrimes if (name[0] != CTL_USER) 561573Srgrimes return (__sysctl(name, namelen, oldp, oldlenp, newp, newlen)); 571573Srgrimes 581573Srgrimes if (newp != NULL) { 591573Srgrimes errno = EPERM; 601573Srgrimes return (-1); 611573Srgrimes } 621573Srgrimes if (namelen != 2) { 631573Srgrimes errno = EINVAL; 641573Srgrimes return (-1); 651573Srgrimes } 661573Srgrimes 671573Srgrimes switch (name[1]) { 681573Srgrimes case USER_CS_PATH: 6942353Sdes if (oldp && *oldlenp < sizeof(_PATH_STDPATH)) { 7042353Sdes errno = ENOMEM; 7142353Sdes return -1; 7242353Sdes } 731573Srgrimes *oldlenp = sizeof(_PATH_STDPATH); 741573Srgrimes if (oldp != NULL) 751573Srgrimes memmove(oldp, _PATH_STDPATH, sizeof(_PATH_STDPATH)); 761573Srgrimes return (0); 771573Srgrimes } 781573Srgrimes 7942353Sdes if (oldp && *oldlenp < sizeof(int)) { 8042353Sdes errno = ENOMEM; 8142353Sdes return (-1); 8242353Sdes } 831573Srgrimes *oldlenp = sizeof(int); 841573Srgrimes if (oldp == NULL) 851573Srgrimes return (0); 861573Srgrimes 871573Srgrimes switch (name[1]) { 881573Srgrimes case USER_BC_BASE_MAX: 891573Srgrimes *(int *)oldp = BC_BASE_MAX; 901573Srgrimes return (0); 911573Srgrimes case USER_BC_DIM_MAX: 921573Srgrimes *(int *)oldp = BC_DIM_MAX; 931573Srgrimes return (0); 941573Srgrimes case USER_BC_SCALE_MAX: 951573Srgrimes *(int *)oldp = BC_SCALE_MAX; 961573Srgrimes return (0); 971573Srgrimes case USER_BC_STRING_MAX: 981573Srgrimes *(int *)oldp = BC_STRING_MAX; 991573Srgrimes return (0); 1001573Srgrimes case USER_COLL_WEIGHTS_MAX: 1011573Srgrimes *(int *)oldp = COLL_WEIGHTS_MAX; 1021573Srgrimes return (0); 1031573Srgrimes case USER_EXPR_NEST_MAX: 1041573Srgrimes *(int *)oldp = EXPR_NEST_MAX; 1051573Srgrimes return (0); 1061573Srgrimes case USER_LINE_MAX: 1071573Srgrimes *(int *)oldp = LINE_MAX; 1081573Srgrimes return (0); 1091573Srgrimes case USER_RE_DUP_MAX: 1101573Srgrimes *(int *)oldp = RE_DUP_MAX; 1111573Srgrimes return (0); 1121573Srgrimes case USER_POSIX2_VERSION: 1131573Srgrimes *(int *)oldp = _POSIX2_VERSION; 1141573Srgrimes return (0); 1151573Srgrimes case USER_POSIX2_C_BIND: 1161573Srgrimes#ifdef POSIX2_C_BIND 1171573Srgrimes *(int *)oldp = 1; 1181573Srgrimes#else 1191573Srgrimes *(int *)oldp = 0; 1201573Srgrimes#endif 1211573Srgrimes return (0); 1221573Srgrimes case USER_POSIX2_C_DEV: 1231573Srgrimes#ifdef POSIX2_C_DEV 1241573Srgrimes *(int *)oldp = 1; 1251573Srgrimes#else 1261573Srgrimes *(int *)oldp = 0; 1271573Srgrimes#endif 1281573Srgrimes return (0); 1291573Srgrimes case USER_POSIX2_CHAR_TERM: 1301573Srgrimes#ifdef POSIX2_CHAR_TERM 1311573Srgrimes *(int *)oldp = 1; 1321573Srgrimes#else 1331573Srgrimes *(int *)oldp = 0; 1341573Srgrimes#endif 1351573Srgrimes return (0); 1361573Srgrimes case USER_POSIX2_FORT_DEV: 1371573Srgrimes#ifdef POSIX2_FORT_DEV 1381573Srgrimes *(int *)oldp = 1; 1391573Srgrimes#else 1401573Srgrimes *(int *)oldp = 0; 1411573Srgrimes#endif 1421573Srgrimes return (0); 1431573Srgrimes case USER_POSIX2_FORT_RUN: 1441573Srgrimes#ifdef POSIX2_FORT_RUN 1451573Srgrimes *(int *)oldp = 1; 1461573Srgrimes#else 1471573Srgrimes *(int *)oldp = 0; 1481573Srgrimes#endif 1491573Srgrimes return (0); 1501573Srgrimes case USER_POSIX2_LOCALEDEF: 1511573Srgrimes#ifdef POSIX2_LOCALEDEF 1521573Srgrimes *(int *)oldp = 1; 1531573Srgrimes#else 1541573Srgrimes *(int *)oldp = 0; 1551573Srgrimes#endif 1561573Srgrimes return (0); 1571573Srgrimes case USER_POSIX2_SW_DEV: 1581573Srgrimes#ifdef POSIX2_SW_DEV 1591573Srgrimes *(int *)oldp = 1; 1601573Srgrimes#else 1611573Srgrimes *(int *)oldp = 0; 1621573Srgrimes#endif 1631573Srgrimes return (0); 1641573Srgrimes case USER_POSIX2_UPE: 1651573Srgrimes#ifdef POSIX2_UPE 1661573Srgrimes *(int *)oldp = 1; 1671573Srgrimes#else 1681573Srgrimes *(int *)oldp = 0; 1691573Srgrimes#endif 1701573Srgrimes return (0); 1711573Srgrimes case USER_STREAM_MAX: 1721573Srgrimes *(int *)oldp = FOPEN_MAX; 1731573Srgrimes return (0); 1741573Srgrimes case USER_TZNAME_MAX: 1751573Srgrimes *(int *)oldp = NAME_MAX; 1761573Srgrimes return (0); 1771573Srgrimes default: 1781573Srgrimes errno = EINVAL; 1791573Srgrimes return (-1); 1801573Srgrimes } 1811573Srgrimes /* NOTREACHED */ 1821573Srgrimes} 183