Import complex arithmetic functions from {Net,Free}BSD.
[dragonfly.git] / lib / libc / gen / sysconf.c
blob244aed9528b3e8afa9596c3e0f75aab84ee6a373
1 /*-
2 * Copyright (c) 1993
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
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.
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.
32 * @(#)sysconf.c 8.2 (Berkeley) 3/20/94
33 * $FreeBSD: src/lib/libc/gen/sysconf.c,v 1.26 2008/02/27 05:56:57 wollman Exp $
34 * $DragonFly: src/lib/libc/gen/sysconf.c,v 1.5 2008/02/21 12:47:54 hasso Exp $
37 #include <sys/param.h>
38 #include <sys/time.h>
39 #include <sys/sysctl.h>
40 #include <sys/resource.h>
41 #include <sys/socket.h>
43 #include <errno.h>
44 #include <limits.h>
45 #include <paths.h>
46 #include <pthread.h> /* we just need the limits */
47 #include <time.h>
48 #include <unistd.h>
50 #include "../stdlib/atexit.h"
51 #include "../stdtime/tzfile.h"
53 #define _PATH_ZONEINFO TZDIR /* from tzfile.h */
56 * sysconf --
57 * get configurable system variables.
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.
67 long
68 sysconf(int name)
70 struct rlimit rl;
71 size_t len;
72 int mib[2], sverrno, value;
73 long lvalue, defaultresult;
74 const char *path;
76 defaultresult = -1;
78 switch (name) {
79 case _SC_ARG_MAX:
80 mib[0] = CTL_KERN;
81 mib[1] = KERN_ARGMAX;
82 break;
83 case _SC_CHILD_MAX:
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);
92 return ((long)rl.rlim_cur);
93 case _SC_CLK_TCK:
94 return (CLK_TCK);
95 case _SC_NGROUPS_MAX:
96 mib[0] = CTL_KERN;
97 mib[1] = KERN_NGROUPS;
98 break;
99 case _SC_OPEN_MAX:
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);
108 return ((long)rl.rlim_cur);
109 case _SC_STREAM_MAX:
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);
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.
124 if (rl.rlim_cur > SHRT_MAX)
125 return (SHRT_MAX);
127 return ((long)rl.rlim_cur);
128 case _SC_JOB_CONTROL:
129 return (_POSIX_JOB_CONTROL);
130 case _SC_SAVED_IDS:
131 /* XXX - must be 1 */
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;
139 case _SC_BC_BASE_MAX:
140 return (BC_BASE_MAX);
141 case _SC_BC_DIM_MAX:
142 return (BC_DIM_MAX);
143 case _SC_BC_SCALE_MAX:
144 return (BC_SCALE_MAX);
145 case _SC_BC_STRING_MAX:
146 return (BC_STRING_MAX);
147 case _SC_COLL_WEIGHTS_MAX:
148 return (COLL_WEIGHTS_MAX);
149 case _SC_EXPR_NEST_MAX:
150 return (EXPR_NEST_MAX);
151 case _SC_LINE_MAX:
152 return (LINE_MAX);
153 case _SC_RE_DUP_MAX:
154 return (RE_DUP_MAX);
155 case _SC_2_VERSION:
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.
161 return (_POSIX2_VERSION);
162 case _SC_2_C_BIND:
163 return (_POSIX2_C_BIND);
164 case _SC_2_C_DEV:
165 return (_POSIX2_C_DEV);
166 case _SC_2_CHAR_TERM:
167 return (_POSIX2_CHAR_TERM);
168 case _SC_2_FORT_DEV:
169 return (_POSIX2_FORT_DEV);
170 case _SC_2_FORT_RUN:
171 return (_POSIX2_FORT_RUN);
172 case _SC_2_LOCALEDEF:
173 return (_POSIX2_LOCALEDEF);
174 case _SC_2_SW_DEV:
175 return (_POSIX2_SW_DEV);
176 case _SC_2_UPE:
177 return (_POSIX2_UPE);
178 case _SC_TZNAME_MAX:
179 path = _PATH_ZONEINFO;
180 do_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);
189 case _SC_ASYNCHRONOUS_IO:
190 #if _POSIX_ASYNCHRONOUS_IO == 0
191 mib[0] = CTL_P1003_1B;
192 mib[1] = CTL_P1003_1B_ASYNCHRONOUS_IO;
193 break;
194 #else
195 return (_POSIX_ASYNCHRONOUS_IO);
196 #endif
197 case _SC_MAPPED_FILES:
198 return (_POSIX_MAPPED_FILES);
199 case _SC_MEMLOCK:
200 return (_POSIX_MEMLOCK);
201 case _SC_MEMLOCK_RANGE:
202 return (_POSIX_MEMLOCK_RANGE);
203 case _SC_MEMORY_PROTECTION:
204 return (_POSIX_MEMORY_PROTECTION);
205 case _SC_MESSAGE_PASSING:
206 #if _POSIX_MESSAGE_PASSING == 0
207 mib[0] = CTL_P1003_1B;
208 mib[1] = CTL_P1003_1B_MESSAGE_PASSING;
209 goto yesno;
210 #else
211 return (_POSIX_MESSAGE_PASSING);
212 #endif
213 case _SC_PRIORITIZED_IO:
214 #if _POSIX_PRIORITIZED_IO == 0
215 mib[0] = CTL_P1003_1B;
216 mib[1] = CTL_P1003_1B_PRIORITIZED_IO;
217 goto yesno;
218 #else
219 return (_POSIX_PRIORITIZED_IO);
220 #endif
221 case _SC_PRIORITY_SCHEDULING:
222 #if _POSIX_PRIORITY_SCHEDULING == 0
223 mib[0] = CTL_P1003_1B;
224 mib[1] = CTL_P1003_1B_PRIORITY_SCHEDULING;
225 goto yesno;
226 #else
227 return (_POSIX_PRIORITY_SCHEDULING);
228 #endif
229 case _SC_REALTIME_SIGNALS:
230 #if _POSIX_REALTIME_SIGNALS == 0
231 mib[0] = CTL_P1003_1B;
232 mib[1] = CTL_P1003_1B_REALTIME_SIGNALS;
233 goto yesno;
234 #else
235 return (_POSIX_REALTIME_SIGNALS);
236 #endif
237 case _SC_SEMAPHORES:
238 #if _POSIX_SEMAPHORES == 0
239 mib[0] = CTL_P1003_1B;
240 mib[1] = CTL_P1003_1B_SEMAPHORES;
241 goto yesno;
242 #else
243 return (_POSIX_SEMAPHORES);
244 #endif
245 case _SC_FSYNC:
246 return (_POSIX_FSYNC);
248 case _SC_SHARED_MEMORY_OBJECTS:
249 return (_POSIX_SHARED_MEMORY_OBJECTS);
250 case _SC_SYNCHRONIZED_IO:
251 #if _POSIX_SYNCHRONIZED_IO == 0
252 mib[0] = CTL_P1003_1B;
253 mib[1] = CTL_P1003_1B_SYNCHRONIZED_IO;
254 goto yesno;
255 #else
256 return (_POSIX_SYNCHRONIZED_IO);
257 #endif
258 case _SC_TIMERS:
259 #if _POSIX_TIMERS == 0
260 mib[0] = CTL_P1003_1B;
261 mib[1] = CTL_P1003_1B_TIMERS;
262 goto yesno;
263 #else
264 return (_POSIX_TIMERS);
265 #endif
266 case _SC_AIO_LISTIO_MAX:
267 mib[0] = CTL_P1003_1B;
268 mib[1] = CTL_P1003_1B_AIO_LISTIO_MAX;
269 break;
270 case _SC_AIO_MAX:
271 mib[0] = CTL_P1003_1B;
272 mib[1] = CTL_P1003_1B_AIO_MAX;
273 break;
274 case _SC_AIO_PRIO_DELTA_MAX:
275 mib[0] = CTL_P1003_1B;
276 mib[1] = CTL_P1003_1B_AIO_PRIO_DELTA_MAX;
277 break;
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;
310 yesno:
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);
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"
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''.
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:
365 * XXX - The standard doesn't tell us how to define
366 * _POSIX_FILE_LOCKING, so we can't answer this one.
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
384 #if _POSIX_MESSAGE_PASSING > -1
385 case _SC_MQ_PRIO_MAX:
386 return (MQ_PRIO_MAX);
387 #endif
388 case _SC_READER_WRITER_LOCKS:
389 return (_POSIX_READER_WRITER_LOCKS);
390 case _SC_REGEXP:
391 return (_POSIX_REGEXP);
392 case _SC_SHELL:
393 return (_POSIX_SHELL);
394 case _SC_SPAWN:
395 return (_POSIX_SPAWN);
396 case _SC_SPIN_LOCKS:
397 return (_POSIX_SPIN_LOCKS);
398 case _SC_SPORADIC_SERVER:
399 #if _POSIX_SPORADIC_SERVER == 0
400 #error "_POSIX_SPORADIC_SERVER"
401 #else
402 return (_POSIX_SPORADIC_SERVER);
403 #endif
404 case _SC_THREAD_ATTR_STACKADDR:
405 return (_POSIX_THREAD_ATTR_STACKADDR);
406 case _SC_THREAD_ATTR_STACKSIZE:
407 return (_POSIX_THREAD_ATTR_STACKSIZE);
408 case _SC_THREAD_CPUTIME:
409 return (_POSIX_THREAD_CPUTIME);
410 case _SC_THREAD_DESTRUCTOR_ITERATIONS:
411 return (PTHREAD_DESTRUCTOR_ITERATIONS);
412 case _SC_THREAD_KEYS_MAX:
413 return (PTHREAD_KEYS_MAX);
414 case _SC_THREAD_PRIO_INHERIT:
415 return (_POSIX_THREAD_PRIO_INHERIT);
416 case _SC_THREAD_PRIO_PROTECT:
417 return (_POSIX_THREAD_PRIO_PROTECT);
418 case _SC_THREAD_PRIORITY_SCHEDULING:
419 return (_POSIX_THREAD_PRIORITY_SCHEDULING);
420 case _SC_THREAD_PROCESS_SHARED:
421 return (_POSIX_THREAD_PROCESS_SHARED);
422 case _SC_THREAD_SAFE_FUNCTIONS:
423 return (_POSIX_THREAD_SAFE_FUNCTIONS);
424 case _SC_THREAD_STACK_MIN:
425 return (PTHREAD_STACK_MIN);
426 case _SC_THREAD_THREADS_MAX:
427 return (PTHREAD_THREADS_MAX); /* XXX wrong type! */
428 case _SC_TIMEOUTS:
429 return (_POSIX_TIMEOUTS);
430 case _SC_THREADS:
431 return (_POSIX_THREADS);
432 case _SC_TRACE:
433 #if _POSIX_TRACE == 0
434 #error "_POSIX_TRACE"
435 /* While you're implementing this, also do the ones below. */
436 #else
437 return (_POSIX_TRACE);
438 #endif
439 #if _POSIX_TRACE > -1
440 case _SC_TRACE_EVENT_FILTER:
441 return (_POSIX_TRACE_EVENT_FILTER);
442 case _SC_TRACE_INHERIT:
443 return (_POSIX_TRACE_INHERIT);
444 case _SC_TRACE_LOG:
445 return (_POSIX_TRACE_LOG);
446 #endif
447 case _SC_TTY_NAME_MAX:
448 path = _PATH_DEV;
449 goto do_NAME_MAX;
450 case _SC_TYPED_MEMORY_OBJECTS:
451 #if _POSIX_TYPED_MEMORY_OBJECTS == 0
452 #error "_POSIX_TYPED_MEMORY_OBJECTS"
453 #else
454 return (_POSIX_TYPED_MEMORY_OBJECTS);
455 #endif
456 case _SC_V6_ILP32_OFF32:
457 #if _V6_ILP32_OFF32 == 0
458 if (sizeof(int) * CHAR_BIT == 32 &&
459 sizeof(int) == sizeof(long) &&
460 sizeof(long) == sizeof(void *) &&
461 sizeof(void *) == sizeof(off_t))
462 return 1;
463 else
464 return -1;
465 #else
466 return (_V6_ILP32_OFF32);
467 #endif
468 case _SC_V6_ILP32_OFFBIG:
469 #if _V6_ILP32_OFFBIG == 0
470 if (sizeof(int) * CHAR_BIT == 32 &&
471 sizeof(int) == sizeof(long) &&
472 sizeof(long) == sizeof(void *) &&
473 sizeof(off_t) * CHAR_BIT >= 64)
474 return 1;
475 else
476 return -1;
477 #else
478 return (_V6_ILP32_OFFBIG);
479 #endif
480 case _SC_V6_LP64_OFF64:
481 #if _V6_LP64_OFF64 == 0
482 if (sizeof(int) * CHAR_BIT == 32 &&
483 sizeof(long) * CHAR_BIT == 64 &&
484 sizeof(long) == sizeof(void *) &&
485 sizeof(void *) == sizeof(off_t))
486 return 1;
487 else
488 return -1;
489 #else
490 return (_V6_LP64_OFF64);
491 #endif
492 case _SC_V6_LPBIG_OFFBIG:
493 #if _V6_LPBIG_OFFBIG == 0
494 if (sizeof(int) * CHAR_BIT >= 32 &&
495 sizeof(long) * CHAR_BIT >= 64 &&
496 sizeof(void *) * CHAR_BIT >= 64 &&
497 sizeof(off_t) * CHAR_BIT >= 64)
498 return 1;
499 else
500 return -1;
501 #else
502 return (_V6_LPBIG_OFFBIG);
503 #endif
504 case _SC_ATEXIT_MAX:
505 return (ATEXIT_SIZE);
506 case _SC_IOV_MAX:
507 mib[0] = CTL_KERN;
508 mib[1] = KERN_IOV_MAX;
509 break;
510 case _SC_XOPEN_CRYPT:
511 return (_XOPEN_CRYPT);
512 case _SC_XOPEN_ENH_I18N:
513 return (_XOPEN_ENH_I18N);
514 case _SC_XOPEN_LEGACY:
515 return (_XOPEN_LEGACY);
516 case _SC_XOPEN_REALTIME:
517 #if _XOPEN_REALTIME == 0
518 sverrno = errno;
519 value = sysconf(_SC_ASYNCHRONOUS_IO) > 0 &&
520 sysconf(_SC_MEMLOCK) > 0 &&
521 sysconf(_SC_MEMLOCK_RANGE) > 0 &&
522 sysconf(_SC_MESSAGE_PASSING) > 0 &&
523 sysconf(_SC_PRIORITY_SCHEDULING) > 0 &&
524 sysconf(_SC_REALTIME_SIGNALS) > 0 &&
525 sysconf(_SC_SEMAPHORES) > 0 &&
526 sysconf(_SC_SHARED_MEMORY_OBJECTS) > 0 &&
527 sysconf(_SC_SYNCHRONIZED_IO) > 0 &&
528 sysconf(_SC_TIMERS) > 0;
529 errno = sverrno;
530 if (value)
531 return (200112L);
532 else
533 return (-1);
534 #else
535 return (_XOPEN_REALTIME);
536 #endif
537 case _SC_XOPEN_REALTIME_THREADS:
538 #if _XOPEN_REALTIME_THREADS == 0
539 #error "_XOPEN_REALTIME_THREADS"
540 #else
541 return (_XOPEN_REALTIME_THREADS);
542 #endif
543 case _SC_XOPEN_SHM:
544 len = sizeof(lvalue);
545 sverrno = errno;
546 if (sysctlbyname("kern.ipc.shmmin", &lvalue, &len, NULL,
547 0) == -1) {
548 errno = sverrno;
549 return (-1);
551 errno = sverrno;
552 return (1);
553 case _SC_XOPEN_STREAMS:
554 return (_XOPEN_STREAMS);
555 case _SC_XOPEN_UNIX:
556 return (_XOPEN_UNIX);
557 #ifdef _XOPEN_VERSION
558 case _SC_XOPEN_VERSION:
559 return (_XOPEN_VERSION);
560 #endif
561 #ifdef _XOPEN_XCU_VERSION
562 case _SC_XOPEN_XCU_VERSION:
563 return (_XOPEN_XCU_VERSION);
564 #endif
565 case _SC_SYMLOOP_MAX:
566 return (MAXSYMLINKS);
567 case _SC_RAW_SOCKETS:
568 return (_POSIX_RAW_SOCKETS);
569 case _SC_IPV6:
570 #if _POSIX_IPV6 == 0
571 sverrno = errno;
572 value = socket(PF_INET6, SOCK_DGRAM, 0);
573 errno = sverrno;
574 if (value >= 0) {
575 close(value);
576 return (200112L);
577 } else
578 return (0);
579 #else
580 return (_POSIX_IPV6);
581 #endif
583 case _SC_NPROCESSORS_CONF:
584 case _SC_NPROCESSORS_ONLN:
585 mib[0] = CTL_HW;
586 mib[1] = HW_NCPU;
587 break;
589 #ifdef _SC_PHYS_PAGES
590 case _SC_PHYS_PAGES:
591 len = sizeof(lvalue);
592 if (sysctlbyname("hw.availpages", &lvalue, &len, NULL, 0) == -1)
593 return (-1);
594 return (lvalue);
595 #endif
597 default:
598 errno = EINVAL;
599 return (-1);
601 len = sizeof(value);
602 if (sysctl(mib, 2, &value, &len, NULL, 0) == -1)
603 value = -1;
604 return ((long)value);