sysctl.c revision 11659
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: 691573Srgrimes if (oldp && *oldlenp < sizeof(_PATH_STDPATH)) 701573Srgrimes return (ENOMEM); 711573Srgrimes *oldlenp = sizeof(_PATH_STDPATH); 721573Srgrimes if (oldp != NULL) 731573Srgrimes memmove(oldp, _PATH_STDPATH, sizeof(_PATH_STDPATH)); 741573Srgrimes return (0); 751573Srgrimes } 761573Srgrimes 771573Srgrimes if (oldp && *oldlenp < sizeof(int)) 781573Srgrimes return (ENOMEM); 791573Srgrimes *oldlenp = sizeof(int); 801573Srgrimes if (oldp == NULL) 811573Srgrimes return (0); 821573Srgrimes 831573Srgrimes switch (name[1]) { 841573Srgrimes case USER_BC_BASE_MAX: 851573Srgrimes *(int *)oldp = BC_BASE_MAX; 861573Srgrimes return (0); 871573Srgrimes case USER_BC_DIM_MAX: 881573Srgrimes *(int *)oldp = BC_DIM_MAX; 891573Srgrimes return (0); 901573Srgrimes case USER_BC_SCALE_MAX: 911573Srgrimes *(int *)oldp = BC_SCALE_MAX; 921573Srgrimes return (0); 931573Srgrimes case USER_BC_STRING_MAX: 941573Srgrimes *(int *)oldp = BC_STRING_MAX; 951573Srgrimes return (0); 961573Srgrimes case USER_COLL_WEIGHTS_MAX: 971573Srgrimes *(int *)oldp = COLL_WEIGHTS_MAX; 981573Srgrimes return (0); 991573Srgrimes case USER_EXPR_NEST_MAX: 1001573Srgrimes *(int *)oldp = EXPR_NEST_MAX; 1011573Srgrimes return (0); 1021573Srgrimes case USER_LINE_MAX: 1031573Srgrimes *(int *)oldp = LINE_MAX; 1041573Srgrimes return (0); 1051573Srgrimes case USER_RE_DUP_MAX: 1061573Srgrimes *(int *)oldp = RE_DUP_MAX; 1071573Srgrimes return (0); 1081573Srgrimes case USER_POSIX2_VERSION: 1091573Srgrimes *(int *)oldp = _POSIX2_VERSION; 1101573Srgrimes return (0); 1111573Srgrimes case USER_POSIX2_C_BIND: 1121573Srgrimes#ifdef POSIX2_C_BIND 1131573Srgrimes *(int *)oldp = 1; 1141573Srgrimes#else 1151573Srgrimes *(int *)oldp = 0; 1161573Srgrimes#endif 1171573Srgrimes return (0); 1181573Srgrimes case USER_POSIX2_C_DEV: 1191573Srgrimes#ifdef POSIX2_C_DEV 1201573Srgrimes *(int *)oldp = 1; 1211573Srgrimes#else 1221573Srgrimes *(int *)oldp = 0; 1231573Srgrimes#endif 1241573Srgrimes return (0); 1251573Srgrimes case USER_POSIX2_CHAR_TERM: 1261573Srgrimes#ifdef POSIX2_CHAR_TERM 1271573Srgrimes *(int *)oldp = 1; 1281573Srgrimes#else 1291573Srgrimes *(int *)oldp = 0; 1301573Srgrimes#endif 1311573Srgrimes return (0); 1321573Srgrimes case USER_POSIX2_FORT_DEV: 1331573Srgrimes#ifdef POSIX2_FORT_DEV 1341573Srgrimes *(int *)oldp = 1; 1351573Srgrimes#else 1361573Srgrimes *(int *)oldp = 0; 1371573Srgrimes#endif 1381573Srgrimes return (0); 1391573Srgrimes case USER_POSIX2_FORT_RUN: 1401573Srgrimes#ifdef POSIX2_FORT_RUN 1411573Srgrimes *(int *)oldp = 1; 1421573Srgrimes#else 1431573Srgrimes *(int *)oldp = 0; 1441573Srgrimes#endif 1451573Srgrimes return (0); 1461573Srgrimes case USER_POSIX2_LOCALEDEF: 1471573Srgrimes#ifdef POSIX2_LOCALEDEF 1481573Srgrimes *(int *)oldp = 1; 1491573Srgrimes#else 1501573Srgrimes *(int *)oldp = 0; 1511573Srgrimes#endif 1521573Srgrimes return (0); 1531573Srgrimes case USER_POSIX2_SW_DEV: 1541573Srgrimes#ifdef POSIX2_SW_DEV 1551573Srgrimes *(int *)oldp = 1; 1561573Srgrimes#else 1571573Srgrimes *(int *)oldp = 0; 1581573Srgrimes#endif 1591573Srgrimes return (0); 1601573Srgrimes case USER_POSIX2_UPE: 1611573Srgrimes#ifdef POSIX2_UPE 1621573Srgrimes *(int *)oldp = 1; 1631573Srgrimes#else 1641573Srgrimes *(int *)oldp = 0; 1651573Srgrimes#endif 1661573Srgrimes return (0); 1671573Srgrimes case USER_STREAM_MAX: 1681573Srgrimes *(int *)oldp = FOPEN_MAX; 1691573Srgrimes return (0); 1701573Srgrimes case USER_TZNAME_MAX: 1711573Srgrimes *(int *)oldp = NAME_MAX; 1721573Srgrimes return (0); 1731573Srgrimes default: 1741573Srgrimes errno = EINVAL; 1751573Srgrimes return (-1); 1761573Srgrimes } 1771573Srgrimes /* NOTREACHED */ 1781573Srgrimes} 179