64-bit optimized implementation of trunc.
[glibc.git] / sysdeps / posix / sysconf.c
blobe734fdd9bdf5f8baff0a58be31a30bc309016ac5
1 /* Copyright (C) 1991,1993,1995-1997,1999-2003,2004,2006,2009
2 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <errno.h>
21 #include <limits.h>
22 #include <grp.h>
23 #include <pwd.h>
24 #include <stddef.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <time.h>
29 #include <unistd.h>
30 #include <sys/param.h>
31 #include <sys/stat.h>
32 #include <sys/sysinfo.h>
33 #include <sys/types.h>
34 #include <regex.h>
37 #define NEED_CHECK_SPEC \
38 (!defined _XBS5_ILP32_OFF32 || !defined _XBS5_ILP32_OFFBIG \
39 || !defined _XBS5_LP64_OFF64 || !defined _XBS5_LPBIG_OFFBIG \
40 || !defined _POSIX_V6_ILP32_OFF32 || !defined _POSIX_V6_ILP32_OFFBIG \
41 || !defined _POSIX_V6_LP64_OFF64 || !defined _POSIX_V6_LPBIG_OFFBIG \
42 || !defined _POSIX_V7_ILP32_OFF32 || !defined _POSIX_V7_ILP32_OFFBIG \
43 || !defined _POSIX_V7_LP64_OFF64 || !defined _POSIX_V7_LPBIG_OFFBIG)
44 #if NEED_CHECK_SPEC
45 static long int __sysconf_check_spec (const char *spec);
46 #endif
49 /* Get the value of the system variable NAME. */
50 long int
51 __sysconf (name)
52 int name;
54 switch (name)
56 /* Also add obsolete or unnecessarily added constants here. */
57 case _SC_EQUIV_CLASS_MAX:
58 default:
59 __set_errno (EINVAL);
60 return -1;
62 case _SC_ARG_MAX:
63 #ifdef ARG_MAX
64 return ARG_MAX;
65 #else
66 return -1;
67 #endif
69 case _SC_CHILD_MAX:
70 #ifdef CHILD_MAX
71 return CHILD_MAX;
72 #else
73 return __get_child_max ();
74 #endif
76 case _SC_CLK_TCK:
77 return __getclktck ();
79 case _SC_NGROUPS_MAX:
80 #ifdef NGROUPS_MAX
81 return NGROUPS_MAX;
82 #else
83 return -1;
84 #endif
86 case _SC_OPEN_MAX:
87 return __getdtablesize ();
89 case _SC_STREAM_MAX:
90 #ifdef STREAM_MAX
91 return STREAM_MAX;
92 #else
93 return FOPEN_MAX;
94 #endif
96 case _SC_TZNAME_MAX:
97 return MAX (__tzname_max (), _POSIX_TZNAME_MAX);
99 case _SC_JOB_CONTROL:
100 #if _POSIX_JOB_CONTROL > 0
101 return _POSIX_JOB_CONTROL;
102 #else
103 return -1;
104 #endif
106 case _SC_SAVED_IDS:
107 #if _POSIX_SAVED_IDS > 0
108 return 1;
109 #else
110 return -1;
111 #endif
113 case _SC_REALTIME_SIGNALS:
114 #if _POSIX_REALTIME_SIGNALS > 0
115 return _POSIX_REALTIME_SIGNALS;
116 #else
117 return -1;
118 #endif
120 case _SC_PRIORITY_SCHEDULING:
121 #if _POSIX_PRIORITY_SCHEDULING > 0
122 return _POSIX_PRIORITY_SCHEDULING;
123 #else
124 return -1;
125 #endif
127 case _SC_TIMERS:
128 #if _POSIX_TIMERS > 0
129 return _POSIX_TIMERS;
130 #else
131 return -1;
132 #endif
134 case _SC_ASYNCHRONOUS_IO:
135 #if _POSIX_ASYNCHRONOUS_IO > 0
136 return _POSIX_ASYNCHRONOUS_IO;
137 #else
138 return -1;
139 #endif
141 case _SC_PRIORITIZED_IO:
142 #if _POSIX_PRIORITIZED_IO > 0
143 return _POSIX_PRIORITIZED_IO;
144 #else
145 return -1;
146 #endif
148 case _SC_SYNCHRONIZED_IO:
149 #if _POSIX_SYNCHRONIZED_IO > 0
150 return _POSIX_SYNCHRONIZED_IO;
151 #else
152 return -1;
153 #endif
155 case _SC_FSYNC:
156 #if _POSIX_FSYNC > 0
157 return _POSIX_FSYNC;
158 #else
159 return -1;
160 #endif
162 case _SC_MAPPED_FILES:
163 #if _POSIX_MAPPED_FILES > 0
164 return _POSIX_MAPPED_FILES;
165 #else
166 return -1;
167 #endif
169 case _SC_MEMLOCK:
170 #if _POSIX_MEMLOCK > 0
171 return _POSIX_MEMLOCK;
172 #else
173 return -1;
174 #endif
176 case _SC_MEMLOCK_RANGE:
177 #if _POSIX_MEMLOCK_RANGE > 0
178 return _POSIX_MEMLOCK_RANGE;
179 #else
180 return -1;
181 #endif
183 case _SC_MEMORY_PROTECTION:
184 #if _POSIX_MEMORY_PROTECTION > 0
185 return _POSIX_MEMORY_PROTECTION;
186 #else
187 return -1;
188 #endif
190 case _SC_MESSAGE_PASSING:
191 #if _POSIX_MESSAGE_PASSING > 0
192 return _POSIX_MESSAGE_PASSING;
193 #else
194 return -1;
195 #endif
197 case _SC_SEMAPHORES:
198 #if _POSIX_SEMAPHORES > 0
199 return _POSIX_SEMAPHORES;
200 #else
201 return -1;
202 #endif
204 case _SC_SHARED_MEMORY_OBJECTS:
205 #if _POSIX_SHARED_MEMORY_OBJECTS > 0
206 return _POSIX_SHARED_MEMORY_OBJECTS;
207 #else
208 return -1;
209 #endif
211 case _SC_VERSION:
212 return _POSIX_VERSION;
214 case _SC_PAGESIZE:
215 return __getpagesize ();
217 case _SC_AIO_LISTIO_MAX:
218 #ifdef AIO_LISTIO_MAX
219 return AIO_LISTIO_MAX;
220 #else
221 return -1;
222 #endif
224 case _SC_AIO_MAX:
225 #ifdef AIO_MAX
226 return AIO_MAX;
227 #else
228 return -1;
229 #endif
231 case _SC_AIO_PRIO_DELTA_MAX:
232 #ifdef AIO_PRIO_DELTA_MAX
233 return AIO_PRIO_DELTA_MAX;
234 #else
235 return -1;
236 #endif
238 case _SC_DELAYTIMER_MAX:
239 #ifdef DELAYTIMER_MAX
240 return DELAYTIMER_MAX;
241 #else
242 return -1;
243 #endif
245 case _SC_MQ_OPEN_MAX:
246 #ifdef MQ_OPEN_MAX
247 return MQ_OPEN_MAX;
248 #else
249 return -1;
250 #endif
252 case _SC_MQ_PRIO_MAX:
253 #ifdef MQ_PRIO_MAX
254 return MQ_PRIO_MAX;
255 #else
256 return -1;
257 #endif
259 case _SC_RTSIG_MAX:
260 #ifdef RTSIG_MAX
261 return RTSIG_MAX;
262 #else
263 return -1;
264 #endif
266 case _SC_SEM_NSEMS_MAX:
267 #ifdef SEM_NSEMS_MAX
268 return SEM_NSEMS_MAX;
269 #else
270 return -1;
271 #endif
273 case _SC_SEM_VALUE_MAX:
274 #ifdef SEM_VALUE_MAX
275 return SEM_VALUE_MAX;
276 #else
277 return -1;
278 #endif
280 case _SC_SIGQUEUE_MAX:
281 #ifdef SIGQUEUE_MAX
282 return SIGQUEUE_MAX;
283 #else
284 return -1;
285 #endif
287 case _SC_TIMER_MAX:
288 #ifdef TIMER_MAX
289 return TIMER_MAX;
290 #else
291 return -1;
292 #endif
294 case _SC_BC_BASE_MAX:
295 #ifdef BC_BASE_MAX
296 return BC_BASE_MAX;
297 #else
298 return -1;
299 #endif
301 case _SC_BC_DIM_MAX:
302 #ifdef BC_DIM_MAX
303 return BC_DIM_MAX;
304 #else
305 return -1;
306 #endif
308 case _SC_BC_SCALE_MAX:
309 #ifdef BC_SCALE_MAX
310 return BC_SCALE_MAX;
311 #else
312 return -1;
313 #endif
315 case _SC_BC_STRING_MAX:
316 #ifdef BC_STRING_MAX
317 return BC_STRING_MAX;
318 #else
319 return -1;
320 #endif
322 case _SC_COLL_WEIGHTS_MAX:
323 #ifdef COLL_WEIGHTS_MAX
324 return COLL_WEIGHTS_MAX;
325 #else
326 return -1;
327 #endif
329 case _SC_EXPR_NEST_MAX:
330 #ifdef EXPR_NEST_MAX
331 return EXPR_NEST_MAX;
332 #else
333 return -1;
334 #endif
336 case _SC_LINE_MAX:
337 #ifdef LINE_MAX
338 return LINE_MAX;
339 #else
340 return -1;
341 #endif
343 case _SC_RE_DUP_MAX:
344 #ifdef RE_DUP_MAX
345 return RE_DUP_MAX;
346 #else
347 return -1;
348 #endif
350 case _SC_CHARCLASS_NAME_MAX:
351 #ifdef CHARCLASS_NAME_MAX
352 return CHARCLASS_NAME_MAX;
353 #else
354 return -1;
355 #endif
357 case _SC_PII:
358 #if _POSIX_PII > 0
359 return 1;
360 #else
361 return -1;
362 #endif
364 case _SC_PII_XTI:
365 #if _POSIX_PII_XTI > 0
366 return 1;
367 #else
368 return -1;
369 #endif
371 case _SC_PII_SOCKET:
372 #if _POSIX_PII_SOCKET > 0
373 return 1;
374 #else
375 return -1;
376 #endif
378 case _SC_PII_INTERNET:
379 #if _POSIX_PII_INTERNET > 0
380 return 1;
381 #else
382 return -1;
383 #endif
385 case _SC_PII_OSI:
386 #if _POSIX_PII_OSI > 0
387 return 1;
388 #else
389 return -1;
390 #endif
392 case _SC_POLL:
393 #if _POSIX_POLL > 0
394 return 1;
395 #else
396 return -1;
397 #endif
399 case _SC_SELECT:
400 #if _POSIX_SELECT > 0
401 return 1;
402 #else
403 return -1;
404 #endif
406 /* The same as _SC_IOV_MAX. */
407 case _SC_UIO_MAXIOV:
408 #ifdef UIO_MAXIOV
409 return UIO_MAXIOV;
410 #else
411 return -1;
412 #endif
414 case _SC_PII_INTERNET_STREAM:
415 #if _POSIX_PII_INTERNET_STREAM > 0
416 return 1;
417 #else
418 return -1;
419 #endif
421 case _SC_PII_INTERNET_DGRAM:
422 #if _POSIX_PII_INTERNET_DGRAM > 0
423 return 1;
424 #else
425 return -1;
426 #endif
428 case _SC_PII_OSI_COTS:
429 #if _POSIX_PII_OSI_COTS > 0
430 return 1;
431 #else
432 return -1;
433 #endif
435 case _SC_PII_OSI_CLTS:
436 #if _POSIX_PII_OSI_CLTS > 0
437 return 1;
438 #else
439 return -1;
440 #endif
442 case _SC_PII_OSI_M:
443 #if _POSIX_PII_OSI_M > 0
444 return 1;
445 #else
446 return -1;
447 #endif
449 case _SC_T_IOV_MAX:
450 #ifdef _T_IOV_MAX
451 return _T_IOV_MAX;
452 #else
453 return -1;
454 #endif
456 case _SC_2_VERSION:
457 return _POSIX2_VERSION;
459 case _SC_2_C_BIND:
460 #ifdef _POSIX2_C_BIND
461 return _POSIX2_C_BIND;
462 #else
463 return -1;
464 #endif
466 case _SC_2_C_DEV:
467 #ifdef _POSIX2_C_DEV
468 return _POSIX2_C_DEV;
469 #else
470 return -1;
471 #endif
473 case _SC_2_C_VERSION:
474 #ifdef _POSIX2_C_VERSION
475 return _POSIX2_C_VERSION;
476 #else
477 return -1;
478 #endif
480 case _SC_2_FORT_DEV:
481 #ifdef _POSIX2_FORT_DEV
482 return _POSIX2_FORT_DEV;
483 #else
484 return -1;
485 #endif
487 case _SC_2_FORT_RUN:
488 #ifdef _POSIX2_FORT_RUN
489 return _POSIX2_FORT_RUN;
490 #else
491 return -1;
492 #endif
494 case _SC_2_LOCALEDEF:
495 #ifdef _POSIX2_LOCALEDEF
496 return _POSIX2_LOCALEDEF;
497 #else
498 return -1;
499 #endif
501 case _SC_2_SW_DEV:
502 #ifdef _POSIX2_SW_DEV
503 return _POSIX2_SW_DEV;
504 #else
505 return -1;
506 #endif
508 case _SC_2_CHAR_TERM:
509 #ifdef _POSIX2_CHAR_TERM
510 return _POSIX2_CHAR_TERM;
511 #else
512 return -1;
513 #endif
515 case _SC_2_UPE:
516 #ifdef _POSIX2_UPE
517 return _POSIX2_UPE;
518 #else
519 return -1;
520 #endif
522 /* POSIX 1003.1c (POSIX Threads). */
523 case _SC_THREADS:
524 #if _POSIX_THREADS > 0
525 return _POSIX_THREADS;
526 #else
527 return -1;
528 #endif
530 case _SC_THREAD_SAFE_FUNCTIONS:
531 #if _POSIX_THREAD_SAFE_FUNCTIONS > 0
532 return _POSIX_THREAD_SAFE_FUNCTIONS;
533 #else
534 return -1;
535 #endif
537 case _SC_GETGR_R_SIZE_MAX:
538 return NSS_BUFLEN_GROUP;
540 case _SC_GETPW_R_SIZE_MAX:
541 return NSS_BUFLEN_PASSWD;
543 case _SC_LOGIN_NAME_MAX:
544 #ifdef LOGIN_NAME_MAX
545 return LOGIN_NAME_MAX;
546 #else
547 return -1;
548 #endif
550 case _SC_TTY_NAME_MAX:
551 #ifdef TTY_NAME_MAX
552 return TTY_NAME_MAX;
553 #else
554 return -1;
555 #endif
557 case _SC_THREAD_DESTRUCTOR_ITERATIONS:
558 #if _POSIX_THREAD_DESTRUCTOR_ITERATIONS > 0
559 return _POSIX_THREAD_DESTRUCTOR_ITERATIONS;
560 #else
561 return -1;
562 #endif
564 case _SC_THREAD_KEYS_MAX:
565 #ifdef PTHREAD_KEYS_MAX
566 return PTHREAD_KEYS_MAX;
567 #else
568 return -1;
569 #endif
571 case _SC_THREAD_STACK_MIN:
572 #ifdef PTHREAD_STACK_MIN
573 return PTHREAD_STACK_MIN;
574 #else
575 return -1;
576 #endif
578 case _SC_THREAD_THREADS_MAX:
579 #ifdef PTHREAD_THREADS_MAX
580 return PTHREAD_THREADS_MAX;
581 #else
582 return -1;
583 #endif
585 case _SC_THREAD_ATTR_STACKADDR:
586 #if _POSIX_THREAD_ATTR_STACKADDR > 0
587 return _POSIX_THREAD_ATTR_STACKADDR;
588 #else
589 return -1;
590 #endif
592 case _SC_THREAD_ATTR_STACKSIZE:
593 #if _POSIX_THREAD_ATTR_STACKSIZE > 0
594 return _POSIX_THREAD_ATTR_STACKSIZE;
595 #else
596 return -1;
597 #endif
599 case _SC_THREAD_PRIORITY_SCHEDULING:
600 #if _POSIX_THREAD_PRIORITY_SCHEDULING > 0
601 return _POSIX_THREAD_PRIORITY_SCHEDULING;
602 #else
603 return -1;
604 #endif
606 case _SC_THREAD_PRIO_INHERIT:
607 #if _POSIX_THREAD_PRIO_INHERIT > 0
608 return _POSIX_THREAD_PRIO_INHERIT;
609 #else
610 return -1;
611 #endif
613 case _SC_THREAD_PRIO_PROTECT:
614 #if _POSIX_THREAD_PRIO_PROTECT > 0
615 return _POSIX_THREAD_PRIO_PROTECT;
616 #else
617 return -1;
618 #endif
620 case _SC_THREAD_PROCESS_SHARED:
621 #if _POSIX_THREAD_PROCESS_SHARED > 0
622 return _POSIX_THREAD_PROCESS_SHARED;
623 #else
624 return -1;
625 #endif
627 case _SC_NPROCESSORS_CONF:
628 return __get_nprocs_conf ();
630 case _SC_NPROCESSORS_ONLN:
631 return __get_nprocs ();
633 case _SC_PHYS_PAGES:
634 return __get_phys_pages ();
636 case _SC_AVPHYS_PAGES:
637 return __get_avphys_pages ();
639 case _SC_ATEXIT_MAX:
640 /* We have no limit since we use lists. */
641 return INT_MAX;
643 case _SC_PASS_MAX:
644 /* We have no limit but since the return value might be used to
645 allocate a buffer we restrict the value. */
646 return BUFSIZ;
648 case _SC_XOPEN_VERSION:
649 return _XOPEN_VERSION;
651 case _SC_XOPEN_XCU_VERSION:
652 return _XOPEN_XCU_VERSION;
654 case _SC_XOPEN_UNIX:
655 return _XOPEN_UNIX;
657 case _SC_XOPEN_CRYPT:
658 #ifdef _XOPEN_CRYPT
659 return _XOPEN_CRYPT;
660 #else
661 return -1;
662 #endif
664 case _SC_XOPEN_ENH_I18N:
665 #ifdef _XOPEN_ENH_I18N
666 return _XOPEN_ENH_I18N;
667 #else
668 return -1;
669 #endif
671 case _SC_XOPEN_SHM:
672 #ifdef _XOPEN_SHM
673 return _XOPEN_SHM;
674 #else
675 return -1;
676 #endif
678 case _SC_XOPEN_XPG2:
679 #ifdef _XOPEN_XPG2
680 return _XOPEN_XPG2;
681 #else
682 return -1;
683 #endif
685 case _SC_XOPEN_XPG3:
686 #ifdef _XOPEN_XPG3
687 return _XOPEN_XPG3;
688 #else
689 return -1;
690 #endif
692 case _SC_XOPEN_XPG4:
693 #ifdef _XOPEN_XPG4
694 return _XOPEN_XPG4;
695 #else
696 return -1;
697 #endif
699 case _SC_CHAR_BIT:
700 return CHAR_BIT;
702 case _SC_CHAR_MAX:
703 return CHAR_MAX;
705 case _SC_CHAR_MIN:
706 return CHAR_MIN;
708 case _SC_INT_MAX:
709 return INT_MAX;
711 case _SC_INT_MIN:
712 return INT_MIN;
714 case _SC_LONG_BIT:
715 return sizeof (long int) * CHAR_BIT;
717 case _SC_WORD_BIT:
718 return sizeof (int) * CHAR_BIT;
720 case _SC_MB_LEN_MAX:
721 return MB_LEN_MAX;
723 case _SC_NZERO:
724 return NZERO;
726 case _SC_SSIZE_MAX:
727 return _POSIX_SSIZE_MAX;
729 case _SC_SCHAR_MAX:
730 return SCHAR_MAX;
732 case _SC_SCHAR_MIN:
733 return SCHAR_MIN;
735 case _SC_SHRT_MAX:
736 return SHRT_MAX;
738 case _SC_SHRT_MIN:
739 return SHRT_MIN;
741 case _SC_UCHAR_MAX:
742 return UCHAR_MAX;
744 case _SC_UINT_MAX:
745 return UINT_MAX;
747 case _SC_ULONG_MAX:
748 return ULONG_MAX;
750 case _SC_USHRT_MAX:
751 return USHRT_MAX;
753 case _SC_NL_ARGMAX:
754 #ifdef NL_ARGMAX
755 return NL_ARGMAX;
756 #else
757 return -1;
758 #endif
760 case _SC_NL_LANGMAX:
761 #ifdef NL_LANGMAX
762 return NL_LANGMAX;
763 #else
764 return -1;
765 #endif
767 case _SC_NL_MSGMAX:
768 #ifdef NL_MSGMAX
769 return NL_MSGMAX;
770 #else
771 return -1;
772 #endif
774 case _SC_NL_NMAX:
775 #ifdef NL_NMAX
776 return NL_NMAX;
777 #else
778 return -1;
779 #endif
781 case _SC_NL_SETMAX:
782 #ifdef NL_SETMAX
783 return NL_SETMAX;
784 #else
785 return -1;
786 #endif
788 case _SC_NL_TEXTMAX:
789 #ifdef NL_TEXTMAX
790 return NL_TEXTMAX;
791 #else
792 return -1;
793 #endif
795 case _SC_XBS5_ILP32_OFF32:
796 #ifdef _XBS5_ILP32_OFF32
797 return _XBS5_ILP32_OFF32;
798 #else
799 return __sysconf_check_spec ("ILP32_OFF32");
800 #endif
801 case _SC_XBS5_ILP32_OFFBIG:
802 #ifdef _XBS5_ILP32_OFFBIG
803 return _XBS5_ILP32_OFFBIG;
804 #else
805 return __sysconf_check_spec ("ILP32_OFFBIG");
806 #endif
807 case _SC_XBS5_LP64_OFF64:
808 #ifdef _XBS5_LP64_OFF64
809 return _XBS5_LP64_OFF64;
810 #else
811 return __sysconf_check_spec ("LP64_OFF64");
812 #endif
813 case _SC_XBS5_LPBIG_OFFBIG:
814 #ifdef _XBS5_LPBIG_OFFBIG
815 return _XBS5_LPBIG_OFFBIG;
816 #else
817 return __sysconf_check_spec ("LPBIG_OFFBIG");
818 #endif
820 case _SC_V6_ILP32_OFF32:
821 #ifdef _POSIX_V6_ILP32_OFF32
822 return _POSIX_V6_ILP32_OFF32;
823 #else
824 return __sysconf_check_spec ("ILP32_OFF32");
825 #endif
826 case _SC_V6_ILP32_OFFBIG:
827 #ifdef _POSIX_V6_ILP32_OFFBIG
828 return _POSIX_V6_ILP32_OFFBIG;
829 #else
830 return __sysconf_check_spec ("ILP32_OFFBIG");
831 #endif
832 case _SC_V6_LP64_OFF64:
833 #ifdef _POSIX_V6_LP64_OFF64
834 return _POSIX_V6_LP64_OFF64;
835 #else
836 return __sysconf_check_spec ("LP64_OFF64");
837 #endif
838 case _SC_V6_LPBIG_OFFBIG:
839 #ifdef _POSIX_V6_LPBIG_OFFBIG
840 return _POSIX_V6_LPBIG_OFFBIG;
841 #else
842 return __sysconf_check_spec ("LPBIG_OFFBIG");
843 #endif
845 case _SC_V7_ILP32_OFF32:
846 #ifdef _POSIX_V7_ILP32_OFF32
847 return _POSIX_V7_ILP32_OFF32;
848 #else
849 return __sysconf_check_spec ("ILP32_OFF32");
850 #endif
851 case _SC_V7_ILP32_OFFBIG:
852 #ifdef _POSIX_V7_ILP32_OFFBIG
853 return _POSIX_V7_ILP32_OFFBIG;
854 #else
855 return __sysconf_check_spec ("ILP32_OFFBIG");
856 #endif
857 case _SC_V7_LP64_OFF64:
858 #ifdef _POSIX_V7_LP64_OFF64
859 return _POSIX_V7_LP64_OFF64;
860 #else
861 return __sysconf_check_spec ("LP64_OFF64");
862 #endif
863 case _SC_V7_LPBIG_OFFBIG:
864 #ifdef _POSIX_V7_LPBIG_OFFBIG
865 return _POSIX_V7_LPBIG_OFFBIG;
866 #else
867 return __sysconf_check_spec ("LPBIG_OFFBIG");
868 #endif
870 case _SC_XOPEN_LEGACY:
871 return _XOPEN_LEGACY;
873 case _SC_XOPEN_REALTIME:
874 #ifdef _XOPEN_REALTIME
875 return _XOPEN_REALTIME;
876 #else
877 return -1;
878 #endif
879 case _SC_XOPEN_REALTIME_THREADS:
880 #ifdef _XOPEN_REALTIME_THREADS
881 return _XOPEN_REALTIME_THREADS;
882 #else
883 return -1;
884 #endif
886 case _SC_ADVISORY_INFO:
887 #if _POSIX_ADVISORY_INFO > 0
888 return _POSIX_ADVISORY_INFO;
889 #else
890 return -1;
891 #endif
893 case _SC_BARRIERS:
894 #if _POSIX_BARRIERS > 0
895 return _POSIX_BARRIERS;
896 #else
897 return -1;
898 #endif
900 case _SC_BASE:
901 #if _POSIX_BASE > 0
902 return _POSIX_BASE;
903 #else
904 return -1;
905 #endif
906 case _SC_C_LANG_SUPPORT:
907 #if _POSIX_C_LANG_SUPPORT > 0
908 return _POSIX_C_LANG_SUPPORT;
909 #else
910 return -1;
911 #endif
912 case _SC_C_LANG_SUPPORT_R:
913 #if _POSIX_C_LANG_SUPPORT_R > 0
914 return _POSIX_C_LANG_SUPPORT_R;
915 #else
916 return -1;
917 #endif
919 case _SC_CLOCK_SELECTION:
920 #if _POSIX_CLOCK_SELECTION > 0
921 return _POSIX_CLOCK_SELECTION;
922 #else
923 return -1;
924 #endif
926 case _SC_CPUTIME:
927 #if _POSIX_CPUTIME > 0
928 return _POSIX_CPUTIME;
929 #else
930 return -1;
931 #endif
933 case _SC_DEVICE_IO:
934 #if _POSIX_DEVICE_IO > 0
935 return _POSIX_DEVICE_IO;
936 #else
937 return -1;
938 #endif
939 case _SC_DEVICE_SPECIFIC:
940 #if _POSIX_DEVICE_SPCIFIC > 0
941 return _POSIX_DEVICE_SPECIFIC;
942 #else
943 return -1;
944 #endif
945 case _SC_DEVICE_SPECIFIC_R:
946 #if _POSIX_DEVICE_SPCIFIC_R > 0
947 return _POSIX_DEVICE_SPECIFIC_R;
948 #else
949 return -1;
950 #endif
952 case _SC_FD_MGMT:
953 #if _POSIX_FD_MGMT > 0
954 return _POSIX_FD_MGMT;
955 #else
956 return -1;
957 #endif
959 case _SC_FIFO:
960 #if _POSIX_FIFO > 0
961 return _POSIX_FIFO;
962 #else
963 return -1;
964 #endif
965 case _SC_PIPE:
966 #if _POSIX_PIPE > 0
967 return _POSIX_PIPE;
968 #else
969 return -1;
970 #endif
972 case _SC_FILE_ATTRIBUTES:
973 #if _POSIX_FILE_ATTRIBUTES > 0
974 return _POSIX_FILE_ATTRIBUTES;
975 #else
976 return -1;
977 #endif
978 case _SC_FILE_LOCKING:
979 #if _POSIX_FILE_LOCKING > 0
980 return _POSIX_FILE_LOCKING;
981 #else
982 return -1;
983 #endif
984 case _SC_FILE_SYSTEM:
985 #if _POSIX_FILE_SYSTEM > 0
986 return _POSIX_FILE_SYSTEM;
987 #else
988 return -1;
989 #endif
991 case _SC_MONOTONIC_CLOCK:
992 #if _POSIX_MONOTONIC_CLOCK
993 return _POSIX_MONOTONIC_CLOCK;
994 #else
995 return -1;
996 #endif
998 case _SC_MULTI_PROCESS:
999 #if _POSIX_MULTI_PROCESS > 0
1000 return _POSIX_MULTI_PROCESS;
1001 #else
1002 return -1;
1003 #endif
1004 case _SC_SINGLE_PROCESS:
1005 #if _POSIX_SINGLE_PROCESS > 0
1006 return _POSIX_SINGLE_PROCESS;
1007 #else
1008 return -1;
1009 #endif
1011 case _SC_NETWORKING:
1012 #if _POSIX_NETWORKING > 0
1013 return _POSIX_NETWORKING;
1014 #else
1015 return -1;
1016 #endif
1018 case _SC_READER_WRITER_LOCKS:
1019 #if _POSIX_READER_WRITER_LOCKS > 0
1020 return _POSIX_READER_WRITER_LOCKS;
1021 #else
1022 return -1;
1023 #endif
1024 case _SC_SPIN_LOCKS:
1025 #if _POSIX_SPIN_LOCKS > 0
1026 return _POSIX_SPIN_LOCKS;
1027 #else
1028 return -1;
1029 #endif
1031 case _SC_REGEXP:
1032 #if _POSIX_REGEXP > 0
1033 return _POSIX_REGEXP;
1034 #else
1035 return -1;
1036 #endif
1037 case _SC_REGEX_VERSION:
1038 #if _POSIX_REGEX_VERSION > 0
1039 return _POSIX_REGEX_VERSION;
1040 #else
1041 return -1;
1042 #endif
1044 case _SC_SHELL:
1045 #if _POSIX_SHELL > 0
1046 return _POSIX_SHELL;
1047 #else
1048 return -1;
1049 #endif
1051 case _SC_SIGNALS:
1052 #ifdef _POSUX_SIGNALS
1053 return _POSIX_SIGNALS;
1054 #else
1055 return -1;
1056 #endif
1058 case _SC_SPAWN:
1059 #if _POSIX_SPAWN > 0
1060 return _POSIX_SPAWN;
1061 #else
1062 return -1;
1063 #endif
1065 case _SC_SPORADIC_SERVER:
1066 #if _POSIX_SPORADIC_SERVER > 0
1067 return _POSIX_SPORADIC_SERVER;
1068 #else
1069 return -1;
1070 #endif
1071 case _SC_THREAD_SPORADIC_SERVER:
1072 #if _POSIX_THREAD_SPORADIC_SERVER > 0
1073 return _POSIX_THREAD_SPORADIC_SERVER;
1074 #else
1075 return -1;
1076 #endif
1078 case _SC_SYSTEM_DATABASE:
1079 #if _POSIX_SYSTEM_DATABASE > 0
1080 return _POSIX_SYSTEM_DATABASE;
1081 #else
1082 return -1;
1083 #endif
1084 case _SC_SYSTEM_DATABASE_R:
1085 #if _POSIX_SYSTEM_DATABASE_R > 0
1086 return _POSIX_SYSTEM_DATABASE_R;
1087 #else
1088 return -1;
1089 #endif
1091 case _SC_THREAD_CPUTIME:
1092 #if _POSIX_THREAD_CPUTIME > 0
1093 return _POSIX_THREAD_CPUTIME;
1094 #else
1095 return -1;
1096 #endif
1098 case _SC_TIMEOUTS:
1099 #if _POSIX_TIMEOUTS > 0
1100 return _POSIX_TIMEOUTS;
1101 #else
1102 return -1;
1103 #endif
1105 case _SC_TYPED_MEMORY_OBJECTS:
1106 #if _POSIX_TYPED_MEMORY_OBJECTS > 0
1107 return _POSIX_TYPED_MEMORY_OBJECTS;
1108 #else
1109 return -1;
1110 #endif
1112 case _SC_USER_GROUPS:
1113 #if _POSIX_USER_GROUPS > 0
1114 return _POSIX_USER_GROUPS;
1115 #else
1116 return -1;
1117 #endif
1118 case _SC_USER_GROUPS_R:
1119 #if _POSIX_USER_GROUPS_R > 0
1120 return _POSIX_USER_GROUPS_R;
1121 #else
1122 return -1;
1123 #endif
1125 case _SC_2_PBS:
1126 #ifdef _POSIX2_PBS
1127 return _POSIX2_PBS;
1128 #else
1129 return -1;
1130 #endif
1131 case _SC_2_PBS_ACCOUNTING:
1132 #ifdef _POSIX2_PBS_ACCOUNTING
1133 return _POSIX2_PBS_ACCOUNTING;
1134 #else
1135 return -1;
1136 #endif
1137 case _SC_2_PBS_CHECKPOINT:
1138 #ifdef _POSIX2_PBS_CHECKPOINT
1139 return _POSIX2_PBS_CHECKPOINT;
1140 #else
1141 return -1;
1142 #endif
1143 case _SC_2_PBS_LOCATE:
1144 #ifdef _POSIX2_PBS_LOCATE
1145 return _POSIX2_PBS_LOCATE;
1146 #else
1147 return -1;
1148 #endif
1149 case _SC_2_PBS_MESSAGE:
1150 #ifdef _POSIX2_PBS_MESSAGE
1151 return _POSIX2_PBS_MESSAGE;
1152 #else
1153 return -1;
1154 #endif
1155 case _SC_2_PBS_TRACK:
1156 #ifdef _POSIX2_PBS_TRACK
1157 return _POSIX2_PBS_TRACK;
1158 #else
1159 return -1;
1160 #endif
1162 case _SC_SYMLOOP_MAX:
1163 #ifdef SYMLOOP_MAX
1164 return SYMLOOP_MAX;
1165 #else
1166 return -1;
1167 #endif
1169 case _SC_STREAMS:
1170 #ifdef _XOPEN_STREAMS
1171 return _XOPEN_STREAMS;
1172 #else
1173 return -1;
1174 #endif
1176 case _SC_HOST_NAME_MAX:
1177 #ifdef HOST_NAME_MAX
1178 return HOST_NAME_MAX;
1179 #else
1180 return -1;
1181 #endif
1183 case _SC_TRACE:
1184 #if _POSIX_TRACE > 0
1185 return _POSIX_TRACE;
1186 #else
1187 return -1;
1188 #endif
1189 case _SC_TRACE_EVENT_FILTER:
1190 #if _POSIX_TRACE_EVENT_FILTER > 0
1191 return _POSIX_TRACE_EVENT_FILTER;
1192 #else
1193 return -1;
1194 #endif
1195 case _SC_TRACE_INHERIT:
1196 #if _POSIX_TRACE_INHERIT > 0
1197 return _POSIX_TRACE_INHERIT;
1198 #else
1199 return -1;
1200 #endif
1201 case _SC_TRACE_LOG:
1202 #if _POSIX_TRACE_LOG > 0
1203 return _POSIX_TRACE_LOG;
1204 #else
1205 return -1;
1206 #endif
1208 case _SC_TRACE_EVENT_NAME_MAX:
1209 case _SC_TRACE_NAME_MAX:
1210 case _SC_TRACE_SYS_MAX:
1211 case _SC_TRACE_USER_EVENT_MAX:
1212 /* No support for tracing. */
1214 case _SC_XOPEN_STREAMS:
1215 /* No support for STREAMS. */
1216 return -1;
1218 case _SC_LEVEL1_ICACHE_SIZE:
1219 case _SC_LEVEL1_ICACHE_ASSOC:
1220 case _SC_LEVEL1_ICACHE_LINESIZE:
1221 case _SC_LEVEL1_DCACHE_SIZE:
1222 case _SC_LEVEL1_DCACHE_ASSOC:
1223 case _SC_LEVEL1_DCACHE_LINESIZE:
1224 case _SC_LEVEL2_CACHE_SIZE:
1225 case _SC_LEVEL2_CACHE_ASSOC:
1226 case _SC_LEVEL2_CACHE_LINESIZE:
1227 case _SC_LEVEL3_CACHE_SIZE:
1228 case _SC_LEVEL3_CACHE_ASSOC:
1229 case _SC_LEVEL3_CACHE_LINESIZE:
1230 case _SC_LEVEL4_CACHE_SIZE:
1231 case _SC_LEVEL4_CACHE_ASSOC:
1232 /* In general we cannot determine these values. Therefore we
1233 return zero which indicates that no information is
1234 available. */
1235 return 0;
1237 case _SC_IPV6:
1238 #if _POSIX_IPV6 > 0
1239 return _POSIX_IPV6;
1240 #else
1241 return -1;
1242 #endif
1244 case _SC_RAW_SOCKETS:
1245 #if _POSIX_RAW_SOCKETS > 0
1246 return _POSIX_RAW_SOCKETS;
1247 #else
1248 return -1;
1249 #endif
1253 #undef __sysconf
1254 weak_alias (__sysconf, sysconf)
1255 libc_hidden_def (__sysconf)
1257 #if NEED_CHECK_SPEC
1258 static long int
1259 __sysconf_check_spec (const char *spec)
1261 int save_errno = errno;
1263 const char *getconf_dir = __secure_getenv ("GETCONF_DIR") ?: GETCONF_DIR;
1264 size_t getconf_dirlen = strlen (getconf_dir);
1265 size_t speclen = strlen (spec);
1267 char name[getconf_dirlen + sizeof ("/POSIX_V6_") + speclen];
1268 memcpy (mempcpy (mempcpy (name, getconf_dir, getconf_dirlen),
1269 "/POSIX_V6_", sizeof ("/POSIX_V6_") - 1),
1270 spec, speclen + 1);
1272 struct stat64 st;
1273 long int ret = __xstat64 (_STAT_VER, name, &st) >= 0 ? 1 : -1;
1275 __set_errno (save_errno);
1276 return ret;
1278 #endif