1 /*- 2 * Copyright (c) 1993 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #if defined(LIBC_SCCS) && !defined(lint) 9 static char sccsid[] = "@(#)sysctl.c 5.1 (Berkeley) 05/15/93"; 10 #endif /* LIBC_SCCS and not lint */ 11 12 #include <sys/param.h> 13 #include <sys/sysctl.h> 14 15 #include <errno.h> 16 #include <limits.h> 17 #include <paths.h> 18 #include <unistd.h> 19 20 int 21 sysctl(name, namelen, oldp, oldlenp, newp, newlen) 22 int *name; 23 u_int namelen; 24 void *oldp, *newp; 25 size_t *oldlenp, newlen; 26 { 27 if (name[0] != CTL_USER) 28 return (__sysctl(name, namelen, oldp, oldlenp, newp, newlen)); 29 30 if (newp != NULL) { 31 errno = EPERM; 32 return (-1); 33 } 34 if (namelen != 2) { 35 errno = EINVAL; 36 return (-1); 37 } 38 39 switch (name[1]) { 40 case USER_CS_PATH: 41 if (oldp && *oldlenp < sizeof(_PATH_STDPATH)) 42 return (ENOMEM); 43 *oldlenp = sizeof(_PATH_STDPATH); 44 if (oldp != NULL) 45 memmove(oldp, _PATH_STDPATH, sizeof(_PATH_STDPATH)); 46 return (0); 47 } 48 49 if (oldp && *oldlenp < sizeof(int)) 50 return (ENOMEM); 51 *oldlenp = sizeof(int); 52 if (oldp == NULL) 53 return (0); 54 55 switch (name[1]) { 56 case USER_BC_BASE_MAX: 57 *(int *)oldp = BC_BASE_MAX; 58 return (0); 59 case USER_BC_DIM_MAX: 60 *(int *)oldp = BC_DIM_MAX; 61 return (0); 62 case USER_BC_SCALE_MAX: 63 *(int *)oldp = BC_SCALE_MAX; 64 return (0); 65 case USER_BC_STRING_MAX: 66 *(int *)oldp = BC_STRING_MAX; 67 return (0); 68 case USER_COLL_WEIGHTS_MAX: 69 *(int *)oldp = COLL_WEIGHTS_MAX; 70 return (0); 71 case USER_EXPR_NEST_MAX: 72 *(int *)oldp = EXPR_NEST_MAX; 73 return (0); 74 case USER_LINE_MAX: 75 *(int *)oldp = LINE_MAX; 76 return (0); 77 case USER_RE_DUP_MAX: 78 *(int *)oldp = RE_DUP_MAX; 79 return (0); 80 case USER_POSIX2_VERSION: 81 *(int *)oldp = _POSIX2_VERSION; 82 return (0); 83 case USER_POSIX2_C_BIND: 84 #ifdef POSIX2_C_BIND 85 *(int *)oldp = 1; 86 #else 87 *(int *)oldp = 0; 88 #endif 89 return (0); 90 case USER_POSIX2_C_DEV: 91 #ifdef POSIX2_C_DEV 92 *(int *)oldp = 1; 93 #else 94 *(int *)oldp = 0; 95 #endif 96 return (0); 97 case USER_POSIX2_CHAR_TERM: 98 #ifdef POSIX2_CHAR_TERM 99 *(int *)oldp = 1; 100 #else 101 *(int *)oldp = 0; 102 #endif 103 return (0); 104 case USER_POSIX2_FORT_DEV: 105 #ifdef POSIX2_FORT_DEV 106 *(int *)oldp = 1; 107 #else 108 *(int *)oldp = 0; 109 #endif 110 return (0); 111 case USER_POSIX2_FORT_RUN: 112 #ifdef POSIX2_FORT_RUN 113 *(int *)oldp = 1; 114 #else 115 *(int *)oldp = 0; 116 #endif 117 return (0); 118 case USER_POSIX2_LOCALEDEF: 119 #ifdef POSIX2_LOCALEDEF 120 *(int *)oldp = 1; 121 #else 122 *(int *)oldp = 0; 123 #endif 124 return (0); 125 case USER_POSIX2_SW_DEV: 126 #ifdef POSIX2_SW_DEV 127 *(int *)oldp = 1; 128 #else 129 *(int *)oldp = 0; 130 #endif 131 return (0); 132 case USER_POSIX2_UPE: 133 #ifdef POSIX2_UPE 134 *(int *)oldp = 1; 135 #else 136 *(int *)oldp = 0; 137 #endif 138 return (0); 139 default: 140 errno = EINVAL; 141 return (-1); 142 } 143 /* NOTREACHED */ 144 } 145