mqueues: Add support for _SC_MQ_PRIO_MAX in sysconf(3).
[dragonfly.git] / lib / libc / gen / sysconf.c
CommitLineData
984263bc
MD
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.
984263bc
MD
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.
1de703da
MD
31 *
32 * @(#)sysconf.c 8.2 (Berkeley) 3/20/94
9d66746c 33 * $FreeBSD: src/lib/libc/gen/sysconf.c,v 1.26 2008/02/27 05:56:57 wollman Exp $
dd47c5d8 34 * $DragonFly: src/lib/libc/gen/sysconf.c,v 1.5 2008/02/21 12:47:54 hasso Exp $
984263bc
MD
35 */
36
984263bc
MD
37#include <sys/param.h>
38#include <sys/time.h>
39#include <sys/sysctl.h>
40#include <sys/resource.h>
9d66746c 41#include <sys/socket.h>
984263bc
MD
42
43#include <errno.h>
9d66746c
PA
44#include <limits.h>
45#include <paths.h>
46#include <pthread.h> /* we just need the limits */
984263bc
MD
47#include <time.h>
48#include <unistd.h>
49
9d66746c
PA
50#include "../stdlib/atexit.h"
51#include "../stdtime/tzfile.h"
52
53#define _PATH_ZONEINFO TZDIR /* from tzfile.h */
54
984263bc
MD
55/*
56 * sysconf --
57 * get configurable system variables.
58 *
59 * XXX
60 * POSIX 1003.1 (ISO/IEC 9945-1, 4.8.1.3) states that the variable values
61 * not change during the lifetime of the calling process. This would seem
62 * to require that any change to system limits kill all running processes.
63 * A workaround might be to cache the values when they are first retrieved
64 * and then simply return the cached value on subsequent calls. This is
65 * less useful than returning up-to-date values, however.
66 */
67long
0f52d283 68sysconf(int name)
984263bc
MD
69{
70 struct rlimit rl;
71 size_t len;
9d66746c
PA
72 int mib[2], sverrno, value;
73 long lvalue, defaultresult;
74 const char *path;
984263bc 75
984263bc
MD
76 defaultresult = -1;
77
78 switch (name) {
984263bc
MD
79 case _SC_ARG_MAX:
80 mib[0] = CTL_KERN;
81 mib[1] = KERN_ARGMAX;
82 break;
83 case _SC_CHILD_MAX:
9d66746c
PA
84 if (getrlimit(RLIMIT_NPROC, &rl) != 0)
85 return (-1);
86 if (rl.rlim_cur == RLIM_INFINITY)
87 return (-1);
88 if (rl.rlim_cur > LONG_MAX) {
89 errno = EOVERFLOW;
90 return (-1);
91 }
92 return ((long)rl.rlim_cur);
984263bc
MD
93 case _SC_CLK_TCK:
94 return (CLK_TCK);
984263bc
MD
95 case _SC_NGROUPS_MAX:
96 mib[0] = CTL_KERN;
97 mib[1] = KERN_NGROUPS;
98 break;
99 case _SC_OPEN_MAX:
9d66746c
PA
100 if (getrlimit(RLIMIT_NOFILE, &rl) != 0)
101 return (-1);
102 if (rl.rlim_cur == RLIM_INFINITY)
103 return (-1);
104 if (rl.rlim_cur > LONG_MAX) {
105 errno = EOVERFLOW;
106 return (-1);
107 }
108 return ((long)rl.rlim_cur);
984263bc 109 case _SC_STREAM_MAX:
9d66746c
PA
110 if (getrlimit(RLIMIT_NOFILE, &rl) != 0)
111 return (-1);
112 if (rl.rlim_cur == RLIM_INFINITY)
113 return (-1);
114 if (rl.rlim_cur > LONG_MAX) {
115 errno = EOVERFLOW;
116 return (-1);
117 }
118 /*
119 * struct __sFILE currently has a limitation that
120 * file descriptors must fit in a signed short.
121 * This doesn't precisely capture the letter of POSIX
122 * but approximates the spirit.
123 */
124 if (rl.rlim_cur > SHRT_MAX)
125 return (SHRT_MAX);
126
127 return ((long)rl.rlim_cur);
128 case _SC_JOB_CONTROL:
129 return (_POSIX_JOB_CONTROL);
984263bc 130 case _SC_SAVED_IDS:
9d66746c 131 /* XXX - must be 1 */
984263bc
MD
132 mib[0] = CTL_KERN;
133 mib[1] = KERN_SAVED_IDS;
134 goto yesno;
135 case _SC_VERSION:
136 mib[0] = CTL_KERN;
137 mib[1] = KERN_POSIX1;
138 break;
984263bc 139 case _SC_BC_BASE_MAX:
9d66746c 140 return (BC_BASE_MAX);
984263bc 141 case _SC_BC_DIM_MAX:
9d66746c 142 return (BC_DIM_MAX);
984263bc 143 case _SC_BC_SCALE_MAX:
9d66746c 144 return (BC_SCALE_MAX);
984263bc 145 case _SC_BC_STRING_MAX:
9d66746c 146 return (BC_STRING_MAX);
984263bc 147 case _SC_COLL_WEIGHTS_MAX:
9d66746c 148 return (COLL_WEIGHTS_MAX);
984263bc 149 case _SC_EXPR_NEST_MAX:
9d66746c 150 return (EXPR_NEST_MAX);
984263bc 151 case _SC_LINE_MAX:
9d66746c 152 return (LINE_MAX);
984263bc 153 case _SC_RE_DUP_MAX:
9d66746c 154 return (RE_DUP_MAX);
984263bc 155 case _SC_2_VERSION:
9d66746c
PA
156 /*
157 * This is something of a lie, but it would be silly at
158 * this point to try to deduce this from the contents
159 * of the filesystem.
160 */
161 return (_POSIX2_VERSION);
984263bc 162 case _SC_2_C_BIND:
9d66746c 163 return (_POSIX2_C_BIND);
984263bc 164 case _SC_2_C_DEV:
9d66746c 165 return (_POSIX2_C_DEV);
984263bc 166 case _SC_2_CHAR_TERM:
9d66746c 167 return (_POSIX2_CHAR_TERM);
984263bc 168 case _SC_2_FORT_DEV:
9d66746c 169 return (_POSIX2_FORT_DEV);
984263bc 170 case _SC_2_FORT_RUN:
9d66746c 171 return (_POSIX2_FORT_RUN);
984263bc 172 case _SC_2_LOCALEDEF:
9d66746c 173 return (_POSIX2_LOCALEDEF);
984263bc 174 case _SC_2_SW_DEV:
9d66746c 175 return (_POSIX2_SW_DEV);
984263bc 176 case _SC_2_UPE:
9d66746c
PA
177 return (_POSIX2_UPE);
178 case _SC_TZNAME_MAX:
179 path = _PATH_ZONEINFO;
180do_NAME_MAX:
181 sverrno = errno;
182 errno = 0;
183 lvalue = pathconf(path, _PC_NAME_MAX);
184 if (lvalue == -1 && errno != 0)
185 return (-1);
186 errno = sverrno;
187 return (lvalue);
984263bc
MD
188
189 case _SC_ASYNCHRONOUS_IO:
9d66746c 190#if _POSIX_ASYNCHRONOUS_IO == 0
984263bc
MD
191 mib[0] = CTL_P1003_1B;
192 mib[1] = CTL_P1003_1B_ASYNCHRONOUS_IO;
9d66746c
PA
193 break;
194#else
195 return (_POSIX_ASYNCHRONOUS_IO);
196#endif
984263bc 197 case _SC_MAPPED_FILES:
9d66746c 198 return (_POSIX_MAPPED_FILES);
984263bc 199 case _SC_MEMLOCK:
9d66746c 200 return (_POSIX_MEMLOCK);
984263bc 201 case _SC_MEMLOCK_RANGE:
9d66746c 202 return (_POSIX_MEMLOCK_RANGE);
984263bc 203 case _SC_MEMORY_PROTECTION:
9d66746c 204 return (_POSIX_MEMORY_PROTECTION);
984263bc 205 case _SC_MESSAGE_PASSING:
9d66746c 206#if _POSIX_MESSAGE_PASSING == 0
984263bc
MD
207 mib[0] = CTL_P1003_1B;
208 mib[1] = CTL_P1003_1B_MESSAGE_PASSING;
209 goto yesno;
9d66746c
PA
210#else
211 return (_POSIX_MESSAGE_PASSING);
212#endif
984263bc 213 case _SC_PRIORITIZED_IO:
9d66746c 214#if _POSIX_PRIORITIZED_IO == 0
984263bc
MD
215 mib[0] = CTL_P1003_1B;
216 mib[1] = CTL_P1003_1B_PRIORITIZED_IO;
217 goto yesno;
9d66746c
PA
218#else
219 return (_POSIX_PRIORITIZED_IO);
220#endif
984263bc 221 case _SC_PRIORITY_SCHEDULING:
9d66746c 222#if _POSIX_PRIORITY_SCHEDULING == 0
984263bc
MD
223 mib[0] = CTL_P1003_1B;
224 mib[1] = CTL_P1003_1B_PRIORITY_SCHEDULING;
225 goto yesno;
9d66746c
PA
226#else
227 return (_POSIX_PRIORITY_SCHEDULING);
228#endif
984263bc 229 case _SC_REALTIME_SIGNALS:
9d66746c 230#if _POSIX_REALTIME_SIGNALS == 0
984263bc
MD
231 mib[0] = CTL_P1003_1B;
232 mib[1] = CTL_P1003_1B_REALTIME_SIGNALS;
233 goto yesno;
9d66746c
PA
234#else
235 return (_POSIX_REALTIME_SIGNALS);
236#endif
984263bc 237 case _SC_SEMAPHORES:
9d66746c 238#if _POSIX_SEMAPHORES == 0
984263bc
MD
239 mib[0] = CTL_P1003_1B;
240 mib[1] = CTL_P1003_1B_SEMAPHORES;
241 goto yesno;
9d66746c
PA
242#else
243 return (_POSIX_SEMAPHORES);
244#endif
984263bc 245 case _SC_FSYNC:
9d66746c
PA
246 return (_POSIX_FSYNC);
247
984263bc 248 case _SC_SHARED_MEMORY_OBJECTS:
9d66746c 249 return (_POSIX_SHARED_MEMORY_OBJECTS);
984263bc 250 case _SC_SYNCHRONIZED_IO:
9d66746c 251#if _POSIX_SYNCHRONIZED_IO == 0
984263bc
MD
252 mib[0] = CTL_P1003_1B;
253 mib[1] = CTL_P1003_1B_SYNCHRONIZED_IO;
254 goto yesno;
9d66746c
PA
255#else
256 return (_POSIX_SYNCHRONIZED_IO);
257#endif
984263bc 258 case _SC_TIMERS:
9d66746c 259#if _POSIX_TIMERS == 0
984263bc
MD
260 mib[0] = CTL_P1003_1B;
261 mib[1] = CTL_P1003_1B_TIMERS;
262 goto yesno;
9d66746c
PA
263#else
264 return (_POSIX_TIMERS);
265#endif
984263bc
MD
266 case _SC_AIO_LISTIO_MAX:
267 mib[0] = CTL_P1003_1B;
268 mib[1] = CTL_P1003_1B_AIO_LISTIO_MAX;
9d66746c 269 break;
984263bc
MD
270 case _SC_AIO_MAX:
271 mib[0] = CTL_P1003_1B;
272 mib[1] = CTL_P1003_1B_AIO_MAX;
9d66746c 273 break;
984263bc
MD
274 case _SC_AIO_PRIO_DELTA_MAX:
275 mib[0] = CTL_P1003_1B;
276 mib[1] = CTL_P1003_1B_AIO_PRIO_DELTA_MAX;
9d66746c 277 break;
984263bc
MD
278 case _SC_DELAYTIMER_MAX:
279 mib[0] = CTL_P1003_1B;
280 mib[1] = CTL_P1003_1B_DELAYTIMER_MAX;
281 goto yesno;
282 case _SC_MQ_OPEN_MAX:
283 mib[0] = CTL_P1003_1B;
284 mib[1] = CTL_P1003_1B_MQ_OPEN_MAX;
285 goto yesno;
286 case _SC_PAGESIZE:
287 defaultresult = getpagesize();
288 mib[0] = CTL_P1003_1B;
289 mib[1] = CTL_P1003_1B_PAGESIZE;
290 goto yesno;
291 case _SC_RTSIG_MAX:
292 mib[0] = CTL_P1003_1B;
293 mib[1] = CTL_P1003_1B_RTSIG_MAX;
294 goto yesno;
295 case _SC_SEM_NSEMS_MAX:
296 mib[0] = CTL_P1003_1B;
297 mib[1] = CTL_P1003_1B_SEM_NSEMS_MAX;
298 goto yesno;
299 case _SC_SEM_VALUE_MAX:
300 mib[0] = CTL_P1003_1B;
301 mib[1] = CTL_P1003_1B_SEM_VALUE_MAX;
302 goto yesno;
303 case _SC_SIGQUEUE_MAX:
304 mib[0] = CTL_P1003_1B;
305 mib[1] = CTL_P1003_1B_SIGQUEUE_MAX;
306 goto yesno;
307 case _SC_TIMER_MAX:
308 mib[0] = CTL_P1003_1B;
309 mib[1] = CTL_P1003_1B_TIMER_MAX;
9d66746c
PA
310yesno:
311 len = sizeof(value);
312 if (sysctl(mib, 2, &value, &len, NULL, 0) == -1)
313 return (-1);
314 if (value == 0)
315 return (defaultresult);
316 return ((long)value);
317
318 case _SC_2_PBS:
319 case _SC_2_PBS_ACCOUNTING:
320 case _SC_2_PBS_CHECKPOINT:
321 case _SC_2_PBS_LOCATE:
322 case _SC_2_PBS_MESSAGE:
323 case _SC_2_PBS_TRACK:
324#if _POSIX2_PBS == 0
325#error "don't know how to determine _SC_2_PBS"
326 /*
327 * This probably requires digging through the filesystem
328 * to see if the appropriate package has been installed.
329 * Since we don't currently support this option at all,
330 * it's not worth the effort to write the code now.
331 * Figuring out which of the sub-options are supported
332 * would be even more difficult, so it's probably easier
333 * to always say ``no''.
334 */
335#else
336 return (_POSIX2_PBS);
337#endif
338 case _SC_ADVISORY_INFO:
339#if _POSIX_ADVISORY_INFO == 0
340#error "_POSIX_ADVISORY_INFO"
341#else
342 return (_POSIX_ADVISORY_INFO);
343#endif
344 case _SC_BARRIERS:
345#if _POSIX_BARRIERS == 0
346#error "_POSIX_BARRIERS"
347#else
348 return (_POSIX_BARRIERS);
349#endif
350 case _SC_CLOCK_SELECTION:
351#if _POSIX_CLOCK_SELECTION == 0
352#error "_POSIX_CLOCK_SELECTION"
353#else
354 return (_POSIX_CLOCK_SELECTION);
355#endif
356 case _SC_CPUTIME:
357#if _POSIX_CPUTIME == 0
358#error "_POSIX_CPUTIME"
359#else
360 return (_POSIX_CPUTIME);
361#endif
362#ifdef notdef
363 case _SC_FILE_LOCKING:
364 /*
365 * XXX - The standard doesn't tell us how to define
366 * _POSIX_FILE_LOCKING, so we can't answer this one.
367 */
368#endif
369#if _POSIX_THREAD_SAFE_FUNCTIONS > -1
370 case _SC_GETGR_R_SIZE_MAX:
371 case _SC_GETPW_R_SIZE_MAX:
372#error "somebody needs to implement this"
373#endif
374 case _SC_HOST_NAME_MAX:
375 return (MAXHOSTNAMELEN - 1); /* does not include \0 */
376 case _SC_LOGIN_NAME_MAX:
377 return (MAXLOGNAME);
378 case _SC_MONOTONIC_CLOCK:
379#if _POSIX_MONOTONIC_CLOCK == 0
380#error "_POSIX_MONOTONIC_CLOCK"
381#else
382 return (_POSIX_MONOTONIC_CLOCK);
383#endif
9d66746c 384 case _SC_MQ_PRIO_MAX:
d2506be8
SK
385 len = sizeof(lvalue);
386 if (sysctlbyname("kern.mqueue.mq_prio_max", &lvalue, &len,
387 NULL, 0) == -1)
388 return (-1);
389 return (lvalue);
390
9d66746c
PA
391 case _SC_READER_WRITER_LOCKS:
392 return (_POSIX_READER_WRITER_LOCKS);
393 case _SC_REGEXP:
394 return (_POSIX_REGEXP);
395 case _SC_SHELL:
396 return (_POSIX_SHELL);
397 case _SC_SPAWN:
398 return (_POSIX_SPAWN);
399 case _SC_SPIN_LOCKS:
400 return (_POSIX_SPIN_LOCKS);
401 case _SC_SPORADIC_SERVER:
402#if _POSIX_SPORADIC_SERVER == 0
403#error "_POSIX_SPORADIC_SERVER"
404#else
405 return (_POSIX_SPORADIC_SERVER);
406#endif
407 case _SC_THREAD_ATTR_STACKADDR:
408 return (_POSIX_THREAD_ATTR_STACKADDR);
409 case _SC_THREAD_ATTR_STACKSIZE:
410 return (_POSIX_THREAD_ATTR_STACKSIZE);
411 case _SC_THREAD_CPUTIME:
412 return (_POSIX_THREAD_CPUTIME);
413 case _SC_THREAD_DESTRUCTOR_ITERATIONS:
414 return (PTHREAD_DESTRUCTOR_ITERATIONS);
415 case _SC_THREAD_KEYS_MAX:
416 return (PTHREAD_KEYS_MAX);
417 case _SC_THREAD_PRIO_INHERIT:
418 return (_POSIX_THREAD_PRIO_INHERIT);
419 case _SC_THREAD_PRIO_PROTECT:
420 return (_POSIX_THREAD_PRIO_PROTECT);
421 case _SC_THREAD_PRIORITY_SCHEDULING:
422 return (_POSIX_THREAD_PRIORITY_SCHEDULING);
423 case _SC_THREAD_PROCESS_SHARED:
424 return (_POSIX_THREAD_PROCESS_SHARED);
425 case _SC_THREAD_SAFE_FUNCTIONS:
426 return (_POSIX_THREAD_SAFE_FUNCTIONS);
427 case _SC_THREAD_STACK_MIN:
428 return (PTHREAD_STACK_MIN);
429 case _SC_THREAD_THREADS_MAX:
430 return (PTHREAD_THREADS_MAX); /* XXX wrong type! */
431 case _SC_TIMEOUTS:
432 return (_POSIX_TIMEOUTS);
433 case _SC_THREADS:
434 return (_POSIX_THREADS);
435 case _SC_TRACE:
436#if _POSIX_TRACE == 0
437#error "_POSIX_TRACE"
438 /* While you're implementing this, also do the ones below. */
439#else
440 return (_POSIX_TRACE);
441#endif
442#if _POSIX_TRACE > -1
443 case _SC_TRACE_EVENT_FILTER:
444 return (_POSIX_TRACE_EVENT_FILTER);
445 case _SC_TRACE_INHERIT:
446 return (_POSIX_TRACE_INHERIT);
447 case _SC_TRACE_LOG:
448 return (_POSIX_TRACE_LOG);
449#endif
450 case _SC_TTY_NAME_MAX:
451 path = _PATH_DEV;
452 goto do_NAME_MAX;
453 case _SC_TYPED_MEMORY_OBJECTS:
454#if _POSIX_TYPED_MEMORY_OBJECTS == 0
455#error "_POSIX_TYPED_MEMORY_OBJECTS"
456#else
457 return (_POSIX_TYPED_MEMORY_OBJECTS);
458#endif
459 case _SC_V6_ILP32_OFF32:
460#if _V6_ILP32_OFF32 == 0
461 if (sizeof(int) * CHAR_BIT == 32 &&
462 sizeof(int) == sizeof(long) &&
463 sizeof(long) == sizeof(void *) &&
464 sizeof(void *) == sizeof(off_t))
465 return 1;
466 else
467 return -1;
468#else
469 return (_V6_ILP32_OFF32);
470#endif
471 case _SC_V6_ILP32_OFFBIG:
472#if _V6_ILP32_OFFBIG == 0
473 if (sizeof(int) * CHAR_BIT == 32 &&
474 sizeof(int) == sizeof(long) &&
475 sizeof(long) == sizeof(void *) &&
476 sizeof(off_t) * CHAR_BIT >= 64)
477 return 1;
478 else
479 return -1;
480#else
481 return (_V6_ILP32_OFFBIG);
482#endif
483 case _SC_V6_LP64_OFF64:
484#if _V6_LP64_OFF64 == 0
485 if (sizeof(int) * CHAR_BIT == 32 &&
486 sizeof(long) * CHAR_BIT == 64 &&
487 sizeof(long) == sizeof(void *) &&
488 sizeof(void *) == sizeof(off_t))
489 return 1;
490 else
491 return -1;
492#else
493 return (_V6_LP64_OFF64);
494#endif
495 case _SC_V6_LPBIG_OFFBIG:
496#if _V6_LPBIG_OFFBIG == 0
497 if (sizeof(int) * CHAR_BIT >= 32 &&
498 sizeof(long) * CHAR_BIT >= 64 &&
499 sizeof(void *) * CHAR_BIT >= 64 &&
500 sizeof(off_t) * CHAR_BIT >= 64)
501 return 1;
502 else
503 return -1;
504#else
505 return (_V6_LPBIG_OFFBIG);
506#endif
507 case _SC_ATEXIT_MAX:
508 return (ATEXIT_SIZE);
509 case _SC_IOV_MAX:
510 mib[0] = CTL_KERN;
511 mib[1] = KERN_IOV_MAX;
512 break;
513 case _SC_XOPEN_CRYPT:
514 return (_XOPEN_CRYPT);
515 case _SC_XOPEN_ENH_I18N:
516 return (_XOPEN_ENH_I18N);
517 case _SC_XOPEN_LEGACY:
518 return (_XOPEN_LEGACY);
519 case _SC_XOPEN_REALTIME:
520#if _XOPEN_REALTIME == 0
521 sverrno = errno;
522 value = sysconf(_SC_ASYNCHRONOUS_IO) > 0 &&
523 sysconf(_SC_MEMLOCK) > 0 &&
524 sysconf(_SC_MEMLOCK_RANGE) > 0 &&
525 sysconf(_SC_MESSAGE_PASSING) > 0 &&
526 sysconf(_SC_PRIORITY_SCHEDULING) > 0 &&
527 sysconf(_SC_REALTIME_SIGNALS) > 0 &&
528 sysconf(_SC_SEMAPHORES) > 0 &&
529 sysconf(_SC_SHARED_MEMORY_OBJECTS) > 0 &&
530 sysconf(_SC_SYNCHRONIZED_IO) > 0 &&
531 sysconf(_SC_TIMERS) > 0;
532 errno = sverrno;
533 if (value)
534 return (200112L);
535 else
536 return (-1);
537#else
538 return (_XOPEN_REALTIME);
539#endif
540 case _SC_XOPEN_REALTIME_THREADS:
541#if _XOPEN_REALTIME_THREADS == 0
542#error "_XOPEN_REALTIME_THREADS"
543#else
544 return (_XOPEN_REALTIME_THREADS);
545#endif
546 case _SC_XOPEN_SHM:
547 len = sizeof(lvalue);
548 sverrno = errno;
549 if (sysctlbyname("kern.ipc.shmmin", &lvalue, &len, NULL,
550 0) == -1) {
551 errno = sverrno;
552 return (-1);
553 }
554 errno = sverrno;
555 return (1);
556 case _SC_XOPEN_STREAMS:
557 return (_XOPEN_STREAMS);
558 case _SC_XOPEN_UNIX:
559 return (_XOPEN_UNIX);
560#ifdef _XOPEN_VERSION
561 case _SC_XOPEN_VERSION:
562 return (_XOPEN_VERSION);
563#endif
564#ifdef _XOPEN_XCU_VERSION
565 case _SC_XOPEN_XCU_VERSION:
566 return (_XOPEN_XCU_VERSION);
567#endif
568 case _SC_SYMLOOP_MAX:
569 return (MAXSYMLINKS);
570 case _SC_RAW_SOCKETS:
571 return (_POSIX_RAW_SOCKETS);
572 case _SC_IPV6:
573#if _POSIX_IPV6 == 0
574 sverrno = errno;
575 value = socket(PF_INET6, SOCK_DGRAM, 0);
576 errno = sverrno;
577 if (value >= 0) {
578 close(value);
579 return (200112L);
580 } else
581 return (0);
582#else
583 return (_POSIX_IPV6);
584#endif
585
dd47c5d8
HT
586 case _SC_NPROCESSORS_CONF:
587 case _SC_NPROCESSORS_ONLN:
588 mib[0] = CTL_HW;
589 mib[1] = HW_NCPU;
9d66746c 590 break;
984263bc 591
9d66746c
PA
592#ifdef _SC_PHYS_PAGES
593 case _SC_PHYS_PAGES:
594 len = sizeof(lvalue);
595 if (sysctlbyname("hw.availpages", &lvalue, &len, NULL, 0) == -1)
984263bc 596 return (-1);
9d66746c
PA
597 return (lvalue);
598#endif
599
984263bc
MD
600 default:
601 errno = EINVAL;
602 return (-1);
603 }
9d66746c
PA
604 len = sizeof(value);
605 if (sysctl(mib, 2, &value, &len, NULL, 0) == -1)
606 value = -1;
607 return ((long)value);
984263bc 608}