3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
6 * Sean Eric Fagan of Cygnus Support.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 #if defined(LIBC_SCCS) && !defined(lint)
38 static char sccsid[] = "@(#)sysconf.c 8.2 (Berkeley) 3/20/94";
39 #endif /* LIBC_SCCS and not lint */
41 #include <sys/_posix.h>
42 #include <sys/param.h>
44 #include <sys/sysctl.h>
45 #include <sys/resource.h>
53 * get configurable system variables.
56 * POSIX 1003.1 (ISO/IEC 9945-1, 4.8.1.3) states that the variable values
57 * not change during the lifetime of the calling process. This would seem
58 * to require that any change to system limits kill all running processes.
59 * A workaround might be to cache the values when they are first retrieved
60 * and then simply return the cached value on subsequent calls. This is
61 * less useful than returning up-to-date values, however.
82 return (getrlimit(RLIMIT_NPROC, &rl) ? -1 : rl.rlim_cur);
87 mib[1] = KERN_JOB_CONTROL;
91 mib[1] = KERN_NGROUPS;
94 return (getrlimit(RLIMIT_NOFILE, &rl) ? -1 : rl.rlim_cur);
97 mib[1] = USER_STREAM_MAX;
101 mib[1] = USER_TZNAME_MAX;
105 mib[1] = KERN_SAVED_IDS;
109 mib[1] = KERN_POSIX1;
113 case _SC_BC_BASE_MAX:
115 mib[1] = USER_BC_BASE_MAX;
119 mib[1] = USER_BC_DIM_MAX;
121 case _SC_BC_SCALE_MAX:
123 mib[1] = USER_BC_SCALE_MAX;
125 case _SC_BC_STRING_MAX:
127 mib[1] = USER_BC_STRING_MAX;
129 case _SC_COLL_WEIGHTS_MAX:
131 mib[1] = USER_COLL_WEIGHTS_MAX;
133 case _SC_EXPR_NEST_MAX:
135 mib[1] = USER_EXPR_NEST_MAX;
139 mib[1] = USER_LINE_MAX;
143 mib[1] = USER_RE_DUP_MAX;
147 mib[1] = USER_POSIX2_VERSION;
151 mib[1] = USER_POSIX2_C_BIND;
155 mib[1] = USER_POSIX2_C_DEV;
157 case _SC_2_CHAR_TERM:
159 mib[1] = USER_POSIX2_CHAR_TERM;
163 mib[1] = USER_POSIX2_FORT_DEV;
167 mib[1] = USER_POSIX2_FORT_RUN;
169 case _SC_2_LOCALEDEF:
171 mib[1] = USER_POSIX2_LOCALEDEF;
175 mib[1] = USER_POSIX2_SW_DEV;
179 mib[1] = USER_POSIX2_UPE;
182 #ifdef _P1003_1B_VISIBLE
185 case _SC_ASYNCHRONOUS_IO:
186 mib[0] = CTL_P1003_1B;
187 mib[1] = CTL_P1003_1B_ASYNCHRONOUS_IO;
189 case _SC_MAPPED_FILES:
190 mib[0] = CTL_P1003_1B;
191 mib[1] = CTL_P1003_1B_MAPPED_FILES;
194 mib[0] = CTL_P1003_1B;
195 mib[1] = CTL_P1003_1B_MEMLOCK;
197 case _SC_MEMLOCK_RANGE:
198 mib[0] = CTL_P1003_1B;
199 mib[1] = CTL_P1003_1B_MEMLOCK_RANGE;
201 case _SC_MEMORY_PROTECTION:
202 mib[0] = CTL_P1003_1B;
203 mib[1] = CTL_P1003_1B_MEMORY_PROTECTION;
205 case _SC_MESSAGE_PASSING:
206 mib[0] = CTL_P1003_1B;
207 mib[1] = CTL_P1003_1B_MESSAGE_PASSING;
209 case _SC_PRIORITIZED_IO:
210 mib[0] = CTL_P1003_1B;
211 mib[1] = CTL_P1003_1B_PRIORITIZED_IO;
213 case _SC_PRIORITY_SCHEDULING:
214 mib[0] = CTL_P1003_1B;
215 mib[1] = CTL_P1003_1B_PRIORITY_SCHEDULING;
217 case _SC_REALTIME_SIGNALS:
218 mib[0] = CTL_P1003_1B;
219 mib[1] = CTL_P1003_1B_REALTIME_SIGNALS;
222 mib[0] = CTL_P1003_1B;
223 mib[1] = CTL_P1003_1B_SEMAPHORES;
226 mib[0] = CTL_P1003_1B;
227 mib[1] = CTL_P1003_1B_FSYNC;
229 case _SC_SHARED_MEMORY_OBJECTS:
230 mib[0] = CTL_P1003_1B;
231 mib[1] = CTL_P1003_1B_SHARED_MEMORY_OBJECTS;
233 case _SC_SYNCHRONIZED_IO:
234 mib[0] = CTL_P1003_1B;
235 mib[1] = CTL_P1003_1B_SYNCHRONIZED_IO;
238 mib[0] = CTL_P1003_1B;
239 mib[1] = CTL_P1003_1B_TIMERS;
241 case _SC_AIO_LISTIO_MAX:
242 mib[0] = CTL_P1003_1B;
243 mib[1] = CTL_P1003_1B_AIO_LISTIO_MAX;
246 mib[0] = CTL_P1003_1B;
247 mib[1] = CTL_P1003_1B_AIO_MAX;
249 case _SC_AIO_PRIO_DELTA_MAX:
250 mib[0] = CTL_P1003_1B;
251 mib[1] = CTL_P1003_1B_AIO_PRIO_DELTA_MAX;
253 case _SC_DELAYTIMER_MAX:
254 mib[0] = CTL_P1003_1B;
255 mib[1] = CTL_P1003_1B_DELAYTIMER_MAX;
257 case _SC_MQ_OPEN_MAX:
258 mib[0] = CTL_P1003_1B;
259 mib[1] = CTL_P1003_1B_MQ_OPEN_MAX;
262 defaultresult = getpagesize();
263 mib[0] = CTL_P1003_1B;
264 mib[1] = CTL_P1003_1B_PAGESIZE;
267 mib[0] = CTL_P1003_1B;
268 mib[1] = CTL_P1003_1B_RTSIG_MAX;
270 case _SC_SEM_NSEMS_MAX:
271 mib[0] = CTL_P1003_1B;
272 mib[1] = CTL_P1003_1B_SEM_NSEMS_MAX;
274 case _SC_SEM_VALUE_MAX:
275 mib[0] = CTL_P1003_1B;
276 mib[1] = CTL_P1003_1B_SEM_VALUE_MAX;
278 case _SC_SIGQUEUE_MAX:
279 mib[0] = CTL_P1003_1B;
280 mib[1] = CTL_P1003_1B_SIGQUEUE_MAX;
283 mib[0] = CTL_P1003_1B;
284 mib[1] = CTL_P1003_1B_TIMER_MAX;
286 #endif /* _P1003_1B_VISIBLE */
288 yesno: if (sysctl(mib, 2, &value, &len, NULL, 0) == -1)
291 return (defaultresult);
298 return (sysctl(mib, 2, &value, &len, NULL, 0) == -1 ? -1 : value);