xref: /original-bsd/lib/libc/gen/sysctl.c (revision a4fd107d)
1553bb761Sbostic /*-
2bac379f5Sbostic  * Copyright (c) 1993
3bac379f5Sbostic  *	The Regents of the University of California.  All rights reserved.
4553bb761Sbostic  *
5553bb761Sbostic  * %sccs.include.redist.c%
6553bb761Sbostic  */
7553bb761Sbostic 
8553bb761Sbostic #if defined(LIBC_SCCS) && !defined(lint)
9*a4fd107dSbostic static char sccsid[] = "@(#)sysctl.c	8.2 (Berkeley) 01/04/94";
10553bb761Sbostic #endif /* LIBC_SCCS and not lint */
11553bb761Sbostic 
12553bb761Sbostic #include <sys/param.h>
13553bb761Sbostic #include <sys/sysctl.h>
14553bb761Sbostic 
15553bb761Sbostic #include <errno.h>
16553bb761Sbostic #include <limits.h>
17553bb761Sbostic #include <paths.h>
18c21407a7Sbostic #include <stdio.h>
19553bb761Sbostic #include <unistd.h>
20553bb761Sbostic 
21553bb761Sbostic int
sysctl(name,namelen,oldp,oldlenp,newp,newlen)22553bb761Sbostic sysctl(name, namelen, oldp, oldlenp, newp, newlen)
23553bb761Sbostic 	int *name;
24553bb761Sbostic 	u_int namelen;
25553bb761Sbostic 	void *oldp, *newp;
26553bb761Sbostic 	size_t *oldlenp, newlen;
27553bb761Sbostic {
28553bb761Sbostic 	if (name[0] != CTL_USER)
29553bb761Sbostic 		return (__sysctl(name, namelen, oldp, oldlenp, newp, newlen));
30553bb761Sbostic 
31553bb761Sbostic 	if (newp != NULL) {
32553bb761Sbostic 		errno = EPERM;
33553bb761Sbostic 		return (-1);
34553bb761Sbostic 	}
35553bb761Sbostic 	if (namelen != 2) {
36553bb761Sbostic 		errno = EINVAL;
37553bb761Sbostic 		return (-1);
38553bb761Sbostic 	}
39553bb761Sbostic 
40553bb761Sbostic 	switch (name[1]) {
41553bb761Sbostic 	case USER_CS_PATH:
42553bb761Sbostic 		if (oldp && *oldlenp < sizeof(_PATH_STDPATH))
43553bb761Sbostic 			return (ENOMEM);
44553bb761Sbostic 		*oldlenp = sizeof(_PATH_STDPATH);
45553bb761Sbostic 		if (oldp != NULL)
46553bb761Sbostic 			memmove(oldp, _PATH_STDPATH, sizeof(_PATH_STDPATH));
47553bb761Sbostic 		return (0);
48553bb761Sbostic 	}
49553bb761Sbostic 
50553bb761Sbostic 	if (oldp && *oldlenp < sizeof(int))
51553bb761Sbostic 		return (ENOMEM);
52553bb761Sbostic 	*oldlenp = sizeof(int);
53553bb761Sbostic 	if (oldp == NULL)
54553bb761Sbostic 		return (0);
55553bb761Sbostic 
56553bb761Sbostic 	switch (name[1]) {
57553bb761Sbostic 	case USER_BC_BASE_MAX:
58553bb761Sbostic 		*(int *)oldp = BC_BASE_MAX;
59553bb761Sbostic 		return (0);
60553bb761Sbostic 	case USER_BC_DIM_MAX:
61553bb761Sbostic 		*(int *)oldp = BC_DIM_MAX;
62553bb761Sbostic 		return (0);
63553bb761Sbostic 	case USER_BC_SCALE_MAX:
64553bb761Sbostic 		*(int *)oldp = BC_SCALE_MAX;
65553bb761Sbostic 		return (0);
66553bb761Sbostic 	case USER_BC_STRING_MAX:
67553bb761Sbostic 		*(int *)oldp = BC_STRING_MAX;
68553bb761Sbostic 		return (0);
69553bb761Sbostic 	case USER_COLL_WEIGHTS_MAX:
70553bb761Sbostic 		*(int *)oldp = COLL_WEIGHTS_MAX;
71553bb761Sbostic 		return (0);
72553bb761Sbostic 	case USER_EXPR_NEST_MAX:
73553bb761Sbostic 		*(int *)oldp = EXPR_NEST_MAX;
74553bb761Sbostic 		return (0);
75553bb761Sbostic 	case USER_LINE_MAX:
76553bb761Sbostic 		*(int *)oldp = LINE_MAX;
77553bb761Sbostic 		return (0);
78553bb761Sbostic 	case USER_RE_DUP_MAX:
79553bb761Sbostic 		*(int *)oldp = RE_DUP_MAX;
80553bb761Sbostic 		return (0);
81553bb761Sbostic 	case USER_POSIX2_VERSION:
82553bb761Sbostic 		*(int *)oldp = _POSIX2_VERSION;
83553bb761Sbostic 		return (0);
84553bb761Sbostic 	case USER_POSIX2_C_BIND:
85553bb761Sbostic #ifdef POSIX2_C_BIND
86553bb761Sbostic 		*(int *)oldp = 1;
87553bb761Sbostic #else
88553bb761Sbostic 		*(int *)oldp = 0;
89553bb761Sbostic #endif
90553bb761Sbostic 		return (0);
91553bb761Sbostic 	case USER_POSIX2_C_DEV:
92553bb761Sbostic #ifdef	POSIX2_C_DEV
93553bb761Sbostic 		*(int *)oldp = 1;
94553bb761Sbostic #else
95553bb761Sbostic 		*(int *)oldp = 0;
96553bb761Sbostic #endif
97553bb761Sbostic 		return (0);
98553bb761Sbostic 	case USER_POSIX2_CHAR_TERM:
99553bb761Sbostic #ifdef	POSIX2_CHAR_TERM
100553bb761Sbostic 		*(int *)oldp = 1;
101553bb761Sbostic #else
102553bb761Sbostic 		*(int *)oldp = 0;
103553bb761Sbostic #endif
104553bb761Sbostic 		return (0);
105553bb761Sbostic 	case USER_POSIX2_FORT_DEV:
106553bb761Sbostic #ifdef	POSIX2_FORT_DEV
107553bb761Sbostic 		*(int *)oldp = 1;
108553bb761Sbostic #else
109553bb761Sbostic 		*(int *)oldp = 0;
110553bb761Sbostic #endif
111553bb761Sbostic 		return (0);
112553bb761Sbostic 	case USER_POSIX2_FORT_RUN:
113553bb761Sbostic #ifdef	POSIX2_FORT_RUN
114553bb761Sbostic 		*(int *)oldp = 1;
115553bb761Sbostic #else
116553bb761Sbostic 		*(int *)oldp = 0;
117553bb761Sbostic #endif
118553bb761Sbostic 		return (0);
119553bb761Sbostic 	case USER_POSIX2_LOCALEDEF:
120553bb761Sbostic #ifdef	POSIX2_LOCALEDEF
121553bb761Sbostic 		*(int *)oldp = 1;
122553bb761Sbostic #else
123553bb761Sbostic 		*(int *)oldp = 0;
124553bb761Sbostic #endif
125553bb761Sbostic 		return (0);
126553bb761Sbostic 	case USER_POSIX2_SW_DEV:
127553bb761Sbostic #ifdef	POSIX2_SW_DEV
128553bb761Sbostic 		*(int *)oldp = 1;
129553bb761Sbostic #else
130553bb761Sbostic 		*(int *)oldp = 0;
131553bb761Sbostic #endif
132553bb761Sbostic 		return (0);
133553bb761Sbostic 	case USER_POSIX2_UPE:
134553bb761Sbostic #ifdef	POSIX2_UPE
135553bb761Sbostic 		*(int *)oldp = 1;
136553bb761Sbostic #else
137553bb761Sbostic 		*(int *)oldp = 0;
138553bb761Sbostic #endif
139553bb761Sbostic 		return (0);
140c21407a7Sbostic 	case USER_STREAM_MAX:
141c21407a7Sbostic 		*(int *)oldp = FOPEN_MAX;
142c21407a7Sbostic 		return (0);
143c21407a7Sbostic 	case USER_TZNAME_MAX:
144*a4fd107dSbostic 		*(int *)oldp = NAME_MAX;
145c21407a7Sbostic 		return (0);
146553bb761Sbostic 	default:
147553bb761Sbostic 		errno = EINVAL;
148553bb761Sbostic 		return (-1);
149553bb761Sbostic 	}
150553bb761Sbostic 	/* NOTREACHED */
151553bb761Sbostic }
152