]>
Commit | Line | Data |
---|---|---|
1 | /*- | |
2 | * Copyright (c) 1993 | |
3 | * The Regents of the University of California. All rights reserved. | |
4 | * | |
5 | * This code is derived from software contributed to Berkeley by | |
6 | * Sean Eric Fagan of Cygnus Support. | |
7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | |
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 | * 4. Neither the name of the University nor the names of its contributors | |
17 | * may be used to endorse or promote products derived from this software | |
18 | * without specific prior written permission. | |
19 | * | |
20 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
30 | * SUCH DAMAGE. | |
31 | */ | |
32 | ||
33 | #if defined(LIBC_SCCS) && !defined(lint) | |
34 | static char sccsid[] = "@(#)sysconf.c 8.2 (Berkeley) 3/20/94"; | |
35 | #endif /* LIBC_SCCS and not lint */ | |
36 | #include <sys/cdefs.h> | |
37 | __FBSDID("$FreeBSD: lib/libc/gen/sysconf.c r168718 $"); | |
38 | ||
39 | #include <sys/param.h> | |
40 | #include <sys/time.h> | |
41 | #include <sys/sysctl.h> | |
42 | #include <sys/resource.h> | |
43 | #include <sys/socket.h> | |
44 | #include <sys/aio.h> | |
45 | #include <sys/semaphore.h> | |
46 | ||
47 | #include <errno.h> | |
48 | #include <limits.h> | |
49 | #include <paths.h> | |
50 | #include <pthread.h> /* we just need the limits */ | |
51 | #include <time.h> | |
52 | #include <unistd.h> | |
53 | ||
54 | #include "../../stdlib/FreeBSD/atexit.h" | |
55 | #include "../../stdtime/FreeBSD/tzfile.h" | |
56 | ||
57 | #define _PATH_ZONEINFO TZDIR /* from tzfile.h */ | |
58 | ||
59 | /* | |
60 | * sysconf -- | |
61 | * get configurable system variables. | |
62 | * | |
63 | * XXX | |
64 | * POSIX 1003.1 (ISO/IEC 9945-1, 4.8.1.3) states that the variable values | |
65 | * not change during the lifetime of the calling process. This would seem | |
66 | * to require that any change to system limits kill all running processes. | |
67 | * A workaround might be to cache the values when they are first retrieved | |
68 | * and then simply return the cached value on subsequent calls. This is | |
69 | * less useful than returning up-to-date values, however. | |
70 | */ | |
71 | long | |
72 | sysconf(name) | |
73 | int name; | |
74 | { | |
75 | struct rlimit rl; | |
76 | quad_t qdvalue; /* for kern.sysv.shmmin */ | |
77 | size_t len; | |
78 | int mib[3], sverrno, value; | |
79 | long lvalue, defaultresult; | |
80 | const char *path; | |
81 | ||
82 | defaultresult = -1; | |
83 | ||
84 | switch (name) { | |
85 | case _SC_ARG_MAX: | |
86 | mib[0] = CTL_KERN; | |
87 | mib[1] = KERN_ARGMAX; | |
88 | break; | |
89 | case _SC_CHILD_MAX: | |
90 | if (getrlimit(RLIMIT_NPROC, &rl) != 0) | |
91 | return (-1); | |
92 | if (rl.rlim_cur == RLIM_INFINITY) | |
93 | return (-1); | |
94 | if (rl.rlim_cur > LONG_MAX) { | |
95 | errno = EOVERFLOW; | |
96 | return (-1); | |
97 | } | |
98 | return ((long)rl.rlim_cur); | |
99 | case _SC_CLK_TCK: | |
100 | return (CLK_TCK); | |
101 | case _SC_NGROUPS_MAX: | |
102 | mib[0] = CTL_KERN; | |
103 | mib[1] = KERN_NGROUPS; | |
104 | break; | |
105 | case _SC_OPEN_MAX: | |
106 | case _SC_STREAM_MAX: /* assume fds run out before memory does */ | |
107 | if (getrlimit(RLIMIT_NOFILE, &rl) != 0) | |
108 | return (-1); | |
109 | if (rl.rlim_cur == RLIM_INFINITY) | |
110 | return (-1); | |
111 | if (rl.rlim_cur > LONG_MAX) { | |
112 | errno = EOVERFLOW; | |
113 | return (-1); | |
114 | } | |
115 | return ((long)rl.rlim_cur); | |
116 | case _SC_JOB_CONTROL: | |
117 | return (_POSIX_JOB_CONTROL); | |
118 | case _SC_SAVED_IDS: | |
119 | /* XXX - must be 1 */ | |
120 | mib[0] = CTL_KERN; | |
121 | mib[1] = KERN_SAVED_IDS; | |
122 | goto yesno; | |
123 | case _SC_VERSION: | |
124 | mib[0] = CTL_KERN; | |
125 | mib[1] = KERN_POSIX1; | |
126 | break; | |
127 | case _SC_BC_BASE_MAX: | |
128 | return (BC_BASE_MAX); | |
129 | case _SC_BC_DIM_MAX: | |
130 | return (BC_DIM_MAX); | |
131 | case _SC_BC_SCALE_MAX: | |
132 | return (BC_SCALE_MAX); | |
133 | case _SC_BC_STRING_MAX: | |
134 | return (BC_STRING_MAX); | |
135 | case _SC_COLL_WEIGHTS_MAX: | |
136 | return (COLL_WEIGHTS_MAX); | |
137 | case _SC_EXPR_NEST_MAX: | |
138 | return (EXPR_NEST_MAX); | |
139 | case _SC_LINE_MAX: | |
140 | return (LINE_MAX); | |
141 | case _SC_RE_DUP_MAX: | |
142 | return (RE_DUP_MAX); | |
143 | case _SC_2_VERSION: | |
144 | /* | |
145 | * This is something of a lie, but it would be silly at | |
146 | * this point to try to deduce this from the contents | |
147 | * of the filesystem. | |
148 | */ | |
149 | return (_POSIX2_VERSION); | |
150 | case _SC_2_C_BIND: | |
151 | return (_POSIX2_C_BIND); | |
152 | case _SC_2_C_DEV: | |
153 | return (_POSIX2_C_DEV); | |
154 | case _SC_2_CHAR_TERM: | |
155 | return (_POSIX2_CHAR_TERM); | |
156 | case _SC_2_FORT_DEV: | |
157 | return (_POSIX2_FORT_DEV); | |
158 | case _SC_2_FORT_RUN: | |
159 | return (_POSIX2_FORT_RUN); | |
160 | case _SC_2_LOCALEDEF: | |
161 | return (_POSIX2_LOCALEDEF); | |
162 | case _SC_2_SW_DEV: | |
163 | return (_POSIX2_SW_DEV); | |
164 | case _SC_2_UPE: | |
165 | return (_POSIX2_UPE); | |
166 | case _SC_TZNAME_MAX: | |
167 | path = _PATH_ZONEINFO; | |
168 | do_NAME_MAX: | |
169 | sverrno = errno; | |
170 | errno = 0; | |
171 | lvalue = pathconf(path, _PC_NAME_MAX); | |
172 | if (lvalue == -1 && errno != 0) | |
173 | return (-1); | |
174 | errno = sverrno; | |
175 | return (lvalue); | |
176 | ||
177 | case _SC_ASYNCHRONOUS_IO: | |
178 | #if _POSIX_ASYNCHRONOUS_IO == 0 | |
179 | mib[0] = CTL_P1003_1B; | |
180 | mib[1] = CTL_P1003_1B_ASYNCHRONOUS_IO; | |
181 | break; | |
182 | #else | |
183 | return (_POSIX_ASYNCHRONOUS_IO); | |
184 | #endif | |
185 | case _SC_MAPPED_FILES: | |
186 | return (_POSIX_MAPPED_FILES); | |
187 | case _SC_MEMLOCK: | |
188 | return (_POSIX_MEMLOCK); | |
189 | case _SC_MEMLOCK_RANGE: | |
190 | return (_POSIX_MEMLOCK_RANGE); | |
191 | case _SC_MEMORY_PROTECTION: | |
192 | return (_POSIX_MEMORY_PROTECTION); | |
193 | case _SC_MESSAGE_PASSING: | |
194 | #if _POSIX_MESSAGE_PASSING == 0 | |
195 | mib[0] = CTL_P1003_1B; | |
196 | mib[1] = CTL_P1003_1B_MESSAGE_PASSING; | |
197 | goto yesno; | |
198 | #else | |
199 | return (_POSIX_MESSAGE_PASSING); | |
200 | #endif | |
201 | case _SC_PRIORITIZED_IO: | |
202 | #if _POSIX_PRIORITIZED_IO == 0 | |
203 | mib[0] = CTL_P1003_1B; | |
204 | mib[1] = CTL_P1003_1B_PRIORITIZED_IO; | |
205 | goto yesno; | |
206 | #else | |
207 | return (_POSIX_PRIORITIZED_IO); | |
208 | #endif | |
209 | case _SC_PRIORITY_SCHEDULING: | |
210 | #if _POSIX_PRIORITY_SCHEDULING == 0 | |
211 | mib[0] = CTL_P1003_1B; | |
212 | mib[1] = CTL_P1003_1B_PRIORITY_SCHEDULING; | |
213 | goto yesno; | |
214 | #else | |
215 | return (_POSIX_PRIORITY_SCHEDULING); | |
216 | #endif | |
217 | case _SC_REALTIME_SIGNALS: | |
218 | #if _POSIX_REALTIME_SIGNALS == 0 | |
219 | mib[0] = CTL_P1003_1B; | |
220 | mib[1] = CTL_P1003_1B_REALTIME_SIGNALS; | |
221 | goto yesno; | |
222 | #else | |
223 | return (_POSIX_REALTIME_SIGNALS); | |
224 | #endif | |
225 | case _SC_SEMAPHORES: | |
226 | #if _POSIX_SEMAPHORES == 0 | |
227 | mib[0] = CTL_P1003_1B; | |
228 | mib[1] = CTL_P1003_1B_SEMAPHORES; | |
229 | goto yesno; | |
230 | #else | |
231 | return (_POSIX_SEMAPHORES); | |
232 | #endif | |
233 | case _SC_FSYNC: | |
234 | return (_POSIX_FSYNC); | |
235 | ||
236 | case _SC_SHARED_MEMORY_OBJECTS: | |
237 | return (_POSIX_SHARED_MEMORY_OBJECTS); | |
238 | case _SC_SYNCHRONIZED_IO: | |
239 | #if _POSIX_SYNCHRONIZED_IO == 0 | |
240 | mib[0] = CTL_P1003_1B; | |
241 | mib[1] = CTL_P1003_1B_SYNCHRONIZED_IO; | |
242 | goto yesno; | |
243 | #else | |
244 | return (_POSIX_SYNCHRONIZED_IO); | |
245 | #endif | |
246 | case _SC_TIMERS: | |
247 | #if _POSIX_TIMERS == 0 | |
248 | mib[0] = CTL_P1003_1B; | |
249 | mib[1] = CTL_P1003_1B_TIMERS; | |
250 | goto yesno; | |
251 | #else | |
252 | return (_POSIX_TIMERS); | |
253 | #endif | |
254 | case _SC_AIO_LISTIO_MAX: | |
255 | #if defined(CTL_P1003_1B) && defined(CTL_P1003_1B_AIO_LISTIO_MAX) | |
256 | mib[0] = CTL_P1003_1B; | |
257 | mib[1] = CTL_P1003_1B_AIO_LISTIO_MAX; | |
258 | #else | |
259 | mib[0] = CTL_KERN;; | |
260 | mib[1] = KERN_AIOMAX; | |
261 | #endif | |
262 | break; | |
263 | case _SC_AIO_MAX: | |
264 | #if defined(CTL_P1003_1B) && defined(CTL_P1003_1B_AIO_MAX) | |
265 | mib[0] = CTL_P1003_1B; | |
266 | mib[1] = CTL_P1003_1B_AIO_MAX; | |
267 | #else | |
268 | mib[0] = CTL_KERN;; | |
269 | mib[1] = KERN_AIOMAX; | |
270 | #endif | |
271 | break; | |
272 | case _SC_AIO_PRIO_DELTA_MAX: | |
273 | #if defined(CTL_P1003_1B) && defined(CTL_P1003_1B_AIO_PRIO_DELTA_MAX) | |
274 | mib[0] = CTL_P1003_1B; | |
275 | mib[1] = CTL_P1003_1B_AIO_PRIO_DELTA_MAX; | |
276 | break; | |
277 | #else | |
278 | return (-1); | |
279 | #endif | |
280 | case _SC_DELAYTIMER_MAX: | |
281 | #if defined(CTL_P1003_1B) && defined(CTL_P1003_1B_DELAYTIMER_MAX) | |
282 | mib[0] = CTL_P1003_1B; | |
283 | mib[1] = CTL_P1003_1B_DELAYTIMER_MAX; | |
284 | goto yesno; | |
285 | #else | |
286 | return (-1); | |
287 | #endif | |
288 | case _SC_MQ_OPEN_MAX: | |
289 | #if defined(CTL_P1003_1B) && defined(CTL_P1003_1B_MQ_OPEN_MAX) | |
290 | mib[0] = CTL_P1003_1B; | |
291 | mib[1] = CTL_P1003_1B_MQ_OPEN_MAX; | |
292 | goto yesno; | |
293 | #else | |
294 | return (-1); | |
295 | #endif | |
296 | case _SC_PAGESIZE: | |
297 | defaultresult = getpagesize(); | |
298 | #if defined(CTL_P1003_1B) && defined(CTL_P1003_1B_PAGESIZE) | |
299 | mib[0] = CTL_P1003_1B; | |
300 | mib[1] = CTL_P1003_1B_PAGESIZE; | |
301 | goto yesno; | |
302 | #else | |
303 | return defaultresult; | |
304 | #endif | |
305 | case _SC_RTSIG_MAX: | |
306 | #if defined(CTL_P1003_1B) && defined(CTL_P1003_1B_RTSIG_MAX) | |
307 | mib[0] = CTL_P1003_1B; | |
308 | mib[1] = CTL_P1003_1B_RTSIG_MAX; | |
309 | goto yesno; | |
310 | #else | |
311 | return (-1); | |
312 | #endif | |
313 | case _SC_SEM_NSEMS_MAX: | |
314 | #if defined(CTL_P1003_1B) && defined(CTL_P1003_1B_RTSIG_MAX) | |
315 | mib[0] = CTL_P1003_1B; | |
316 | mib[1] = CTL_P1003_1B_SEM_NSEMS_MAX; | |
317 | goto yesno; | |
318 | #else | |
319 | len = sizeof(value); | |
320 | return (sysctlbyname("kern.sysv.semmns", &value, &len, NULL, 0) == -1 ? -1 : value); | |
321 | #endif | |
322 | ||
323 | case _SC_SEM_VALUE_MAX: | |
324 | #if SEM_VALUE_MAX == 0 | |
325 | mib[0] = CTL_P1003_1B; | |
326 | mib[1] = CTL_P1003_1B_SEM_VALUE_MAX; | |
327 | goto yesno; | |
328 | #else | |
329 | return (SEM_VALUE_MAX); | |
330 | #endif | |
331 | case _SC_SIGQUEUE_MAX: | |
332 | #if defined(CTL_P1003_1B) && defined(CTL_P1003_1B_SIGQUEUE_MAX) | |
333 | mib[0] = CTL_P1003_1B; | |
334 | mib[1] = CTL_P1003_1B_SIGQUEUE_MAX; | |
335 | goto yesno; | |
336 | #else | |
337 | return (-1); | |
338 | #endif | |
339 | case _SC_TIMER_MAX: | |
340 | #if defined(CTL_P1003_1B) && defined(CTL_P1003_1B_TIMER_MAX) | |
341 | mib[0] = CTL_P1003_1B; | |
342 | mib[1] = CTL_P1003_1B_TIMER_MAX; | |
343 | #else | |
344 | return (-1); | |
345 | #endif | |
346 | ||
347 | yesno: | |
348 | len = sizeof(value); | |
349 | if (sysctl(mib, 2, &value, &len, NULL, 0) == -1) | |
350 | return (-1); | |
351 | if (value == 0) | |
352 | return (defaultresult); | |
353 | return ((long)value); | |
354 | ||
355 | case _SC_2_PBS: | |
356 | case _SC_2_PBS_ACCOUNTING: | |
357 | case _SC_2_PBS_CHECKPOINT: | |
358 | case _SC_2_PBS_LOCATE: | |
359 | case _SC_2_PBS_MESSAGE: | |
360 | case _SC_2_PBS_TRACK: | |
361 | #if _POSIX2_PBS == 0 | |
362 | #error "don't know how to determine _SC_2_PBS" | |
363 | /* | |
364 | * This probably requires digging through the filesystem | |
365 | * to see if the appropriate package has been installed. | |
366 | * Since we don't currently support this option at all, | |
367 | * it's not worth the effort to write the code now. | |
368 | * Figuring out which of the sub-options are supported | |
369 | * would be even more difficult, so it's probably easier | |
370 | * to always say ``no''. | |
371 | */ | |
372 | #else | |
373 | return (_POSIX2_PBS); | |
374 | #endif | |
375 | case _SC_ADVISORY_INFO: | |
376 | #if _POSIX_ADVISORY_INFO == 0 | |
377 | #error "_POSIX_ADVISORY_INFO" | |
378 | #else | |
379 | return (_POSIX_ADVISORY_INFO); | |
380 | #endif | |
381 | case _SC_BARRIERS: | |
382 | #if _POSIX_BARRIERS == 0 | |
383 | #error "_POSIX_BARRIERS" | |
384 | #else | |
385 | return (_POSIX_BARRIERS); | |
386 | #endif | |
387 | case _SC_CLOCK_SELECTION: | |
388 | #if _POSIX_CLOCK_SELECTION == 0 | |
389 | #error "_POSIX_CLOCK_SELECTION" | |
390 | #else | |
391 | return (_POSIX_CLOCK_SELECTION); | |
392 | #endif | |
393 | case _SC_CPUTIME: | |
394 | #if _POSIX_CPUTIME == 0 | |
395 | #error "_POSIX_CPUTIME" | |
396 | #else | |
397 | return (_POSIX_CPUTIME); | |
398 | #endif | |
399 | case _SC_FILE_LOCKING: | |
400 | case _SC_GETGR_R_SIZE_MAX: | |
401 | /* return sizeof(group) + group_name_max + group_passwd_max + max_group_member*(MAXLOGNAME+1); */ | |
402 | return 4096; /* INT_MAX is too big for Perl */ | |
403 | case _SC_GETPW_R_SIZE_MAX: | |
404 | return 4096; | |
405 | case _SC_HOST_NAME_MAX: | |
406 | return (MAXHOSTNAMELEN - 1); /* does not include \0 */ | |
407 | case _SC_LOGIN_NAME_MAX: | |
408 | return (MAXLOGNAME); | |
409 | case _SC_MONOTONIC_CLOCK: | |
410 | #if _POSIX_MONOTONIC_CLOCK == 0 | |
411 | #error "_POSIX_MONOTONIC_CLOCK" | |
412 | #else | |
413 | return (_POSIX_MONOTONIC_CLOCK); | |
414 | #endif | |
415 | case _SC_MQ_PRIO_MAX: | |
416 | return (-1); | |
417 | case _SC_READER_WRITER_LOCKS: | |
418 | return (_POSIX_READER_WRITER_LOCKS); | |
419 | case _SC_REGEXP: | |
420 | return (_POSIX_REGEXP); | |
421 | case _SC_SHELL: | |
422 | return (_POSIX_SHELL); | |
423 | case _SC_SPAWN: | |
424 | return (_POSIX_SPAWN); | |
425 | case _SC_SPIN_LOCKS: | |
426 | return (_POSIX_SPIN_LOCKS); | |
427 | case _SC_SPORADIC_SERVER: | |
428 | #if _POSIX_SPORADIC_SERVER == 0 | |
429 | #error "_POSIX_SPORADIC_SERVER" | |
430 | #else | |
431 | return (_POSIX_SPORADIC_SERVER); | |
432 | #endif | |
433 | case _SC_THREAD_ATTR_STACKADDR: | |
434 | return (_POSIX_THREAD_ATTR_STACKADDR); | |
435 | case _SC_THREAD_ATTR_STACKSIZE: | |
436 | return (_POSIX_THREAD_ATTR_STACKSIZE); | |
437 | case _SC_THREAD_CPUTIME: | |
438 | return (_POSIX_THREAD_CPUTIME); | |
439 | case _SC_THREAD_DESTRUCTOR_ITERATIONS: | |
440 | return (PTHREAD_DESTRUCTOR_ITERATIONS); | |
441 | case _SC_THREAD_KEYS_MAX: | |
442 | return (PTHREAD_KEYS_MAX); | |
443 | case _SC_THREAD_PRIO_INHERIT: | |
444 | return (_POSIX_THREAD_PRIO_INHERIT); | |
445 | case _SC_THREAD_PRIO_PROTECT: | |
446 | return (_POSIX_THREAD_PRIO_PROTECT); | |
447 | case _SC_THREAD_PRIORITY_SCHEDULING: | |
448 | return (_POSIX_THREAD_PRIORITY_SCHEDULING); | |
449 | case _SC_THREAD_PROCESS_SHARED: | |
450 | return (_POSIX_THREAD_PROCESS_SHARED); | |
451 | case _SC_THREAD_SAFE_FUNCTIONS: | |
452 | return (_POSIX_THREAD_SAFE_FUNCTIONS); | |
453 | case _SC_THREAD_SPORADIC_SERVER: | |
454 | return (_POSIX_THREAD_SPORADIC_SERVER); | |
455 | case _SC_THREAD_STACK_MIN: | |
456 | return (PTHREAD_STACK_MIN); | |
457 | case _SC_THREAD_THREADS_MAX: | |
458 | #ifdef PTHREAD_THREADS_MAX | |
459 | return (PTHREAD_THREADS_MAX); /* XXX wrong type! */ | |
460 | #else | |
461 | return (-1); | |
462 | #endif | |
463 | case _SC_TIMEOUTS: | |
464 | return (_POSIX_TIMEOUTS); | |
465 | case _SC_THREADS: | |
466 | return (_POSIX_THREADS); | |
467 | case _SC_TRACE: | |
468 | #if _POSIX_TRACE == 0 | |
469 | #error "_POSIX_TRACE" | |
470 | /* While you're implementing this, also do the ones below. */ | |
471 | #else | |
472 | return (_POSIX_TRACE); | |
473 | #endif | |
474 | case _SC_TRACE_EVENT_FILTER: | |
475 | return (_POSIX_TRACE_EVENT_FILTER); | |
476 | case _SC_TRACE_INHERIT: | |
477 | return (_POSIX_TRACE_INHERIT); | |
478 | case _SC_TRACE_LOG: | |
479 | return (_POSIX_TRACE_LOG); | |
480 | case _SC_TTY_NAME_MAX: | |
481 | path = "/"; // should be _PATH_DEV (PR-3624562) | |
482 | goto do_NAME_MAX; | |
483 | case _SC_TYPED_MEMORY_OBJECTS: | |
484 | #if _POSIX_TYPED_MEMORY_OBJECTS == 0 | |
485 | #error "_POSIX_TYPED_MEMORY_OBJECTS" | |
486 | #else | |
487 | return (_POSIX_TYPED_MEMORY_OBJECTS); | |
488 | #endif | |
489 | case _SC_V6_ILP32_OFF32: | |
490 | #if _V6_ILP32_OFF32 == 0 | |
491 | if (sizeof(int) * CHAR_BIT == 32 && | |
492 | sizeof(int) == sizeof(long) && | |
493 | sizeof(long) == sizeof(void *) && | |
494 | sizeof(void *) == sizeof(off_t)) | |
495 | return 1; | |
496 | else | |
497 | return -1; | |
498 | #else | |
499 | return (_V6_ILP32_OFF32); | |
500 | #endif | |
501 | case _SC_V6_ILP32_OFFBIG: | |
502 | #if _V6_ILP32_OFFBIG == 0 | |
503 | if (sizeof(int) * CHAR_BIT == 32 && | |
504 | sizeof(int) == sizeof(long) && | |
505 | sizeof(long) == sizeof(void *) && | |
506 | sizeof(off_t) * CHAR_BIT >= 64) | |
507 | return 1; | |
508 | else | |
509 | return -1; | |
510 | #else | |
511 | return (_V6_ILP32_OFFBIG); | |
512 | #endif | |
513 | case _SC_V6_LP64_OFF64: | |
514 | #if _V6_LP64_OFF64 == 0 | |
515 | if (sizeof(int) * CHAR_BIT == 32 && | |
516 | sizeof(long) * CHAR_BIT == 64 && | |
517 | sizeof(long) == sizeof(void *) && | |
518 | sizeof(void *) == sizeof(off_t)) | |
519 | return 1; | |
520 | else | |
521 | return -1; | |
522 | #else | |
523 | return (_V6_LP64_OFF64); | |
524 | #endif | |
525 | case _SC_V6_LPBIG_OFFBIG: | |
526 | #if _V6_LPBIG_OFFBIG == 0 | |
527 | if (sizeof(int) * CHAR_BIT >= 32 && | |
528 | sizeof(long) * CHAR_BIT >= 64 && | |
529 | sizeof(void *) * CHAR_BIT >= 64 && | |
530 | sizeof(off_t) * CHAR_BIT >= 64) | |
531 | return 1; | |
532 | else | |
533 | return -1; | |
534 | #else | |
535 | return (_V6_LPBIG_OFFBIG); | |
536 | #endif | |
537 | case _SC_ATEXIT_MAX: | |
538 | return (INT_MAX); /* unlimited */ | |
539 | case _SC_IOV_MAX: | |
540 | #ifdef KERN_IOV_MAX | |
541 | mib[0] = CTL_KERN; | |
542 | mib[1] = KERN_IOV_MAX; | |
543 | break; | |
544 | #else | |
545 | return (IOV_MAX); | |
546 | #endif | |
547 | case _SC_XOPEN_CRYPT: | |
548 | return (_XOPEN_CRYPT); | |
549 | case _SC_XOPEN_ENH_I18N: | |
550 | return (_XOPEN_ENH_I18N); | |
551 | case _SC_XOPEN_LEGACY: | |
552 | return (_XOPEN_LEGACY); | |
553 | case _SC_XOPEN_REALTIME: | |
554 | #if _XOPEN_REALTIME == 0 | |
555 | sverrno = errno; | |
556 | value = sysconf(_SC_ASYNCHRONOUS_IO) > 0 && | |
557 | sysconf(_SC_MEMLOCK) > 0 && | |
558 | sysconf(_SC_MEMLOCK_RANGE) > 0 && | |
559 | sysconf(_SC_MESSAGE_PASSING) > 0 && | |
560 | sysconf(_SC_PRIORITY_SCHEDULING) > 0 && | |
561 | sysconf(_SC_REALTIME_SIGNALS) > 0 && | |
562 | sysconf(_SC_SEMAPHORES) > 0 && | |
563 | sysconf(_SC_SHARED_MEMORY_OBJECTS) > 0 && | |
564 | sysconf(_SC_SYNCHRONIZED_IO) > 0 && | |
565 | sysconf(_SC_TIMERS) > 0; | |
566 | errno = sverrno; | |
567 | if (value) | |
568 | return (200112L); | |
569 | else | |
570 | return (-1); | |
571 | #else | |
572 | return (_XOPEN_REALTIME); | |
573 | #endif | |
574 | case _SC_XOPEN_REALTIME_THREADS: | |
575 | #if _XOPEN_REALTIME_THREADS == 0 | |
576 | #error "_XOPEN_REALTIME_THREADS" | |
577 | #else | |
578 | return (_XOPEN_REALTIME_THREADS); | |
579 | #endif | |
580 | case _SC_XOPEN_SHM: | |
581 | sverrno = errno; | |
582 | len = sizeof(qdvalue); | |
583 | if (sysctlbyname("kern.sysv.shmmin", &qdvalue, &len, NULL, | |
584 | 0) == -1) { | |
585 | errno = sverrno; | |
586 | return (-1); | |
587 | } | |
588 | errno = sverrno; | |
589 | return (1); | |
590 | case _SC_XOPEN_STREAMS: | |
591 | return (_XOPEN_STREAMS); | |
592 | case _SC_XOPEN_UNIX: | |
593 | return (_XOPEN_UNIX); | |
594 | #ifdef _XOPEN_VERSION | |
595 | case _SC_XOPEN_VERSION: | |
596 | return (_XOPEN_VERSION); | |
597 | #endif | |
598 | #ifdef _XOPEN_XCU_VERSION | |
599 | case _SC_XOPEN_XCU_VERSION: | |
600 | return (_XOPEN_XCU_VERSION); | |
601 | #endif | |
602 | case _SC_SYMLOOP_MAX: | |
603 | return (MAXSYMLINKS); | |
604 | case _SC_RAW_SOCKETS: | |
605 | return (_POSIX_RAW_SOCKETS); | |
606 | case _SC_IPV6: | |
607 | #if _POSIX_IPV6 == 0 | |
608 | sverrno = errno; | |
609 | value = socket(PF_INET6, SOCK_DGRAM, 0); | |
610 | errno = sverrno; | |
611 | if (value >= 0) { | |
612 | close(value); | |
613 | return (200112L); | |
614 | } else | |
615 | return (0); | |
616 | #else | |
617 | return (_POSIX_IPV6); | |
618 | #endif | |
619 | ||
620 | #ifdef _SC_NPROCESSORS_CONF | |
621 | case _SC_NPROCESSORS_CONF: | |
622 | #endif | |
623 | #ifdef _SC_NPROCESSORS_ONLN | |
624 | case _SC_NPROCESSORS_ONLN: | |
625 | #endif | |
626 | #if defined(_SC_NPROCESSORS_CONF) || defined(_SC_NPROCESSORS_ONLN) | |
627 | mib[0] = CTL_HW; | |
628 | mib[1] = HW_NCPU; | |
629 | break; | |
630 | #endif | |
631 | case _SC_XBS5_ILP32_OFF32: | |
632 | return (_XBS5_ILP32_OFF32); | |
633 | case _SC_XBS5_ILP32_OFFBIG: | |
634 | return (_XBS5_ILP32_OFFBIG); | |
635 | case _SC_XBS5_LP64_OFF64: | |
636 | return (_XBS5_LP64_OFF64); | |
637 | case _SC_XBS5_LPBIG_OFFBIG: | |
638 | return (_XBS5_LPBIG_OFFBIG); | |
639 | case _SC_SS_REPL_MAX: | |
640 | return (_POSIX_SS_REPL_MAX); | |
641 | case _SC_TRACE_EVENT_NAME_MAX: | |
642 | return (_POSIX_TRACE_EVENT_NAME_MAX); | |
643 | case _SC_TRACE_NAME_MAX: | |
644 | return (_POSIX_TRACE_NAME_MAX); | |
645 | case _SC_TRACE_SYS_MAX: | |
646 | return (_POSIX_TRACE_SYS_MAX); | |
647 | case _SC_TRACE_USER_EVENT_MAX: | |
648 | return (_POSIX_TRACE_USER_EVENT_MAX); | |
649 | case _SC_PASS_MAX: | |
650 | return (PASS_MAX); | |
651 | ||
652 | #ifdef _SC_PHYS_PAGES | |
653 | case _SC_PHYS_PAGES: | |
654 | #ifdef __APPLE__ | |
655 | { | |
656 | long memsize; | |
657 | long pagesize; | |
658 | ||
659 | len = sizeof(memsize); | |
660 | if (sysctlbyname("hw.memsize", &memsize, &len, NULL, 0) == -1) | |
661 | return (-1); | |
662 | ||
663 | len = sizeof(pagesize); | |
664 | if (sysctlbyname("hw.pagesize", &pagesize, &len, NULL, 0) == -1) | |
665 | return (-1); | |
666 | ||
667 | return (memsize / pagesize); | |
668 | } | |
669 | #else | |
670 | len = sizeof(lvalue); | |
671 | if (sysctlbyname("hw.availpages", &lvalue, &len, NULL, 0) == -1) | |
672 | return (-1); | |
673 | return (lvalue); | |
674 | #endif | |
675 | #endif | |
676 | ||
677 | default: | |
678 | errno = EINVAL; | |
679 | return (-1); | |
680 | } | |
681 | len = sizeof(value); | |
682 | if (sysctl(mib, 2, &value, &len, NULL, 0) == -1) | |
683 | value = -1; | |
684 | return ((long)value); | |
685 | } |