sysctl.c revision 1.4.4.1 1 /* $NetBSD: sysctl.c,v 1.4.4.1 1996/09/19 20:03:58 jtc Exp $ */
2
3 /*-
4 * Copyright (c) 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
36 #if defined(LIBC_SCCS) && !defined(lint)
37 #if 0
38 static char sccsid[] = "@(#)sysctl.c 8.2 (Berkeley) 1/4/94";
39 #else
40 static char rcsid[] = "$NetBSD: sysctl.c,v 1.4.4.1 1996/09/19 20:03:58 jtc Exp $";
41 #endif
42 #endif /* LIBC_SCCS and not lint */
43
44 #include "namespace.h"
45 #include <sys/param.h>
46 #include <sys/sysctl.h>
47
48 #include <errno.h>
49 #include <limits.h>
50 #include <paths.h>
51 #include <stdio.h>
52 #include <string.h>
53 #include <unistd.h>
54
55 #ifdef __weak_alias
56 __weak_alias(sysctl,_sysctl);
57 #endif
58
59 int
60 sysctl(name, namelen, oldp, oldlenp, newp, newlen)
61 int *name;
62 u_int namelen;
63 void *oldp, *newp;
64 size_t *oldlenp, newlen;
65 {
66 if (name[0] != CTL_USER)
67 return (__sysctl(name, namelen, oldp, oldlenp, newp, newlen));
68
69 if (newp != NULL) {
70 errno = EPERM;
71 return (-1);
72 }
73 if (namelen != 2) {
74 errno = EINVAL;
75 return (-1);
76 }
77
78 switch (name[1]) {
79 case USER_CS_PATH:
80 if (oldp && *oldlenp < sizeof(_PATH_STDPATH))
81 return (ENOMEM);
82 *oldlenp = sizeof(_PATH_STDPATH);
83 if (oldp != NULL)
84 memmove(oldp, _PATH_STDPATH, sizeof(_PATH_STDPATH));
85 return (0);
86 }
87
88 if (oldp && *oldlenp < sizeof(int))
89 return (ENOMEM);
90 *oldlenp = sizeof(int);
91 if (oldp == NULL)
92 return (0);
93
94 switch (name[1]) {
95 case USER_BC_BASE_MAX:
96 *(int *)oldp = BC_BASE_MAX;
97 return (0);
98 case USER_BC_DIM_MAX:
99 *(int *)oldp = BC_DIM_MAX;
100 return (0);
101 case USER_BC_SCALE_MAX:
102 *(int *)oldp = BC_SCALE_MAX;
103 return (0);
104 case USER_BC_STRING_MAX:
105 *(int *)oldp = BC_STRING_MAX;
106 return (0);
107 case USER_COLL_WEIGHTS_MAX:
108 *(int *)oldp = COLL_WEIGHTS_MAX;
109 return (0);
110 case USER_EXPR_NEST_MAX:
111 *(int *)oldp = EXPR_NEST_MAX;
112 return (0);
113 case USER_LINE_MAX:
114 *(int *)oldp = LINE_MAX;
115 return (0);
116 case USER_RE_DUP_MAX:
117 *(int *)oldp = RE_DUP_MAX;
118 return (0);
119 case USER_POSIX2_VERSION:
120 *(int *)oldp = _POSIX2_VERSION;
121 return (0);
122 case USER_POSIX2_C_BIND:
123 #ifdef POSIX2_C_BIND
124 *(int *)oldp = 1;
125 #else
126 *(int *)oldp = 0;
127 #endif
128 return (0);
129 case USER_POSIX2_C_DEV:
130 #ifdef POSIX2_C_DEV
131 *(int *)oldp = 1;
132 #else
133 *(int *)oldp = 0;
134 #endif
135 return (0);
136 case USER_POSIX2_CHAR_TERM:
137 #ifdef POSIX2_CHAR_TERM
138 *(int *)oldp = 1;
139 #else
140 *(int *)oldp = 0;
141 #endif
142 return (0);
143 case USER_POSIX2_FORT_DEV:
144 #ifdef POSIX2_FORT_DEV
145 *(int *)oldp = 1;
146 #else
147 *(int *)oldp = 0;
148 #endif
149 return (0);
150 case USER_POSIX2_FORT_RUN:
151 #ifdef POSIX2_FORT_RUN
152 *(int *)oldp = 1;
153 #else
154 *(int *)oldp = 0;
155 #endif
156 return (0);
157 case USER_POSIX2_LOCALEDEF:
158 #ifdef POSIX2_LOCALEDEF
159 *(int *)oldp = 1;
160 #else
161 *(int *)oldp = 0;
162 #endif
163 return (0);
164 case USER_POSIX2_SW_DEV:
165 #ifdef POSIX2_SW_DEV
166 *(int *)oldp = 1;
167 #else
168 *(int *)oldp = 0;
169 #endif
170 return (0);
171 case USER_POSIX2_UPE:
172 #ifdef POSIX2_UPE
173 *(int *)oldp = 1;
174 #else
175 *(int *)oldp = 0;
176 #endif
177 return (0);
178 case USER_STREAM_MAX:
179 *(int *)oldp = FOPEN_MAX;
180 return (0);
181 case USER_TZNAME_MAX:
182 *(int *)oldp = NAME_MAX;
183 return (0);
184 default:
185 errno = EINVAL;
186 return (-1);
187 }
188 /* NOTREACHED */
189 }
190