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
36 * @(#)sysconf.c 8.2 (Berkeley) 3/20/94
39 #include <sys/_posix.h>
40 #include <sys/param.h>
42 #include <sys/sysctl.h>
43 #include <sys/resource.h>
51 * get configurable system variables.
54 * POSIX 1003.1 (ISO/IEC 9945-1, 4.8.1.3) states that the variable values
55 * not change during the lifetime of the calling process. This would seem
56 * to require that any change to system limits kill all running processes.
57 * A workaround might be to cache the values when they are first retrieved
58 * and then simply return the cached value on subsequent calls. This is
59 * less useful than returning up-to-date values, however.
80 return (getrlimit(RLIMIT_NPROC, &rl) ? -1 : rl.rlim_cur);
85 mib[1] = KERN_JOB_CONTROL;
89 mib[1] = KERN_NGROUPS;
92 return (getrlimit(RLIMIT_NOFILE, &rl) ? -1 : rl.rlim_cur);
95 mib[1] = USER_STREAM_MAX;
99 mib[1] = USER_TZNAME_MAX;
103 mib[1] = KERN_SAVED_IDS;
107 mib[1] = KERN_POSIX1;
111 case _SC_BC_BASE_MAX:
113 mib[1] = USER_BC_BASE_MAX;
117 mib[1] = USER_BC_DIM_MAX;
119 case _SC_BC_SCALE_MAX:
121 mib[1] = USER_BC_SCALE_MAX;
123 case _SC_BC_STRING_MAX:
125 mib[1] = USER_BC_STRING_MAX;
127 case _SC_COLL_WEIGHTS_MAX:
129 mib[1] = USER_COLL_WEIGHTS_MAX;
131 case _SC_EXPR_NEST_MAX:
133 mib[1] = USER_EXPR_NEST_MAX;
137 mib[1] = USER_LINE_MAX;
141 mib[1] = USER_RE_DUP_MAX;
145 mib[1] = USER_POSIX2_VERSION;
149 mib[1] = USER_POSIX2_C_BIND;
153 mib[1] = USER_POSIX2_C_DEV;
155 case _SC_2_CHAR_TERM:
157 mib[1] = USER_POSIX2_CHAR_TERM;
161 mib[1] = USER_POSIX2_FORT_DEV;
165 mib[1] = USER_POSIX2_FORT_RUN;
167 case _SC_2_LOCALEDEF:
169 mib[1] = USER_POSIX2_LOCALEDEF;
173 mib[1] = USER_POSIX2_SW_DEV;
177 mib[1] = USER_POSIX2_UPE;
180 #ifdef _P1003_1B_VISIBLE
183 case _SC_ASYNCHRONOUS_IO:
184 mib[0] = CTL_P1003_1B;
185 mib[1] = CTL_P1003_1B_ASYNCHRONOUS_IO;
187 case _SC_MAPPED_FILES:
188 mib[0] = CTL_P1003_1B;
189 mib[1] = CTL_P1003_1B_MAPPED_FILES;
192 mib[0] = CTL_P1003_1B;
193 mib[1] = CTL_P1003_1B_MEMLOCK;
195 case _SC_MEMLOCK_RANGE:
196 mib[0] = CTL_P1003_1B;
197 mib[1] = CTL_P1003_1B_MEMLOCK_RANGE;
199 case _SC_MEMORY_PROTECTION:
200 mib[0] = CTL_P1003_1B;
201 mib[1] = CTL_P1003_1B_MEMORY_PROTECTION;
203 case _SC_MESSAGE_PASSING:
204 mib[0] = CTL_P1003_1B;
205 mib[1] = CTL_P1003_1B_MESSAGE_PASSING;
207 case _SC_PRIORITIZED_IO:
208 mib[0] = CTL_P1003_1B;
209 mib[1] = CTL_P1003_1B_PRIORITIZED_IO;
211 case _SC_PRIORITY_SCHEDULING:
212 mib[0] = CTL_P1003_1B;
213 mib[1] = CTL_P1003_1B_PRIORITY_SCHEDULING;
215 case _SC_REALTIME_SIGNALS:
216 mib[0] = CTL_P1003_1B;
217 mib[1] = CTL_P1003_1B_REALTIME_SIGNALS;
220 mib[0] = CTL_P1003_1B;
221 mib[1] = CTL_P1003_1B_SEMAPHORES;
224 mib[0] = CTL_P1003_1B;
225 mib[1] = CTL_P1003_1B_FSYNC;
227 case _SC_SHARED_MEMORY_OBJECTS:
228 mib[0] = CTL_P1003_1B;
229 mib[1] = CTL_P1003_1B_SHARED_MEMORY_OBJECTS;
231 case _SC_SYNCHRONIZED_IO:
232 mib[0] = CTL_P1003_1B;
233 mib[1] = CTL_P1003_1B_SYNCHRONIZED_IO;
236 mib[0] = CTL_P1003_1B;
237 mib[1] = CTL_P1003_1B_TIMERS;
239 case _SC_AIO_LISTIO_MAX:
240 mib[0] = CTL_P1003_1B;
241 mib[1] = CTL_P1003_1B_AIO_LISTIO_MAX;
244 mib[0] = CTL_P1003_1B;
245 mib[1] = CTL_P1003_1B_AIO_MAX;
247 case _SC_AIO_PRIO_DELTA_MAX:
248 mib[0] = CTL_P1003_1B;
249 mib[1] = CTL_P1003_1B_AIO_PRIO_DELTA_MAX;
251 case _SC_DELAYTIMER_MAX:
252 mib[0] = CTL_P1003_1B;
253 mib[1] = CTL_P1003_1B_DELAYTIMER_MAX;
255 case _SC_MQ_OPEN_MAX:
256 mib[0] = CTL_P1003_1B;
257 mib[1] = CTL_P1003_1B_MQ_OPEN_MAX;
260 defaultresult = getpagesize();
261 mib[0] = CTL_P1003_1B;
262 mib[1] = CTL_P1003_1B_PAGESIZE;
265 mib[0] = CTL_P1003_1B;
266 mib[1] = CTL_P1003_1B_RTSIG_MAX;
268 case _SC_SEM_NSEMS_MAX:
269 mib[0] = CTL_P1003_1B;
270 mib[1] = CTL_P1003_1B_SEM_NSEMS_MAX;
272 case _SC_SEM_VALUE_MAX:
273 mib[0] = CTL_P1003_1B;
274 mib[1] = CTL_P1003_1B_SEM_VALUE_MAX;
276 case _SC_SIGQUEUE_MAX:
277 mib[0] = CTL_P1003_1B;
278 mib[1] = CTL_P1003_1B_SIGQUEUE_MAX;
281 mib[0] = CTL_P1003_1B;
282 mib[1] = CTL_P1003_1B_TIMER_MAX;
284 #endif /* _P1003_1B_VISIBLE */
286 yesno: if (sysctl(mib, 2, &value, &len, NULL, 0) == -1)
289 return (defaultresult);
296 return (sysctl(mib, 2, &value, &len, NULL, 0) == -1 ? -1 : value);