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