]>
Commit | Line | Data |
---|---|---|
224c7076 A |
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 | * 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. | |
23 | * | |
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 | |
34 | * SUCH DAMAGE. | |
35 | */ | |
36 | ||
37 | #if defined(LIBC_SCCS) && !defined(lint) | |
38 | static char sccsid[] = "@(#)sysconf.c 8.2 (Berkeley) 3/20/94"; | |
39 | #endif /* LIBC_SCCS and not lint */ | |
40 | #include <sys/cdefs.h> | |
41 | __FBSDID("$FreeBSD: src/lib/libc/gen/sysconf.c,v 1.20 2002/11/17 08:54:29 dougb Exp $"); | |
42 | ||
43 | #include <sys/param.h> | |
44 | #include <sys/time.h> | |
45 | #include <sys/sysctl.h> | |
46 | #include <sys/resource.h> | |
47 | #include <sys/socket.h> | |
48 | #include <sys/aio.h> | |
49 | #include <sys/semaphore.h> | |
50 | ||
51 | #include <errno.h> | |
52 | #include <limits.h> | |
53 | #include <paths.h> | |
54 | #include <pthread.h> /* we just need the limits */ | |
55 | #include <time.h> | |
56 | #include <unistd.h> | |
57 | ||
58 | #include "../stdlib/atexit.h" | |
59 | #include "../stdtime/tzfile.h" | |
60 | ||
61 | #define _PATH_ZONEINFO TZDIR /* from tzfile.h */ | |
62 | ||
63 | /* | |
64 | * sysconf -- | |
65 | * get configurable system variables. | |
66 | * | |
67 | * XXX | |
68 | * POSIX 1003.1 (ISO/IEC 9945-1, 4.8.1.3) states that the variable values | |
69 | * not change during the lifetime of the calling process. This would seem | |
70 | * to require that any change to system limits kill all running processes. | |
71 | * A workaround might be to cache the values when they are first retrieved | |
72 | * and then simply return the cached value on subsequent calls. This is | |
73 | * less useful than returning up-to-date values, however. | |
74 | */ | |
75 | long | |
76 | sysconf(name) | |
77 | int name; | |
78 | { | |
79 | struct rlimit rl; | |
80 | quad_t qdvalue; /* for kern.sysv.shmmin */ | |
81 | size_t len; | |
82 | int mib[3], sverrno, value; | |
83 | long defaultresult; | |
84 | const char *path; | |
85 | ||
86 | len = sizeof(value); | |
87 | defaultresult = -1; | |
88 | ||
89 | switch (name) { | |
90 | case _SC_ARG_MAX: | |
91 | mib[0] = CTL_KERN; | |
92 | mib[1] = KERN_ARGMAX; | |
93 | break; | |
94 | case _SC_CHILD_MAX: | |
95 | if (getrlimit(RLIMIT_NPROC, &rl) != 0) | |
96 | return (-1); | |
97 | if (rl.rlim_cur == RLIM_INFINITY) | |
98 | return (-1); | |
99 | if (rl.rlim_cur > LONG_MAX) { | |
100 | errno = EOVERFLOW; | |
101 | return (-1); | |
102 | } | |
103 | return ((long)rl.rlim_cur); | |
104 | case _SC_CLK_TCK: | |
105 | return (CLK_TCK); | |
106 | case _SC_NGROUPS_MAX: | |
107 | mib[0] = CTL_KERN; | |
108 | mib[1] = KERN_NGROUPS; | |
109 | break; | |
110 | case _SC_OPEN_MAX: | |
111 | case _SC_STREAM_MAX: /* assume fds run out before memory does */ | |
112 | if (getrlimit(RLIMIT_NOFILE, &rl) != 0) | |
113 | return (-1); | |
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 | return ((long)rl.rlim_cur); | |
121 | case _SC_JOB_CONTROL: | |
122 | return (_POSIX_JOB_CONTROL); | |
123 | case _SC_SAVED_IDS: | |
124 | /* XXX - must be 1 */ | |
125 | mib[0] = CTL_KERN; | |
126 | mib[1] = KERN_SAVED_IDS; | |
127 | goto yesno; | |
128 | case _SC_VERSION: | |
129 | mib[0] = CTL_KERN; | |
130 | mib[1] = KERN_POSIX1; | |
131 | break; | |
132 | case _SC_BC_BASE_MAX: | |
133 | return (BC_BASE_MAX); | |
134 | case _SC_BC_DIM_MAX: | |
135 | return (BC_DIM_MAX); | |
136 | case _SC_BC_SCALE_MAX: | |
137 | return (BC_SCALE_MAX); | |
138 | case _SC_BC_STRING_MAX: | |
139 | return (BC_STRING_MAX); | |
140 | case _SC_COLL_WEIGHTS_MAX: | |
141 | return (COLL_WEIGHTS_MAX); | |
142 | case _SC_EXPR_NEST_MAX: | |
143 | return (EXPR_NEST_MAX); | |
144 | case _SC_LINE_MAX: | |
145 | return (LINE_MAX); | |
146 | case _SC_RE_DUP_MAX: | |
147 | return (RE_DUP_MAX); | |
148 | case _SC_2_VERSION: | |
149 | /* | |
150 | * This is something of a lie, but it would be silly at | |
151 | * this point to try to deduce this from the contents | |
152 | * of the filesystem. | |
153 | */ | |
154 | return (_POSIX2_VERSION); | |
155 | case _SC_2_C_BIND: | |
156 | return (_POSIX2_C_BIND); | |
157 | case _SC_2_C_DEV: | |
158 | return (_POSIX2_C_DEV); | |
159 | case _SC_2_CHAR_TERM: | |
160 | return (_POSIX2_CHAR_TERM); | |
161 | case _SC_2_FORT_DEV: | |
162 | return (_POSIX2_FORT_DEV); | |
163 | case _SC_2_FORT_RUN: | |
164 | return (_POSIX2_FORT_RUN); | |
165 | case _SC_2_LOCALEDEF: | |
166 | return (_POSIX2_LOCALEDEF); | |
167 | case _SC_2_SW_DEV: | |
168 | return (_POSIX2_SW_DEV); | |
169 | case _SC_2_UPE: | |
170 | return (_POSIX2_UPE); | |
171 | case _SC_TZNAME_MAX: | |
172 | path = _PATH_ZONEINFO; | |
173 | do_NAME_MAX: | |
174 | sverrno = errno; | |
175 | errno = 0; | |
176 | value = pathconf(path, _PC_NAME_MAX); | |
177 | if (value == -1 && errno != 0) | |
178 | return (-1); | |
179 | errno = sverrno; | |
180 | return (value); | |
181 | ||
182 | case _SC_ASYNCHRONOUS_IO: | |
183 | #if _POSIX_ASYNCHRONOUS_IO == 0 | |
184 | mib[0] = CTL_P1003_1B; | |
185 | mib[1] = CTL_P1003_1B_ASYNCHRONOUS_IO; | |
186 | break; | |
187 | #else | |
188 | return (_POSIX_ASYNCHRONOUS_IO); | |
189 | #endif | |
190 | case _SC_MAPPED_FILES: | |
191 | return (_POSIX_MAPPED_FILES); | |
192 | case _SC_MEMLOCK: | |
193 | return (_POSIX_MEMLOCK); | |
194 | case _SC_MEMLOCK_RANGE: | |
195 | return (_POSIX_MEMLOCK_RANGE); | |
196 | case _SC_MEMORY_PROTECTION: | |
197 | return (_POSIX_MEMORY_PROTECTION); | |
198 | case _SC_MESSAGE_PASSING: | |
199 | #if _POSIX_MESSAGE_PASSING == 0 | |
200 | mib[0] = CTL_P1003_1B; | |
201 | mib[1] = CTL_P1003_1B_MESSAGE_PASSING; | |
202 | goto yesno; | |
203 | #else | |
204 | return (_POSIX_MESSAGE_PASSING); | |
205 | #endif | |
206 | case _SC_PRIORITIZED_IO: | |
207 | #if _POSIX_PRIORITIZED_IO == 0 | |
208 | mib[0] = CTL_P1003_1B; | |
209 | mib[1] = CTL_P1003_1B_PRIORITIZED_IO; | |
210 | goto yesno; | |
211 | #else | |
212 | return (_POSIX_PRIORITIZED_IO); | |
213 | #endif | |
214 | case _SC_PRIORITY_SCHEDULING: | |
215 | #if _POSIX_PRIORITY_SCHEDULING == 0 | |
216 | mib[0] = CTL_P1003_1B; | |
217 | mib[1] = CTL_P1003_1B_PRIORITY_SCHEDULING; | |
218 | goto yesno; | |
219 | #else | |
220 | return (_POSIX_PRIORITY_SCHEDULING); | |
221 | #endif | |
222 | case _SC_REALTIME_SIGNALS: | |
223 | #if _POSIX_REALTIME_SIGNALS == 0 | |
224 | mib[0] = CTL_P1003_1B; | |
225 | mib[1] = CTL_P1003_1B_REALTIME_SIGNALS; | |
226 | goto yesno; | |
227 | #else | |
228 | return (_POSIX_REALTIME_SIGNALS); | |
229 | #endif | |
230 | case _SC_SEMAPHORES: | |
231 | #if _POSIX_SEMAPHORES == 0 | |
232 | mib[0] = CTL_P1003_1B; | |
233 | mib[1] = CTL_P1003_1B_SEMAPHORES; | |
234 | goto yesno; | |
235 | #else | |
236 | return (_POSIX_SEMAPHORES); | |
237 | #endif | |
238 | case _SC_FSYNC: | |
239 | return (_POSIX_FSYNC); | |
240 | ||
241 | case _SC_SHARED_MEMORY_OBJECTS: | |
242 | return (_POSIX_SHARED_MEMORY_OBJECTS); | |
243 | case _SC_SYNCHRONIZED_IO: | |
244 | #if _POSIX_SYNCHRONIZED_IO == 0 | |
245 | mib[0] = CTL_P1003_1B; | |
246 | mib[1] = CTL_P1003_1B_SYNCHRONIZED_IO; | |
247 | goto yesno; | |
248 | #else | |
249 | return (_POSIX_SYNCHRONIZED_IO); | |
250 | #endif | |
251 | case _SC_TIMERS: | |
252 | #if _POSIX_TIMERS == 0 | |
253 | mib[0] = CTL_P1003_1B; | |
254 | mib[1] = CTL_P1003_1B_TIMERS; | |
255 | goto yesno; | |
256 | #else | |
257 | return (_POSIX_TIMERS); | |
258 | #endif | |
259 | case _SC_AIO_LISTIO_MAX: | |
260 | case _SC_AIO_MAX: | |
261 | mib[0] = CTL_KERN;; | |
262 | mib[1] = KERN_AIOMAX; | |
263 | break; | |
264 | ||
265 | case _SC_AIO_PRIO_DELTA_MAX: | |
266 | #if defined(CTL_P1003_1B) && defined(CTL_P1003_1B_AIO_PRIO_DELTA_MAX) | |
267 | mib[0] = CTL_P1003_1B; | |
268 | mib[1] = CTL_P1003_1B_AIO_PRIO_DELTA_MAX; | |
269 | break; | |
270 | #else | |
271 | return (-1); | |
272 | #endif | |
273 | case _SC_DELAYTIMER_MAX: | |
274 | #if defined(CTL_P1003_1B) && defined(CTL_P1003_1B_DELAYTIMER_MAX) | |
275 | mib[0] = CTL_P1003_1B; | |
276 | mib[1] = CTL_P1003_1B_DELAYTIMER_MAX; | |
277 | goto yesno; | |
278 | #else | |
279 | return (-1); | |
280 | #endif | |
281 | case _SC_MQ_OPEN_MAX: | |
282 | #if defined(CTL_P1003_1B) && defined(CTL_P1003_1B_MQ_OPEN_MAX) | |
283 | mib[0] = CTL_P1003_1B; | |
284 | mib[1] = CTL_P1003_1B_MQ_OPEN_MAX; | |
285 | goto yesno; | |
286 | #else | |
287 | return (-1); | |
288 | #endif | |
289 | case _SC_PAGESIZE: | |
290 | defaultresult = getpagesize(); | |
291 | #if defined(CTL_P1003_1B) && defined(CTL_P1003_1B_PAGESIZE) | |
292 | mib[0] = CTL_P1003_1B; | |
293 | mib[1] = CTL_P1003_1B_PAGESIZE; | |
294 | goto yesno; | |
295 | #else | |
296 | return defaultresult; | |
297 | #endif | |
298 | case _SC_RTSIG_MAX: | |
299 | #if defined(CTL_P1003_1B) && defined(CTL_P1003_1B_RTSIG_MAX) | |
300 | mib[0] = CTL_P1003_1B; | |
301 | mib[1] = CTL_P1003_1B_RTSIG_MAX; | |
302 | goto yesno; | |
303 | #else | |
304 | return (-1); | |
305 | #endif | |
306 | case _SC_SEM_NSEMS_MAX: | |
307 | return (sysctlbyname("kern.sysv.semmns", &value, &len, NULL, 0) == -1 ? -1 : value); | |
308 | ||
309 | case _SC_SEM_VALUE_MAX: | |
310 | #if SEM_VALUE_MAX == 0 | |
311 | mib[0] = CTL_P1003_1B; | |
312 | mib[1] = CTL_P1003_1B_SEM_VALUE_MAX; | |
313 | goto yesno; | |
314 | #else | |
315 | return (SEM_VALUE_MAX); | |
316 | #endif | |
317 | case _SC_SIGQUEUE_MAX: | |
318 | #if defined(CTL_P1003_1B) && defined(CTL_P1003_1B_SIGQUEUE_MAX) | |
319 | mib[0] = CTL_P1003_1B; | |
320 | mib[1] = CTL_P1003_1B_SIGQUEUE_MAX; | |
321 | goto yesno; | |
322 | #else | |
323 | return (-1); | |
324 | #endif | |
325 | case _SC_TIMER_MAX: | |
326 | #if defined(CTL_P1003_1B) && defined(CTL_P1003_1B_TIMER_MAX) | |
327 | mib[0] = CTL_P1003_1B; | |
328 | mib[1] = CTL_P1003_1B_TIMER_MAX; | |
329 | #else | |
330 | return (-1); | |
331 | #endif | |
332 | ||
333 | yesno: if (sysctl(mib, 2, &value, &len, NULL, 0) == -1) | |
334 | return (-1); | |
335 | if (value == 0) | |
336 | return (defaultresult); | |
337 | return (value); | |
338 | case _SC_2_PBS: | |
339 | case _SC_2_PBS_ACCOUNTING: | |
340 | case _SC_2_PBS_CHECKPOINT: | |
341 | case _SC_2_PBS_LOCATE: | |
342 | case _SC_2_PBS_MESSAGE: | |
343 | case _SC_2_PBS_TRACK: | |
344 | return -1; | |
345 | case _SC_ADVISORY_INFO: | |
346 | #if _POSIX_ADVISORY_INFO == 0 | |
347 | #error "_POSIX_ADVISORY_INFO" | |
348 | #else | |
349 | return (_POSIX_ADVISORY_INFO); | |
350 | #endif | |
351 | case _SC_BARRIERS: | |
352 | #if _POSIX_BARRIERS == 0 | |
353 | #error "_POSIX_BARRIERS" | |
354 | #else | |
355 | return (_POSIX_BARRIERS); | |
356 | #endif | |
357 | case _SC_CLOCK_SELECTION: | |
358 | #if _POSIX_CLOCK_SELECTION == 0 | |
359 | #error "_POSIX_CLOCK_SELECTION" | |
360 | #else | |
361 | return (_POSIX_CLOCK_SELECTION); | |
362 | #endif | |
363 | case _SC_CPUTIME: | |
364 | #if _POSIX_CPUTIME == 0 | |
365 | #error "_POSIX_CPUTIME" | |
366 | #else | |
367 | return (_POSIX_CPUTIME); | |
368 | #endif | |
369 | case _SC_FILE_LOCKING: | |
370 | case _SC_GETGR_R_SIZE_MAX: | |
371 | /* return sizeof(group) + group_name_max + group_passwd_max + max_group_member*(MAXLOGNAME+1); */ | |
372 | return 4096; /* INT_MAX is too big for Perl */ | |
373 | case _SC_GETPW_R_SIZE_MAX: | |
374 | return 4096; | |
375 | case _SC_HOST_NAME_MAX: | |
376 | return (MAXHOSTNAMELEN - 1); /* does not include \0 */ | |
377 | case _SC_LOGIN_NAME_MAX: | |
378 | return (MAXLOGNAME); | |
379 | case _SC_MONOTONIC_CLOCK: | |
380 | #if _POSIX_MONOTONIC_CLOCK == 0 | |
381 | #error "_POSIX_MONOTONIC_CLOCK" | |
382 | #else | |
383 | return (_POSIX_MONOTONIC_CLOCK); | |
384 | #endif | |
385 | case _SC_MQ_PRIO_MAX: | |
386 | return (-1); | |
387 | case _SC_READER_WRITER_LOCKS: | |
388 | return (_POSIX_READER_WRITER_LOCKS); | |
389 | case _SC_REGEXP: | |
390 | return (_POSIX_REGEXP); | |
391 | case _SC_SHELL: | |
392 | return (_POSIX_SHELL); | |
393 | case _SC_SPAWN: | |
394 | return (_POSIX_SPAWN); | |
395 | case _SC_SPIN_LOCKS: | |
396 | return (_POSIX_SPIN_LOCKS); | |
397 | case _SC_SPORADIC_SERVER: | |
398 | #if _POSIX_SPORADIC_SERVER == 0 | |
399 | #error "_POSIX_SPORADIC_SERVER" | |
400 | #else | |
401 | return (_POSIX_SPORADIC_SERVER); | |
402 | #endif | |
403 | case _SC_THREAD_ATTR_STACKADDR: | |
404 | return (_POSIX_THREAD_ATTR_STACKADDR); | |
405 | case _SC_THREAD_ATTR_STACKSIZE: | |
406 | return (_POSIX_THREAD_ATTR_STACKSIZE); | |
407 | case _SC_THREAD_CPUTIME: | |
408 | return (_POSIX_THREAD_CPUTIME); | |
409 | case _SC_THREAD_DESTRUCTOR_ITERATIONS: | |
410 | return (PTHREAD_DESTRUCTOR_ITERATIONS); | |
411 | case _SC_THREAD_KEYS_MAX: | |
412 | return (PTHREAD_KEYS_MAX); | |
413 | case _SC_THREAD_PRIO_INHERIT: | |
414 | return (_POSIX_THREAD_PRIO_INHERIT); | |
415 | case _SC_THREAD_PRIO_PROTECT: | |
416 | return (_POSIX_THREAD_PRIO_PROTECT); | |
417 | case _SC_THREAD_PRIORITY_SCHEDULING: | |
418 | return (_POSIX_THREAD_PRIORITY_SCHEDULING); | |
419 | case _SC_THREAD_PROCESS_SHARED: | |
420 | return (_POSIX_THREAD_PROCESS_SHARED); | |
421 | case _SC_THREAD_SAFE_FUNCTIONS: | |
422 | return (_POSIX_THREAD_SAFE_FUNCTIONS); | |
423 | case _SC_THREAD_SPORADIC_SERVER: | |
424 | return (_POSIX_THREAD_SPORADIC_SERVER); | |
425 | case _SC_THREAD_STACK_MIN: | |
426 | return (PTHREAD_STACK_MIN); | |
427 | case _SC_THREAD_THREADS_MAX: | |
428 | #ifdef PTHREAD_THREADS_MAX | |
429 | return (PTHREAD_THREADS_MAX); /* XXX wrong type! */ | |
430 | #else | |
431 | return (-1); | |
432 | #endif | |
433 | case _SC_TIMEOUTS: | |
434 | return (_POSIX_TIMEOUTS); | |
435 | case _SC_THREADS: | |
436 | return (_POSIX_THREADS); | |
437 | case _SC_TRACE: | |
438 | #if _POSIX_TRACE == 0 | |
439 | #error "_POSIX_TRACE" | |
440 | /* While you're implementing this, also do the ones below. */ | |
441 | #else | |
442 | return (_POSIX_TRACE); | |
443 | #endif | |
444 | case _SC_TRACE_EVENT_FILTER: | |
445 | return (_POSIX_TRACE_EVENT_FILTER); | |
446 | case _SC_TRACE_INHERIT: | |
447 | return (_POSIX_TRACE_INHERIT); | |
448 | case _SC_TRACE_LOG: | |
449 | return (_POSIX_TRACE_LOG); | |
450 | case _SC_TTY_NAME_MAX: | |
451 | path = "/"; // should be _PATH_DEV (PR-3624562) | |
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 (INT_MAX); /* unlimited */ | |
509 | case _SC_IOV_MAX: | |
510 | #ifdef KERN_IOV_MAX | |
511 | mib[0] = CTL_KERN; | |
512 | mib[1] = KERN_IOV_MAX; | |
513 | break; | |
514 | #else | |
515 | return (IOV_MAX); | |
516 | #endif | |
517 | case _SC_XOPEN_CRYPT: | |
518 | return (_XOPEN_CRYPT); | |
519 | case _SC_XOPEN_ENH_I18N: | |
520 | return (_XOPEN_ENH_I18N); | |
521 | case _SC_XOPEN_LEGACY: | |
522 | return (_XOPEN_LEGACY); | |
523 | case _SC_XOPEN_REALTIME: | |
524 | #if _XOPEN_REALTIME == 0 | |
525 | sverrno = errno; | |
526 | value = sysconf(_SC_ASYNCHRONOUS_IO) > 0 && | |
527 | sysconf(_SC_MEMLOCK) > 0 && | |
528 | sysconf(_SC_MEMLOCK_RANGE) > 0 && | |
529 | sysconf(_SC_MESSAGE_PASSING) > 0 && | |
530 | sysconf(_SC_PRIORITY_SCHEDULING) > 0 && | |
531 | sysconf(_SC_REALTIME_SIGNALS) > 0 && | |
532 | sysconf(_SC_SEMAPHORES) > 0 && | |
533 | sysconf(_SC_SHARED_MEMORY_OBJECTS) > 0 && | |
534 | sysconf(_SC_SYNCHRONIZED_IO) > 0 && | |
535 | sysconf(_SC_TIMERS) > 0; | |
536 | errno = sverrno; | |
537 | if (value) | |
538 | return (200112L); | |
539 | else | |
540 | return (-1); | |
541 | #else | |
542 | return (_XOPEN_REALTIME); | |
543 | #endif | |
544 | case _SC_XOPEN_REALTIME_THREADS: | |
545 | #if _XOPEN_REALTIME_THREADS == 0 | |
546 | #error "_XOPEN_REALTIME_THREADS" | |
547 | #else | |
548 | return (_XOPEN_REALTIME_THREADS); | |
549 | #endif | |
550 | case _SC_XOPEN_SHM: | |
551 | sverrno = errno; | |
552 | len = sizeof(qdvalue); | |
553 | if (sysctlbyname("kern.sysv.shmmin", &qdvalue, &len, NULL, | |
554 | 0) == -1) { | |
555 | errno = sverrno; | |
556 | return (-1); | |
557 | } | |
558 | errno = sverrno; | |
559 | return (1); | |
560 | case _SC_XOPEN_STREAMS: | |
561 | return (_XOPEN_STREAMS); | |
562 | case _SC_XOPEN_UNIX: | |
563 | return (_XOPEN_UNIX); | |
564 | #ifdef _XOPEN_VERSION | |
565 | case _SC_XOPEN_VERSION: | |
566 | return (_XOPEN_VERSION); | |
567 | #endif | |
568 | #ifdef _XOPEN_XCU_VERSION | |
569 | case _SC_XOPEN_XCU_VERSION: | |
570 | return (_XOPEN_XCU_VERSION); | |
571 | #endif | |
572 | case _SC_SYMLOOP_MAX: | |
573 | return (MAXSYMLINKS); | |
574 | case _SC_RAW_SOCKETS: | |
575 | return (_POSIX_RAW_SOCKETS); | |
576 | case _SC_IPV6: | |
577 | #if _POSIX_IPV6 == 0 | |
578 | sverrno = errno; | |
579 | value = socket(PF_INET6, SOCK_DGRAM, 0); | |
580 | errno = sverrno; | |
581 | if (value >= 0) { | |
582 | close(value); | |
583 | return (200112L); | |
584 | } else | |
585 | return (0); | |
586 | #else | |
587 | return (_POSIX_IPV6); | |
588 | #endif | |
589 | ||
590 | #ifdef _SC_NPROCESSORS_CONF | |
591 | case _SC_NPROCESSORS_CONF: | |
592 | #endif | |
593 | #ifdef _SC_NPROCESSORS_ONLN | |
594 | case _SC_NPROCESSORS_ONLN: | |
595 | #endif | |
596 | #if defined(_SC_NPROCESSORS_CONF) || defined(_SC_NPROCESSORS_ONLN) | |
597 | mib[0] = CTL_HW; | |
598 | mib[1] = HW_NCPU; | |
599 | break; | |
600 | #endif | |
601 | case _SC_XBS5_ILP32_OFF32: | |
602 | return (_XBS5_ILP32_OFF32); | |
603 | case _SC_XBS5_ILP32_OFFBIG: | |
604 | return (_XBS5_ILP32_OFFBIG); | |
605 | case _SC_XBS5_LP64_OFF64: | |
606 | return (_XBS5_LP64_OFF64); | |
607 | case _SC_XBS5_LPBIG_OFFBIG: | |
608 | return (_XBS5_LPBIG_OFFBIG); | |
609 | case _SC_SS_REPL_MAX: | |
610 | return (_POSIX_SS_REPL_MAX); | |
611 | case _SC_TRACE_EVENT_NAME_MAX: | |
612 | return (_POSIX_TRACE_EVENT_NAME_MAX); | |
613 | case _SC_TRACE_NAME_MAX: | |
614 | return (_POSIX_TRACE_NAME_MAX); | |
615 | case _SC_TRACE_SYS_MAX: | |
616 | return (_POSIX_TRACE_SYS_MAX); | |
617 | case _SC_TRACE_USER_EVENT_MAX: | |
618 | return (_POSIX_TRACE_USER_EVENT_MAX); | |
619 | case _SC_PASS_MAX: | |
620 | return (PASS_MAX); | |
621 | ||
622 | default: | |
623 | errno = EINVAL; | |
624 | return (-1); | |
625 | } | |
626 | return (sysctl(mib, 2, &value, &len, NULL, 0) == -1 ? -1 : value); | |
627 | } |