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
37 * $DragonFly: src/lib/libc/gen/sysconf.c,v 1.3 2004/11/09 17:52:45 joerg Exp $
40 #include <sys/_posix.h>
41 #include <sys/param.h>
43 #include <sys/sysctl.h>
44 #include <sys/resource.h>
52 * get configurable system variables.
55 * POSIX 1003.1 (ISO/IEC 9945-1, 4.8.1.3) states that the variable values
56 * not change during the lifetime of the calling process. This would seem
57 * to require that any change to system limits kill all running processes.
58 * A workaround might be to cache the values when they are first retrieved
59 * and then simply return the cached value on subsequent calls. This is
60 * less useful than returning up-to-date values, however.
81 return (getrlimit(RLIMIT_NPROC, &rl) ? -1 : rl.rlim_cur);
86 mib[1] = KERN_JOB_CONTROL;
90 mib[1] = KERN_NGROUPS;
93 return (getrlimit(RLIMIT_NOFILE, &rl) ? -1 : rl.rlim_cur);
96 mib[1] = USER_STREAM_MAX;
100 mib[1] = USER_TZNAME_MAX;
104 mib[1] = KERN_SAVED_IDS;
108 mib[1] = KERN_POSIX1;
112 mib[1] = KERN_IOV_MAX;
116 case _SC_BC_BASE_MAX:
118 mib[1] = USER_BC_BASE_MAX;
122 mib[1] = USER_BC_DIM_MAX;
124 case _SC_BC_SCALE_MAX:
126 mib[1] = USER_BC_SCALE_MAX;
128 case _SC_BC_STRING_MAX:
130 mib[1] = USER_BC_STRING_MAX;
132 case _SC_COLL_WEIGHTS_MAX:
134 mib[1] = USER_COLL_WEIGHTS_MAX;
136 case _SC_EXPR_NEST_MAX:
138 mib[1] = USER_EXPR_NEST_MAX;
142 mib[1] = USER_LINE_MAX;
146 mib[1] = USER_RE_DUP_MAX;
150 mib[1] = USER_POSIX2_VERSION;
154 mib[1] = USER_POSIX2_C_BIND;
158 mib[1] = USER_POSIX2_C_DEV;
160 case _SC_2_CHAR_TERM:
162 mib[1] = USER_POSIX2_CHAR_TERM;
166 mib[1] = USER_POSIX2_FORT_DEV;
170 mib[1] = USER_POSIX2_FORT_RUN;
172 case _SC_2_LOCALEDEF:
174 mib[1] = USER_POSIX2_LOCALEDEF;
178 mib[1] = USER_POSIX2_SW_DEV;
182 mib[1] = USER_POSIX2_UPE;
185 #ifdef _P1003_1B_VISIBLE
188 case _SC_ASYNCHRONOUS_IO:
189 mib[0] = CTL_P1003_1B;
190 mib[1] = CTL_P1003_1B_ASYNCHRONOUS_IO;
192 case _SC_MAPPED_FILES:
193 mib[0] = CTL_P1003_1B;
194 mib[1] = CTL_P1003_1B_MAPPED_FILES;
197 mib[0] = CTL_P1003_1B;
198 mib[1] = CTL_P1003_1B_MEMLOCK;
200 case _SC_MEMLOCK_RANGE:
201 mib[0] = CTL_P1003_1B;
202 mib[1] = CTL_P1003_1B_MEMLOCK_RANGE;
204 case _SC_MEMORY_PROTECTION:
205 mib[0] = CTL_P1003_1B;
206 mib[1] = CTL_P1003_1B_MEMORY_PROTECTION;
208 case _SC_MESSAGE_PASSING:
209 mib[0] = CTL_P1003_1B;
210 mib[1] = CTL_P1003_1B_MESSAGE_PASSING;
212 case _SC_PRIORITIZED_IO:
213 mib[0] = CTL_P1003_1B;
214 mib[1] = CTL_P1003_1B_PRIORITIZED_IO;
216 case _SC_PRIORITY_SCHEDULING:
217 mib[0] = CTL_P1003_1B;
218 mib[1] = CTL_P1003_1B_PRIORITY_SCHEDULING;
220 case _SC_REALTIME_SIGNALS:
221 mib[0] = CTL_P1003_1B;
222 mib[1] = CTL_P1003_1B_REALTIME_SIGNALS;
225 mib[0] = CTL_P1003_1B;
226 mib[1] = CTL_P1003_1B_SEMAPHORES;
229 mib[0] = CTL_P1003_1B;
230 mib[1] = CTL_P1003_1B_FSYNC;
232 case _SC_SHARED_MEMORY_OBJECTS:
233 mib[0] = CTL_P1003_1B;
234 mib[1] = CTL_P1003_1B_SHARED_MEMORY_OBJECTS;
236 case _SC_SYNCHRONIZED_IO:
237 mib[0] = CTL_P1003_1B;
238 mib[1] = CTL_P1003_1B_SYNCHRONIZED_IO;
241 mib[0] = CTL_P1003_1B;
242 mib[1] = CTL_P1003_1B_TIMERS;
244 case _SC_AIO_LISTIO_MAX:
245 mib[0] = CTL_P1003_1B;
246 mib[1] = CTL_P1003_1B_AIO_LISTIO_MAX;
249 mib[0] = CTL_P1003_1B;
250 mib[1] = CTL_P1003_1B_AIO_MAX;
252 case _SC_AIO_PRIO_DELTA_MAX:
253 mib[0] = CTL_P1003_1B;
254 mib[1] = CTL_P1003_1B_AIO_PRIO_DELTA_MAX;
256 case _SC_DELAYTIMER_MAX:
257 mib[0] = CTL_P1003_1B;
258 mib[1] = CTL_P1003_1B_DELAYTIMER_MAX;
260 case _SC_MQ_OPEN_MAX:
261 mib[0] = CTL_P1003_1B;
262 mib[1] = CTL_P1003_1B_MQ_OPEN_MAX;
265 defaultresult = getpagesize();
266 mib[0] = CTL_P1003_1B;
267 mib[1] = CTL_P1003_1B_PAGESIZE;
270 mib[0] = CTL_P1003_1B;
271 mib[1] = CTL_P1003_1B_RTSIG_MAX;
273 case _SC_SEM_NSEMS_MAX:
274 mib[0] = CTL_P1003_1B;
275 mib[1] = CTL_P1003_1B_SEM_NSEMS_MAX;
277 case _SC_SEM_VALUE_MAX:
278 mib[0] = CTL_P1003_1B;
279 mib[1] = CTL_P1003_1B_SEM_VALUE_MAX;
281 case _SC_SIGQUEUE_MAX:
282 mib[0] = CTL_P1003_1B;
283 mib[1] = CTL_P1003_1B_SIGQUEUE_MAX;
286 mib[0] = CTL_P1003_1B;
287 mib[1] = CTL_P1003_1B_TIMER_MAX;
289 #endif /* _P1003_1B_VISIBLE */
291 yesno: if (sysctl(mib, 2, &value, &len, NULL, 0) == -1)
294 return (defaultresult);
301 return (sysctl(mib, 2, &value, &len, NULL, 0) == -1 ? -1 : value);