]> git.saurik.com Git - apple/libc.git/blob - gen/FreeBSD/sysconf.c
Libc-1439.100.3.tar.gz
[apple/libc.git] / gen / FreeBSD / sysconf.c
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 __LP64__
110 /*
111 * In 64 bit world, sysconf is able to correctly represent
112 * rlim_t values (8 bytes).
113 */
114 if (rl.rlim_cur > RLIM_INFINITY)
115 return (-1);
116 if (rl.rlim_cur > LONG_MAX) {
117 errno = EOVERFLOW;
118 return (-1);
119 }
120 lvalue = rl.rlim_cur;
121 #else
122 /*
123 * In 32 bit world (watches), sysconf falls back to the
124 * old behavior: use (int) OPEN_MAX as max limit. Ideally
125 * we would use maxfilesperproc as max limit, which is a
126 * system value adjusted by the kernel based on available
127 * RAM size. This value defaults to OPEN_MAX for systems
128 * with less than 8G of RAM. So we use OPEN_MAX (defined
129 * in sys/syslimits.h) as max limit here in case
130 * applications with strict sandbox rules prevent libc
131 * from reading maxfilesperproc via sysctl.
132 */
133 if (rl.rlim_cur > OPEN_MAX)
134 lvalue = OPEN_MAX;
135 else
136 lvalue = (long)rl.rlim_cur;
137 #endif
138 return lvalue;
139 case _SC_JOB_CONTROL:
140 return (_POSIX_JOB_CONTROL);
141 case _SC_SAVED_IDS:
142 /* XXX - must be 1 */
143 mib[0] = CTL_KERN;
144 mib[1] = KERN_SAVED_IDS;
145 goto yesno;
146 case _SC_VERSION:
147 mib[0] = CTL_KERN;
148 mib[1] = KERN_POSIX1;
149 break;
150 case _SC_BC_BASE_MAX:
151 return (BC_BASE_MAX);
152 case _SC_BC_DIM_MAX:
153 return (BC_DIM_MAX);
154 case _SC_BC_SCALE_MAX:
155 return (BC_SCALE_MAX);
156 case _SC_BC_STRING_MAX:
157 return (BC_STRING_MAX);
158 case _SC_COLL_WEIGHTS_MAX:
159 return (COLL_WEIGHTS_MAX);
160 case _SC_EXPR_NEST_MAX:
161 return (EXPR_NEST_MAX);
162 case _SC_LINE_MAX:
163 return (LINE_MAX);
164 case _SC_RE_DUP_MAX:
165 return (RE_DUP_MAX);
166 case _SC_2_VERSION:
167 /*
168 * This is something of a lie, but it would be silly at
169 * this point to try to deduce this from the contents
170 * of the filesystem.
171 */
172 return (_POSIX2_VERSION);
173 case _SC_2_C_BIND:
174 return (_POSIX2_C_BIND);
175 case _SC_2_C_DEV:
176 return (_POSIX2_C_DEV);
177 case _SC_2_CHAR_TERM:
178 return (_POSIX2_CHAR_TERM);
179 case _SC_2_FORT_DEV:
180 return (_POSIX2_FORT_DEV);
181 case _SC_2_FORT_RUN:
182 return (_POSIX2_FORT_RUN);
183 case _SC_2_LOCALEDEF:
184 return (_POSIX2_LOCALEDEF);
185 case _SC_2_SW_DEV:
186 return (_POSIX2_SW_DEV);
187 case _SC_2_UPE:
188 return (_POSIX2_UPE);
189 case _SC_TZNAME_MAX:
190 path = _PATH_ZONEINFO;
191 do_NAME_MAX:
192 sverrno = errno;
193 errno = 0;
194 lvalue = pathconf(path, _PC_NAME_MAX);
195 if (lvalue == -1 && errno != 0)
196 return (-1);
197 errno = sverrno;
198 return (lvalue);
199
200 case _SC_ASYNCHRONOUS_IO:
201 #if _POSIX_ASYNCHRONOUS_IO == 0
202 mib[0] = CTL_P1003_1B;
203 mib[1] = CTL_P1003_1B_ASYNCHRONOUS_IO;
204 break;
205 #else
206 return (_POSIX_ASYNCHRONOUS_IO);
207 #endif
208 case _SC_MAPPED_FILES:
209 return (_POSIX_MAPPED_FILES);
210 case _SC_MEMLOCK:
211 return (_POSIX_MEMLOCK);
212 case _SC_MEMLOCK_RANGE:
213 return (_POSIX_MEMLOCK_RANGE);
214 case _SC_MEMORY_PROTECTION:
215 return (_POSIX_MEMORY_PROTECTION);
216 case _SC_MESSAGE_PASSING:
217 #if _POSIX_MESSAGE_PASSING == 0
218 mib[0] = CTL_P1003_1B;
219 mib[1] = CTL_P1003_1B_MESSAGE_PASSING;
220 goto yesno;
221 #else
222 return (_POSIX_MESSAGE_PASSING);
223 #endif
224 case _SC_PRIORITIZED_IO:
225 #if _POSIX_PRIORITIZED_IO == 0
226 mib[0] = CTL_P1003_1B;
227 mib[1] = CTL_P1003_1B_PRIORITIZED_IO;
228 goto yesno;
229 #else
230 return (_POSIX_PRIORITIZED_IO);
231 #endif
232 case _SC_PRIORITY_SCHEDULING:
233 #if _POSIX_PRIORITY_SCHEDULING == 0
234 mib[0] = CTL_P1003_1B;
235 mib[1] = CTL_P1003_1B_PRIORITY_SCHEDULING;
236 goto yesno;
237 #else
238 return (_POSIX_PRIORITY_SCHEDULING);
239 #endif
240 case _SC_REALTIME_SIGNALS:
241 #if _POSIX_REALTIME_SIGNALS == 0
242 mib[0] = CTL_P1003_1B;
243 mib[1] = CTL_P1003_1B_REALTIME_SIGNALS;
244 goto yesno;
245 #else
246 return (_POSIX_REALTIME_SIGNALS);
247 #endif
248 case _SC_SEMAPHORES:
249 #if _POSIX_SEMAPHORES == 0
250 mib[0] = CTL_P1003_1B;
251 mib[1] = CTL_P1003_1B_SEMAPHORES;
252 goto yesno;
253 #else
254 return (_POSIX_SEMAPHORES);
255 #endif
256 case _SC_FSYNC:
257 return (_POSIX_FSYNC);
258
259 case _SC_SHARED_MEMORY_OBJECTS:
260 return (_POSIX_SHARED_MEMORY_OBJECTS);
261 case _SC_SYNCHRONIZED_IO:
262 #if _POSIX_SYNCHRONIZED_IO == 0
263 mib[0] = CTL_P1003_1B;
264 mib[1] = CTL_P1003_1B_SYNCHRONIZED_IO;
265 goto yesno;
266 #else
267 return (_POSIX_SYNCHRONIZED_IO);
268 #endif
269 case _SC_TIMERS:
270 #if _POSIX_TIMERS == 0
271 mib[0] = CTL_P1003_1B;
272 mib[1] = CTL_P1003_1B_TIMERS;
273 goto yesno;
274 #else
275 return (_POSIX_TIMERS);
276 #endif
277 case _SC_AIO_LISTIO_MAX:
278 #if defined(CTL_P1003_1B) && defined(CTL_P1003_1B_AIO_LISTIO_MAX)
279 mib[0] = CTL_P1003_1B;
280 mib[1] = CTL_P1003_1B_AIO_LISTIO_MAX;
281 #else
282 mib[0] = CTL_KERN;;
283 mib[1] = KERN_AIOMAX;
284 #endif
285 break;
286 case _SC_AIO_MAX:
287 #if defined(CTL_P1003_1B) && defined(CTL_P1003_1B_AIO_MAX)
288 mib[0] = CTL_P1003_1B;
289 mib[1] = CTL_P1003_1B_AIO_MAX;
290 #else
291 mib[0] = CTL_KERN;;
292 mib[1] = KERN_AIOMAX;
293 #endif
294 break;
295 case _SC_AIO_PRIO_DELTA_MAX:
296 #if defined(CTL_P1003_1B) && defined(CTL_P1003_1B_AIO_PRIO_DELTA_MAX)
297 mib[0] = CTL_P1003_1B;
298 mib[1] = CTL_P1003_1B_AIO_PRIO_DELTA_MAX;
299 break;
300 #else
301 return (-1);
302 #endif
303 case _SC_DELAYTIMER_MAX:
304 #if defined(CTL_P1003_1B) && defined(CTL_P1003_1B_DELAYTIMER_MAX)
305 mib[0] = CTL_P1003_1B;
306 mib[1] = CTL_P1003_1B_DELAYTIMER_MAX;
307 goto yesno;
308 #else
309 return (-1);
310 #endif
311 case _SC_MQ_OPEN_MAX:
312 #if defined(CTL_P1003_1B) && defined(CTL_P1003_1B_MQ_OPEN_MAX)
313 mib[0] = CTL_P1003_1B;
314 mib[1] = CTL_P1003_1B_MQ_OPEN_MAX;
315 goto yesno;
316 #else
317 return (-1);
318 #endif
319 case _SC_PAGESIZE:
320 defaultresult = getpagesize();
321 #if defined(CTL_P1003_1B) && defined(CTL_P1003_1B_PAGESIZE)
322 mib[0] = CTL_P1003_1B;
323 mib[1] = CTL_P1003_1B_PAGESIZE;
324 goto yesno;
325 #else
326 return defaultresult;
327 #endif
328 case _SC_RTSIG_MAX:
329 #if defined(CTL_P1003_1B) && defined(CTL_P1003_1B_RTSIG_MAX)
330 mib[0] = CTL_P1003_1B;
331 mib[1] = CTL_P1003_1B_RTSIG_MAX;
332 goto yesno;
333 #else
334 return (-1);
335 #endif
336 case _SC_SEM_NSEMS_MAX:
337 #if defined(CTL_P1003_1B) && defined(CTL_P1003_1B_RTSIG_MAX)
338 mib[0] = CTL_P1003_1B;
339 mib[1] = CTL_P1003_1B_SEM_NSEMS_MAX;
340 goto yesno;
341 #else
342 len = sizeof(value);
343 return (sysctlbyname("kern.sysv.semmns", &value, &len, NULL, 0) == -1 ? -1 : value);
344 #endif
345
346 case _SC_SEM_VALUE_MAX:
347 #if SEM_VALUE_MAX == 0
348 mib[0] = CTL_P1003_1B;
349 mib[1] = CTL_P1003_1B_SEM_VALUE_MAX;
350 goto yesno;
351 #else
352 return (SEM_VALUE_MAX);
353 #endif
354 case _SC_SIGQUEUE_MAX:
355 #if defined(CTL_P1003_1B) && defined(CTL_P1003_1B_SIGQUEUE_MAX)
356 mib[0] = CTL_P1003_1B;
357 mib[1] = CTL_P1003_1B_SIGQUEUE_MAX;
358 goto yesno;
359 #else
360 return (-1);
361 #endif
362 case _SC_TIMER_MAX:
363 #if defined(CTL_P1003_1B) && defined(CTL_P1003_1B_TIMER_MAX)
364 mib[0] = CTL_P1003_1B;
365 mib[1] = CTL_P1003_1B_TIMER_MAX;
366 #else
367 return (-1);
368 #endif
369
370 yesno:
371 len = sizeof(value);
372 if (sysctl(mib, 2, &value, &len, NULL, 0) == -1)
373 return (-1);
374 if (value == 0)
375 return (defaultresult);
376 return ((long)value);
377
378 case _SC_2_PBS:
379 case _SC_2_PBS_ACCOUNTING:
380 case _SC_2_PBS_CHECKPOINT:
381 case _SC_2_PBS_LOCATE:
382 case _SC_2_PBS_MESSAGE:
383 case _SC_2_PBS_TRACK:
384 #if _POSIX2_PBS == 0
385 #error "don't know how to determine _SC_2_PBS"
386 /*
387 * This probably requires digging through the filesystem
388 * to see if the appropriate package has been installed.
389 * Since we don't currently support this option at all,
390 * it's not worth the effort to write the code now.
391 * Figuring out which of the sub-options are supported
392 * would be even more difficult, so it's probably easier
393 * to always say ``no''.
394 */
395 #else
396 return (_POSIX2_PBS);
397 #endif
398 case _SC_ADVISORY_INFO:
399 #if _POSIX_ADVISORY_INFO == 0
400 #error "_POSIX_ADVISORY_INFO"
401 #else
402 return (_POSIX_ADVISORY_INFO);
403 #endif
404 case _SC_BARRIERS:
405 #if _POSIX_BARRIERS == 0
406 #error "_POSIX_BARRIERS"
407 #else
408 return (_POSIX_BARRIERS);
409 #endif
410 case _SC_CLOCK_SELECTION:
411 #if _POSIX_CLOCK_SELECTION == 0
412 #error "_POSIX_CLOCK_SELECTION"
413 #else
414 return (_POSIX_CLOCK_SELECTION);
415 #endif
416 case _SC_CPUTIME:
417 #if _POSIX_CPUTIME == 0
418 #error "_POSIX_CPUTIME"
419 #else
420 return (_POSIX_CPUTIME);
421 #endif
422 case _SC_FILE_LOCKING:
423 case _SC_GETGR_R_SIZE_MAX:
424 /* return sizeof(group) + group_name_max + group_passwd_max + max_group_member*(MAXLOGNAME+1); */
425 return 4096; /* INT_MAX is too big for Perl */
426 case _SC_GETPW_R_SIZE_MAX:
427 return 4096;
428 case _SC_HOST_NAME_MAX:
429 return (MAXHOSTNAMELEN - 1); /* does not include \0 */
430 case _SC_LOGIN_NAME_MAX:
431 return (MAXLOGNAME);
432 case _SC_MONOTONIC_CLOCK:
433 #if _POSIX_MONOTONIC_CLOCK == 0
434 #error "_POSIX_MONOTONIC_CLOCK"
435 #else
436 return (_POSIX_MONOTONIC_CLOCK);
437 #endif
438 case _SC_MQ_PRIO_MAX:
439 return (-1);
440 case _SC_READER_WRITER_LOCKS:
441 return (_POSIX_READER_WRITER_LOCKS);
442 case _SC_REGEXP:
443 return (_POSIX_REGEXP);
444 case _SC_SHELL:
445 return (_POSIX_SHELL);
446 case _SC_SPAWN:
447 return (_POSIX_SPAWN);
448 case _SC_SPIN_LOCKS:
449 return (_POSIX_SPIN_LOCKS);
450 case _SC_SPORADIC_SERVER:
451 #if _POSIX_SPORADIC_SERVER == 0
452 #error "_POSIX_SPORADIC_SERVER"
453 #else
454 return (_POSIX_SPORADIC_SERVER);
455 #endif
456 case _SC_THREAD_ATTR_STACKADDR:
457 return (_POSIX_THREAD_ATTR_STACKADDR);
458 case _SC_THREAD_ATTR_STACKSIZE:
459 return (_POSIX_THREAD_ATTR_STACKSIZE);
460 case _SC_THREAD_CPUTIME:
461 return (_POSIX_THREAD_CPUTIME);
462 case _SC_THREAD_DESTRUCTOR_ITERATIONS:
463 return (PTHREAD_DESTRUCTOR_ITERATIONS);
464 case _SC_THREAD_KEYS_MAX:
465 return (PTHREAD_KEYS_MAX);
466 case _SC_THREAD_PRIO_INHERIT:
467 return (_POSIX_THREAD_PRIO_INHERIT);
468 case _SC_THREAD_PRIO_PROTECT:
469 return (_POSIX_THREAD_PRIO_PROTECT);
470 case _SC_THREAD_PRIORITY_SCHEDULING:
471 return (_POSIX_THREAD_PRIORITY_SCHEDULING);
472 case _SC_THREAD_PROCESS_SHARED:
473 return (_POSIX_THREAD_PROCESS_SHARED);
474 case _SC_THREAD_SAFE_FUNCTIONS:
475 return (_POSIX_THREAD_SAFE_FUNCTIONS);
476 case _SC_THREAD_SPORADIC_SERVER:
477 return (_POSIX_THREAD_SPORADIC_SERVER);
478 case _SC_THREAD_STACK_MIN:
479 return (PTHREAD_STACK_MIN);
480 case _SC_THREAD_THREADS_MAX:
481 #ifdef PTHREAD_THREADS_MAX
482 return (PTHREAD_THREADS_MAX); /* XXX wrong type! */
483 #else
484 return (-1);
485 #endif
486 case _SC_TIMEOUTS:
487 return (_POSIX_TIMEOUTS);
488 case _SC_THREADS:
489 return (_POSIX_THREADS);
490 case _SC_TRACE:
491 #if _POSIX_TRACE == 0
492 #error "_POSIX_TRACE"
493 /* While you're implementing this, also do the ones below. */
494 #else
495 return (_POSIX_TRACE);
496 #endif
497 case _SC_TRACE_EVENT_FILTER:
498 return (_POSIX_TRACE_EVENT_FILTER);
499 case _SC_TRACE_INHERIT:
500 return (_POSIX_TRACE_INHERIT);
501 case _SC_TRACE_LOG:
502 return (_POSIX_TRACE_LOG);
503 case _SC_TTY_NAME_MAX:
504 path = "/"; // should be _PATH_DEV (PR-3624562)
505 goto do_NAME_MAX;
506 case _SC_TYPED_MEMORY_OBJECTS:
507 #if _POSIX_TYPED_MEMORY_OBJECTS == 0
508 #error "_POSIX_TYPED_MEMORY_OBJECTS"
509 #else
510 return (_POSIX_TYPED_MEMORY_OBJECTS);
511 #endif
512 case _SC_V6_ILP32_OFF32:
513 #if _V6_ILP32_OFF32 == 0
514 if (sizeof(int) * CHAR_BIT == 32 &&
515 sizeof(int) == sizeof(long) &&
516 sizeof(long) == sizeof(void *) &&
517 sizeof(void *) == sizeof(off_t))
518 return 1;
519 else
520 return -1;
521 #else
522 return (_V6_ILP32_OFF32);
523 #endif
524 case _SC_V6_ILP32_OFFBIG:
525 #if _V6_ILP32_OFFBIG == 0
526 if (sizeof(int) * CHAR_BIT == 32 &&
527 sizeof(int) == sizeof(long) &&
528 sizeof(long) == sizeof(void *) &&
529 sizeof(off_t) * CHAR_BIT >= 64)
530 return 1;
531 else
532 return -1;
533 #else
534 return (_V6_ILP32_OFFBIG);
535 #endif
536 case _SC_V6_LP64_OFF64:
537 #if _V6_LP64_OFF64 == 0
538 if (sizeof(int) * CHAR_BIT == 32 &&
539 sizeof(long) * CHAR_BIT == 64 &&
540 sizeof(long) == sizeof(void *) &&
541 sizeof(void *) == sizeof(off_t))
542 return 1;
543 else
544 return -1;
545 #else
546 return (_V6_LP64_OFF64);
547 #endif
548 case _SC_V6_LPBIG_OFFBIG:
549 #if _V6_LPBIG_OFFBIG == 0
550 if (sizeof(int) * CHAR_BIT >= 32 &&
551 sizeof(long) * CHAR_BIT >= 64 &&
552 sizeof(void *) * CHAR_BIT >= 64 &&
553 sizeof(off_t) * CHAR_BIT >= 64)
554 return 1;
555 else
556 return -1;
557 #else
558 return (_V6_LPBIG_OFFBIG);
559 #endif
560 case _SC_ATEXIT_MAX:
561 return (INT_MAX); /* unlimited */
562 case _SC_IOV_MAX:
563 #ifdef KERN_IOV_MAX
564 mib[0] = CTL_KERN;
565 mib[1] = KERN_IOV_MAX;
566 break;
567 #else
568 return (IOV_MAX);
569 #endif
570 case _SC_XOPEN_CRYPT:
571 return (_XOPEN_CRYPT);
572 case _SC_XOPEN_ENH_I18N:
573 return (_XOPEN_ENH_I18N);
574 case _SC_XOPEN_LEGACY:
575 return (_XOPEN_LEGACY);
576 case _SC_XOPEN_REALTIME:
577 #if _XOPEN_REALTIME == 0
578 sverrno = errno;
579 value = sysconf(_SC_ASYNCHRONOUS_IO) > 0 &&
580 sysconf(_SC_MEMLOCK) > 0 &&
581 sysconf(_SC_MEMLOCK_RANGE) > 0 &&
582 sysconf(_SC_MESSAGE_PASSING) > 0 &&
583 sysconf(_SC_PRIORITY_SCHEDULING) > 0 &&
584 sysconf(_SC_REALTIME_SIGNALS) > 0 &&
585 sysconf(_SC_SEMAPHORES) > 0 &&
586 sysconf(_SC_SHARED_MEMORY_OBJECTS) > 0 &&
587 sysconf(_SC_SYNCHRONIZED_IO) > 0 &&
588 sysconf(_SC_TIMERS) > 0;
589 errno = sverrno;
590 if (value)
591 return (200112L);
592 else
593 return (-1);
594 #else
595 return (_XOPEN_REALTIME);
596 #endif
597 case _SC_XOPEN_REALTIME_THREADS:
598 #if _XOPEN_REALTIME_THREADS == 0
599 #error "_XOPEN_REALTIME_THREADS"
600 #else
601 return (_XOPEN_REALTIME_THREADS);
602 #endif
603 case _SC_XOPEN_SHM:
604 sverrno = errno;
605 len = sizeof(qdvalue);
606 if (sysctlbyname("kern.sysv.shmmin", &qdvalue, &len, NULL,
607 0) == -1) {
608 errno = sverrno;
609 return (-1);
610 }
611 errno = sverrno;
612 return (1);
613 case _SC_XOPEN_STREAMS:
614 return (_XOPEN_STREAMS);
615 case _SC_XOPEN_UNIX:
616 return (_XOPEN_UNIX);
617 #ifdef _XOPEN_VERSION
618 case _SC_XOPEN_VERSION:
619 return (_XOPEN_VERSION);
620 #endif
621 #ifdef _XOPEN_XCU_VERSION
622 case _SC_XOPEN_XCU_VERSION:
623 return (_XOPEN_XCU_VERSION);
624 #endif
625 case _SC_SYMLOOP_MAX:
626 return (MAXSYMLINKS);
627 case _SC_RAW_SOCKETS:
628 return (_POSIX_RAW_SOCKETS);
629 case _SC_IPV6:
630 #if _POSIX_IPV6 == 0
631 sverrno = errno;
632 value = socket(PF_INET6, SOCK_DGRAM, 0);
633 errno = sverrno;
634 if (value >= 0) {
635 close(value);
636 return (200112L);
637 } else
638 return (0);
639 #else
640 return (_POSIX_IPV6);
641 #endif
642
643 #ifdef _SC_NPROCESSORS_CONF
644 case _SC_NPROCESSORS_CONF:
645 #endif
646 #ifdef _SC_NPROCESSORS_ONLN
647 case _SC_NPROCESSORS_ONLN:
648 #endif
649 #if defined(_SC_NPROCESSORS_CONF) || defined(_SC_NPROCESSORS_ONLN)
650 mib[0] = CTL_HW;
651 mib[1] = HW_NCPU;
652 break;
653 #endif
654 case _SC_XBS5_ILP32_OFF32:
655 return (_XBS5_ILP32_OFF32);
656 case _SC_XBS5_ILP32_OFFBIG:
657 return (_XBS5_ILP32_OFFBIG);
658 case _SC_XBS5_LP64_OFF64:
659 return (_XBS5_LP64_OFF64);
660 case _SC_XBS5_LPBIG_OFFBIG:
661 return (_XBS5_LPBIG_OFFBIG);
662 case _SC_SS_REPL_MAX:
663 return (_POSIX_SS_REPL_MAX);
664 case _SC_TRACE_EVENT_NAME_MAX:
665 return (_POSIX_TRACE_EVENT_NAME_MAX);
666 case _SC_TRACE_NAME_MAX:
667 return (_POSIX_TRACE_NAME_MAX);
668 case _SC_TRACE_SYS_MAX:
669 return (_POSIX_TRACE_SYS_MAX);
670 case _SC_TRACE_USER_EVENT_MAX:
671 return (_POSIX_TRACE_USER_EVENT_MAX);
672 case _SC_PASS_MAX:
673 return (PASS_MAX);
674
675 #ifdef _SC_PHYS_PAGES
676 case _SC_PHYS_PAGES:
677 #ifdef __APPLE__
678 {
679 long memsize;
680 long pagesize;
681
682 len = sizeof(memsize);
683 if (sysctlbyname("hw.memsize", &memsize, &len, NULL, 0) == -1)
684 return (-1);
685
686 len = sizeof(pagesize);
687 if (sysctlbyname("hw.pagesize", &pagesize, &len, NULL, 0) == -1)
688 return (-1);
689
690 return (memsize / pagesize);
691 }
692 #else
693 len = sizeof(lvalue);
694 if (sysctlbyname("hw.availpages", &lvalue, &len, NULL, 0) == -1)
695 return (-1);
696 return (lvalue);
697 #endif
698 #endif
699
700 default:
701 errno = EINVAL;
702 return (-1);
703 }
704 len = sizeof(value);
705 if (sysctl(mib, 2, &value, &len, NULL, 0) == -1)
706 value = -1;
707 return ((long)value);
708 }