160021Sbostic /*- 2*61111Sbostic * Copyright (c) 1993 3*61111Sbostic * The Regents of the University of California. All rights reserved. 460021Sbostic * 560021Sbostic * %sccs.include.redist.c% 660021Sbostic */ 760021Sbostic 860021Sbostic #if defined(LIBC_SCCS) && !defined(lint) 9*61111Sbostic static char sccsid[] = "@(#)sysctl.c 8.1 (Berkeley) 06/04/93"; 1060021Sbostic #endif /* LIBC_SCCS and not lint */ 1160021Sbostic 1260021Sbostic #include <sys/param.h> 1360021Sbostic #include <sys/sysctl.h> 1460021Sbostic 1560021Sbostic #include <errno.h> 1660021Sbostic #include <limits.h> 1760021Sbostic #include <paths.h> 1860272Sbostic #include <stdio.h> 1960021Sbostic #include <unistd.h> 2060021Sbostic 2160021Sbostic int 2260021Sbostic sysctl(name, namelen, oldp, oldlenp, newp, newlen) 2360021Sbostic int *name; 2460021Sbostic u_int namelen; 2560021Sbostic void *oldp, *newp; 2660021Sbostic size_t *oldlenp, newlen; 2760021Sbostic { 2860021Sbostic if (name[0] != CTL_USER) 2960021Sbostic return (__sysctl(name, namelen, oldp, oldlenp, newp, newlen)); 3060021Sbostic 3160021Sbostic if (newp != NULL) { 3260021Sbostic errno = EPERM; 3360021Sbostic return (-1); 3460021Sbostic } 3560021Sbostic if (namelen != 2) { 3660021Sbostic errno = EINVAL; 3760021Sbostic return (-1); 3860021Sbostic } 3960021Sbostic 4060021Sbostic switch (name[1]) { 4160021Sbostic case USER_CS_PATH: 4260021Sbostic if (oldp && *oldlenp < sizeof(_PATH_STDPATH)) 4360021Sbostic return (ENOMEM); 4460021Sbostic *oldlenp = sizeof(_PATH_STDPATH); 4560021Sbostic if (oldp != NULL) 4660021Sbostic memmove(oldp, _PATH_STDPATH, sizeof(_PATH_STDPATH)); 4760021Sbostic return (0); 4860021Sbostic } 4960021Sbostic 5060021Sbostic if (oldp && *oldlenp < sizeof(int)) 5160021Sbostic return (ENOMEM); 5260021Sbostic *oldlenp = sizeof(int); 5360021Sbostic if (oldp == NULL) 5460021Sbostic return (0); 5560021Sbostic 5660021Sbostic switch (name[1]) { 5760021Sbostic case USER_BC_BASE_MAX: 5860021Sbostic *(int *)oldp = BC_BASE_MAX; 5960021Sbostic return (0); 6060021Sbostic case USER_BC_DIM_MAX: 6160021Sbostic *(int *)oldp = BC_DIM_MAX; 6260021Sbostic return (0); 6360021Sbostic case USER_BC_SCALE_MAX: 6460021Sbostic *(int *)oldp = BC_SCALE_MAX; 6560021Sbostic return (0); 6660021Sbostic case USER_BC_STRING_MAX: 6760021Sbostic *(int *)oldp = BC_STRING_MAX; 6860021Sbostic return (0); 6960021Sbostic case USER_COLL_WEIGHTS_MAX: 7060021Sbostic *(int *)oldp = COLL_WEIGHTS_MAX; 7160021Sbostic return (0); 7260021Sbostic case USER_EXPR_NEST_MAX: 7360021Sbostic *(int *)oldp = EXPR_NEST_MAX; 7460021Sbostic return (0); 7560021Sbostic case USER_LINE_MAX: 7660021Sbostic *(int *)oldp = LINE_MAX; 7760021Sbostic return (0); 7860021Sbostic case USER_RE_DUP_MAX: 7960021Sbostic *(int *)oldp = RE_DUP_MAX; 8060021Sbostic return (0); 8160021Sbostic case USER_POSIX2_VERSION: 8260021Sbostic *(int *)oldp = _POSIX2_VERSION; 8360021Sbostic return (0); 8460021Sbostic case USER_POSIX2_C_BIND: 8560021Sbostic #ifdef POSIX2_C_BIND 8660021Sbostic *(int *)oldp = 1; 8760021Sbostic #else 8860021Sbostic *(int *)oldp = 0; 8960021Sbostic #endif 9060021Sbostic return (0); 9160021Sbostic case USER_POSIX2_C_DEV: 9260021Sbostic #ifdef POSIX2_C_DEV 9360021Sbostic *(int *)oldp = 1; 9460021Sbostic #else 9560021Sbostic *(int *)oldp = 0; 9660021Sbostic #endif 9760021Sbostic return (0); 9860021Sbostic case USER_POSIX2_CHAR_TERM: 9960021Sbostic #ifdef POSIX2_CHAR_TERM 10060021Sbostic *(int *)oldp = 1; 10160021Sbostic #else 10260021Sbostic *(int *)oldp = 0; 10360021Sbostic #endif 10460021Sbostic return (0); 10560021Sbostic case USER_POSIX2_FORT_DEV: 10660021Sbostic #ifdef POSIX2_FORT_DEV 10760021Sbostic *(int *)oldp = 1; 10860021Sbostic #else 10960021Sbostic *(int *)oldp = 0; 11060021Sbostic #endif 11160021Sbostic return (0); 11260021Sbostic case USER_POSIX2_FORT_RUN: 11360021Sbostic #ifdef POSIX2_FORT_RUN 11460021Sbostic *(int *)oldp = 1; 11560021Sbostic #else 11660021Sbostic *(int *)oldp = 0; 11760021Sbostic #endif 11860021Sbostic return (0); 11960021Sbostic case USER_POSIX2_LOCALEDEF: 12060021Sbostic #ifdef POSIX2_LOCALEDEF 12160021Sbostic *(int *)oldp = 1; 12260021Sbostic #else 12360021Sbostic *(int *)oldp = 0; 12460021Sbostic #endif 12560021Sbostic return (0); 12660021Sbostic case USER_POSIX2_SW_DEV: 12760021Sbostic #ifdef POSIX2_SW_DEV 12860021Sbostic *(int *)oldp = 1; 12960021Sbostic #else 13060021Sbostic *(int *)oldp = 0; 13160021Sbostic #endif 13260021Sbostic return (0); 13360021Sbostic case USER_POSIX2_UPE: 13460021Sbostic #ifdef POSIX2_UPE 13560021Sbostic *(int *)oldp = 1; 13660021Sbostic #else 13760021Sbostic *(int *)oldp = 0; 13860021Sbostic #endif 13960021Sbostic return (0); 14060272Sbostic case USER_STREAM_MAX: 14160272Sbostic *(int *)oldp = FOPEN_MAX; 14260272Sbostic return (0); 14360272Sbostic case USER_TZNAME_MAX: 14460272Sbostic *(int *)oldp = 1024; 14560272Sbostic return (0); 14660021Sbostic default: 14760021Sbostic errno = EINVAL; 14860021Sbostic return (-1); 14960021Sbostic } 15060021Sbostic /* NOTREACHED */ 15160021Sbostic } 152