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