1 /* Copyright (C) 1991,1993,1995-1997,1999-2003,2004,2006
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
30 #include <sys/param.h>
32 #include <sys/sysinfo.h>
33 #include <sys/types.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)
43 static long int __sysconf_check_spec (const char *spec
);
47 /* Get the value of the system variable NAME. */
54 /* Also add obsolete or unnecessarily added constants here. */
55 case _SC_EQUIV_CLASS_MAX
:
71 return __get_child_max ();
75 return __getclktck ();
85 return __getdtablesize ();
95 return MAX (__tzname_max (), _POSIX_TZNAME_MAX
);
98 #if _POSIX_JOB_CONTROL > 0
99 return _POSIX_JOB_CONTROL
;
105 #if _POSIX_SAVED_IDS > 0
111 case _SC_REALTIME_SIGNALS
:
112 #if _POSIX_REALTIME_SIGNALS > 0
113 return _POSIX_REALTIME_SIGNALS
;
118 case _SC_PRIORITY_SCHEDULING
:
119 #if _POSIX_PRIORITY_SCHEDULING > 0
120 return _POSIX_PRIORITY_SCHEDULING
;
126 #if _POSIX_TIMERS > 0
127 return _POSIX_TIMERS
;
132 case _SC_ASYNCHRONOUS_IO
:
133 #if _POSIX_ASYNCHRONOUS_IO > 0
134 return _POSIX_ASYNCHRONOUS_IO
;
139 case _SC_PRIORITIZED_IO
:
140 #if _POSIX_PRIORITIZED_IO > 0
141 return _POSIX_PRIORITIZED_IO
;
146 case _SC_SYNCHRONIZED_IO
:
147 #if _POSIX_SYNCHRONIZED_IO > 0
148 return _POSIX_SYNCHRONIZED_IO
;
160 case _SC_MAPPED_FILES
:
161 #if _POSIX_MAPPED_FILES > 0
162 return _POSIX_MAPPED_FILES
;
168 #if _POSIX_MEMLOCK > 0
169 return _POSIX_MEMLOCK
;
174 case _SC_MEMLOCK_RANGE
:
175 #if _POSIX_MEMLOCK_RANGE > 0
176 return _POSIX_MEMLOCK_RANGE
;
181 case _SC_MEMORY_PROTECTION
:
182 #if _POSIX_MEMORY_PROTECTION > 0
183 return _POSIX_MEMORY_PROTECTION
;
188 case _SC_MESSAGE_PASSING
:
189 #if _POSIX_MESSAGE_PASSING > 0
190 return _POSIX_MESSAGE_PASSING
;
196 #if _POSIX_SEMAPHORES > 0
197 return _POSIX_SEMAPHORES
;
202 case _SC_SHARED_MEMORY_OBJECTS
:
203 #if _POSIX_SHARED_MEMORY_OBJECTS > 0
204 return _POSIX_SHARED_MEMORY_OBJECTS
;
210 return _POSIX_VERSION
;
213 return __getpagesize ();
215 case _SC_AIO_LISTIO_MAX
:
216 #ifdef AIO_LISTIO_MAX
217 return AIO_LISTIO_MAX
;
229 case _SC_AIO_PRIO_DELTA_MAX
:
230 #ifdef AIO_PRIO_DELTA_MAX
231 return AIO_PRIO_DELTA_MAX
;
236 case _SC_DELAYTIMER_MAX
:
237 #ifdef DELAYTIMER_MAX
238 return DELAYTIMER_MAX
;
243 case _SC_MQ_OPEN_MAX
:
250 case _SC_MQ_PRIO_MAX
:
264 case _SC_SEM_NSEMS_MAX
:
266 return SEM_NSEMS_MAX
;
271 case _SC_SEM_VALUE_MAX
:
273 return SEM_VALUE_MAX
;
278 case _SC_SIGQUEUE_MAX
:
292 case _SC_BC_BASE_MAX
:
306 case _SC_BC_SCALE_MAX
:
313 case _SC_BC_STRING_MAX
:
315 return BC_STRING_MAX
;
320 case _SC_COLL_WEIGHTS_MAX
:
321 #ifdef COLL_WEIGHTS_MAX
322 return COLL_WEIGHTS_MAX
;
327 case _SC_EXPR_NEST_MAX
:
329 return EXPR_NEST_MAX
;
348 case _SC_CHARCLASS_NAME_MAX
:
349 #ifdef CHARCLASS_NAME_MAX
350 return CHARCLASS_NAME_MAX
;
363 #if _POSIX_PII_XTI > 0
370 #if _POSIX_PII_SOCKET > 0
376 case _SC_PII_INTERNET
:
377 #if _POSIX_PII_INTERNET > 0
384 #if _POSIX_PII_OSI > 0
398 #if _POSIX_SELECT > 0
404 /* The same as _SC_IOV_MAX. */
412 case _SC_PII_INTERNET_STREAM
:
413 #if _POSIX_PII_INTERNET_STREAM > 0
419 case _SC_PII_INTERNET_DGRAM
:
420 #if _POSIX_PII_INTERNET_DGRAM > 0
426 case _SC_PII_OSI_COTS
:
427 #if _POSIX_PII_OSI_COTS > 0
433 case _SC_PII_OSI_CLTS
:
434 #if _POSIX_PII_OSI_CLTS > 0
441 #if _POSIX_PII_OSI_M > 0
455 return _POSIX2_VERSION
;
458 #ifdef _POSIX2_C_BIND
459 return _POSIX2_C_BIND
;
466 return _POSIX2_C_DEV
;
471 case _SC_2_C_VERSION
:
472 #ifdef _POSIX2_C_VERSION
473 return _POSIX2_C_VERSION
;
479 #ifdef _POSIX2_FORT_DEV
480 return _POSIX2_FORT_DEV
;
486 #ifdef _POSIX2_FORT_RUN
487 return _POSIX2_FORT_RUN
;
492 case _SC_2_LOCALEDEF
:
493 #ifdef _POSIX2_LOCALEDEF
494 return _POSIX2_LOCALEDEF
;
500 #ifdef _POSIX2_SW_DEV
501 return _POSIX2_SW_DEV
;
506 case _SC_2_CHAR_TERM
:
507 #ifdef _POSIX2_CHAR_TERM
508 return _POSIX2_CHAR_TERM
;
520 /* POSIX 1003.1c (POSIX Threads). */
522 #if _POSIX_THREADS > 0
523 return _POSIX_THREADS
;
528 case _SC_THREAD_SAFE_FUNCTIONS
:
529 #if _POSIX_THREAD_SAFE_FUNCTIONS > 0
530 return _POSIX_THREAD_SAFE_FUNCTIONS
;
535 case _SC_GETGR_R_SIZE_MAX
:
536 return NSS_BUFLEN_GROUP
;
538 case _SC_GETPW_R_SIZE_MAX
:
539 return NSS_BUFLEN_PASSWD
;
541 case _SC_LOGIN_NAME_MAX
:
542 #ifdef LOGIN_NAME_MAX
543 return LOGIN_NAME_MAX
;
548 case _SC_TTY_NAME_MAX
:
555 case _SC_THREAD_DESTRUCTOR_ITERATIONS
:
556 #if _POSIX_THREAD_DESTRUCTOR_ITERATIONS > 0
557 return _POSIX_THREAD_DESTRUCTOR_ITERATIONS
;
562 case _SC_THREAD_KEYS_MAX
:
563 #ifdef PTHREAD_KEYS_MAX
564 return PTHREAD_KEYS_MAX
;
569 case _SC_THREAD_STACK_MIN
:
570 #ifdef PTHREAD_STACK_MIN
571 return PTHREAD_STACK_MIN
;
576 case _SC_THREAD_THREADS_MAX
:
577 #ifdef PTHREAD_THREADS_MAX
578 return PTHREAD_THREADS_MAX
;
583 case _SC_THREAD_ATTR_STACKADDR
:
584 #if _POSIX_THREAD_ATTR_STACKADDR > 0
585 return _POSIX_THREAD_ATTR_STACKADDR
;
590 case _SC_THREAD_ATTR_STACKSIZE
:
591 #if _POSIX_THREAD_ATTR_STACKSIZE > 0
592 return _POSIX_THREAD_ATTR_STACKSIZE
;
597 case _SC_THREAD_PRIORITY_SCHEDULING
:
598 #if _POSIX_THREAD_PRIORITY_SCHEDULING > 0
599 return _POSIX_THREAD_PRIORITY_SCHEDULING
;
604 case _SC_THREAD_PRIO_INHERIT
:
605 #if _POSIX_THREAD_PRIO_INHERIT > 0
606 return _POSIX_THREAD_PRIO_INHERIT
;
611 case _SC_THREAD_PRIO_PROTECT
:
612 #if _POSIX_THREAD_PRIO_PROTECT > 0
613 return _POSIX_THREAD_PRIO_PROTECT
;
618 case _SC_THREAD_PROCESS_SHARED
:
619 #if _POSIX_THREAD_PROCESS_SHARED > 0
620 return _POSIX_THREAD_PROCESS_SHARED
;
625 case _SC_NPROCESSORS_CONF
:
626 return __get_nprocs_conf ();
628 case _SC_NPROCESSORS_ONLN
:
629 return __get_nprocs ();
632 return __get_phys_pages ();
634 case _SC_AVPHYS_PAGES
:
635 return __get_avphys_pages ();
638 /* We have no limit since we use lists. */
642 /* We have no limit but since the return value might be used to
643 allocate a buffer we restrict the value. */
646 case _SC_XOPEN_VERSION
:
647 return _XOPEN_VERSION
;
649 case _SC_XOPEN_XCU_VERSION
:
650 return _XOPEN_XCU_VERSION
;
655 case _SC_XOPEN_CRYPT
:
662 case _SC_XOPEN_ENH_I18N
:
663 #ifdef _XOPEN_ENH_I18N
664 return _XOPEN_ENH_I18N
;
713 return sizeof (long int) * CHAR_BIT
;
716 return sizeof (int) * CHAR_BIT
;
725 return _POSIX_SSIZE_MAX
;
793 case _SC_XBS5_ILP32_OFF32
:
794 #ifdef _XBS5_ILP32_OFF32
795 return _XBS5_ILP32_OFF32
;
797 return __sysconf_check_spec ("ILP32_OFF32");
799 case _SC_XBS5_ILP32_OFFBIG
:
800 #ifdef _XBS5_ILP32_OFFBIG
801 return _XBS5_ILP32_OFFBIG
;
803 return __sysconf_check_spec ("ILP32_OFFBIG");
805 case _SC_XBS5_LP64_OFF64
:
806 #ifdef _XBS5_LP64_OFF64
807 return _XBS5_LP64_OFF64
;
809 return __sysconf_check_spec ("LP64_OFF64");
811 case _SC_XBS5_LPBIG_OFFBIG
:
812 #ifdef _XBS5_LPBIG_OFFBIG
813 return _XBS5_LPBIG_OFFBIG
;
815 return __sysconf_check_spec ("LPBIG_OFFBIG");
818 case _SC_V6_ILP32_OFF32
:
819 #ifdef _POSIX_V6_ILP32_OFF32
820 return _POSIX_V6_ILP32_OFF32
;
822 return __sysconf_check_spec ("ILP32_OFF32");
824 case _SC_V6_ILP32_OFFBIG
:
825 #ifdef _POSIX_V6_ILP32_OFFBIG
826 return _POSIX_V6_ILP32_OFFBIG
;
828 return __sysconf_check_spec ("ILP32_OFFBIG");
830 case _SC_V6_LP64_OFF64
:
831 #ifdef _POSIX_V6_LP64_OFF64
832 return _POSIX_V6_LP64_OFF64
;
834 return __sysconf_check_spec ("LP64_OFF64");
836 case _SC_V6_LPBIG_OFFBIG
:
837 #ifdef _POSIX_V6_LPBIG_OFFBIG
838 return _POSIX_V6_LPBIG_OFFBIG
;
840 return __sysconf_check_spec ("LPBIG_OFFBIG");
843 case _SC_XOPEN_LEGACY
:
844 return _XOPEN_LEGACY
;
846 case _SC_XOPEN_REALTIME
:
847 #ifdef _XOPEN_REALTIME
848 return _XOPEN_REALTIME
;
852 case _SC_XOPEN_REALTIME_THREADS
:
853 #ifdef _XOPEN_REALTIME_THREADS
854 return _XOPEN_REALTIME_THREADS
;
859 case _SC_ADVISORY_INFO
:
860 #if _POSIX_ADVISORY_INFO > 0
861 return _POSIX_ADVISORY_INFO
;
867 #if _POSIX_BARRIERS > 0
868 return _POSIX_BARRIERS
;
879 case _SC_C_LANG_SUPPORT
:
880 #if _POSIX_C_LANG_SUPPORT > 0
881 return _POSIX_C_LANG_SUPPORT
;
885 case _SC_C_LANG_SUPPORT_R
:
886 #if _POSIX_C_LANG_SUPPORT_R > 0
887 return _POSIX_C_LANG_SUPPORT_R
;
892 case _SC_CLOCK_SELECTION
:
893 #if _POSIX_CLOCK_SELECTION > 0
894 return _POSIX_CLOCK_SELECTION
;
900 #if _POSIX_CPUTIME > 0
901 return _POSIX_CPUTIME
;
907 #if _POSIX_DEVICE_IO > 0
908 return _POSIX_DEVICE_IO
;
912 case _SC_DEVICE_SPECIFIC
:
913 #if _POSIX_DEVICE_SPCIFIC > 0
914 return _POSIX_DEVICE_SPECIFIC
;
918 case _SC_DEVICE_SPECIFIC_R
:
919 #if _POSIX_DEVICE_SPCIFIC_R > 0
920 return _POSIX_DEVICE_SPECIFIC_R
;
926 #if _POSIX_FD_MGMT > 0
927 return _POSIX_FD_MGMT
;
945 case _SC_FILE_ATTRIBUTES
:
946 #if _POSIX_FILE_ATTRIBUTES > 0
947 return _POSIX_FILE_ATTRIBUTES
;
951 case _SC_FILE_LOCKING
:
952 #if _POSIX_FILE_LOCKING > 0
953 return _POSIX_FILE_LOCKING
;
957 case _SC_FILE_SYSTEM
:
958 #if _POSIX_FILE_SYSTEM > 0
959 return _POSIX_FILE_SYSTEM
;
964 case _SC_MONOTONIC_CLOCK
:
965 #if _POSIX_MONOTONIC_CLOCK
966 return _POSIX_MONOTONIC_CLOCK
;
971 case _SC_MULTI_PROCESS
:
972 #if _POSIX_MULTI_PROCESS > 0
973 return _POSIX_MULTI_PROCESS
;
977 case _SC_SINGLE_PROCESS
:
978 #if _POSIX_SINGLE_PROCESS > 0
979 return _POSIX_SINGLE_PROCESS
;
985 #if _POSIX_NETWORKING > 0
986 return _POSIX_NETWORKING
;
991 case _SC_READER_WRITER_LOCKS
:
992 #if _POSIX_READER_WRITER_LOCKS > 0
993 return _POSIX_READER_WRITER_LOCKS
;
998 #if _POSIX_SPIN_LOCKS > 0
999 return _POSIX_SPIN_LOCKS
;
1005 #if _POSIX_REGEXP > 0
1006 return _POSIX_REGEXP
;
1010 case _SC_REGEX_VERSION
:
1011 #if _POSIX_REGEX_VERSION > 0
1012 return _POSIX_REGEX_VERSION
;
1018 #if _POSIX_SHELL > 0
1019 return _POSIX_SHELL
;
1025 #ifdef _POSUX_SIGNALS
1026 return _POSIX_SIGNALS
;
1032 #if _POSIX_SPAWN > 0
1033 return _POSIX_SPAWN
;
1038 case _SC_SPORADIC_SERVER
:
1039 #if _POSIX_SPORADIC_SERVER > 0
1040 return _POSIX_SPORADIC_SERVER
;
1044 case _SC_THREAD_SPORADIC_SERVER
:
1045 #if _POSIX_THREAD_SPORADIC_SERVER > 0
1046 return _POSIX_THREAD_SPORADIC_SERVER
;
1051 case _SC_SYSTEM_DATABASE
:
1052 #if _POSIX_SYSTEM_DATABASE > 0
1053 return _POSIX_SYSTEM_DATABASE
;
1057 case _SC_SYSTEM_DATABASE_R
:
1058 #if _POSIX_SYSTEM_DATABASE_R > 0
1059 return _POSIX_SYSTEM_DATABASE_R
;
1064 case _SC_THREAD_CPUTIME
:
1065 #if _POSIX_THREAD_CPUTIME > 0
1066 return _POSIX_THREAD_CPUTIME
;
1072 #if _POSIX_TIMEOUTS > 0
1073 return _POSIX_TIMEOUTS
;
1078 case _SC_TYPED_MEMORY_OBJECTS
:
1079 #if _POSIX_TYPED_MEMORY_OBJECTS > 0
1080 return _POSIX_TYPED_MEMORY_OBJECTS
;
1085 case _SC_USER_GROUPS
:
1086 #if _POSIX_USER_GROUPS > 0
1087 return _POSIX_USER_GROUPS
;
1091 case _SC_USER_GROUPS_R
:
1092 #if _POSIX_USER_GROUPS_R > 0
1093 return _POSIX_USER_GROUPS_R
;
1104 case _SC_2_PBS_ACCOUNTING
:
1105 #ifdef _POSIX2_PBS_ACCOUNTING
1106 return _POSIX2_PBS_ACCOUNTING
;
1110 case _SC_2_PBS_CHECKPOINT
:
1111 #ifdef _POSIX2_PBS_CHECKPOINT
1112 return _POSIX2_PBS_CHECKPOINT
;
1116 case _SC_2_PBS_LOCATE
:
1117 #ifdef _POSIX2_PBS_LOCATE
1118 return _POSIX2_PBS_LOCATE
;
1122 case _SC_2_PBS_MESSAGE
:
1123 #ifdef _POSIX2_PBS_MESSAGE
1124 return _POSIX2_PBS_MESSAGE
;
1128 case _SC_2_PBS_TRACK
:
1129 #ifdef _POSIX2_PBS_TRACK
1130 return _POSIX2_PBS_TRACK
;
1135 case _SC_SYMLOOP_MAX
:
1143 #ifdef _XOPEN_STREAMS
1144 return _XOPEN_STREAMS
;
1149 case _SC_HOST_NAME_MAX
:
1150 #ifdef HOST_NAME_MAX
1151 return HOST_NAME_MAX
;
1157 #if _POSIX_TRACE > 0
1158 return _POSIX_TRACE
;
1162 case _SC_TRACE_EVENT_FILTER
:
1163 #if _POSIX_TRACE_EVENT_FILTER > 0
1164 return _POSIX_TRACE_EVENT_FILTER
;
1168 case _SC_TRACE_INHERIT
:
1169 #if _POSIX_TRACE_INHERIT > 0
1170 return _POSIX_TRACE_INHERIT
;
1175 #if _POSIX_TRACE_LOG > 0
1176 return _POSIX_TRACE_LOG
;
1181 case _SC_LEVEL1_ICACHE_SIZE
:
1182 case _SC_LEVEL1_ICACHE_ASSOC
:
1183 case _SC_LEVEL1_ICACHE_LINESIZE
:
1184 case _SC_LEVEL1_DCACHE_SIZE
:
1185 case _SC_LEVEL1_DCACHE_ASSOC
:
1186 case _SC_LEVEL1_DCACHE_LINESIZE
:
1187 case _SC_LEVEL2_CACHE_SIZE
:
1188 case _SC_LEVEL2_CACHE_ASSOC
:
1189 case _SC_LEVEL2_CACHE_LINESIZE
:
1190 case _SC_LEVEL3_CACHE_SIZE
:
1191 case _SC_LEVEL3_CACHE_ASSOC
:
1192 case _SC_LEVEL3_CACHE_LINESIZE
:
1193 case _SC_LEVEL4_CACHE_SIZE
:
1194 case _SC_LEVEL4_CACHE_ASSOC
:
1195 /* In general we cannot determine these values. Therefore we
1196 return zero which indicates that no information is
1207 case _SC_RAW_SOCKETS
:
1208 #if _POSIX_RAW_SOCKETS > 0
1209 return _POSIX_RAW_SOCKETS
;
1217 weak_alias (__sysconf
, sysconf
)
1218 libc_hidden_def (__sysconf
)
1222 __sysconf_check_spec (const char *spec
)
1224 int save_errno
= errno
;
1226 const char *getconf_dir
= __secure_getenv ("GETCONF_DIR") ?: GETCONF_DIR
;
1227 size_t getconf_dirlen
= strlen (getconf_dir
);
1228 size_t speclen
= strlen (spec
);
1230 char name
[getconf_dirlen
+ sizeof ("/POSIX_V6_") + speclen
];
1231 memcpy (mempcpy (mempcpy (name
, getconf_dir
, getconf_dirlen
),
1232 "/POSIX_V6_", sizeof ("/POSIX_V6_") - 1),
1236 long int ret
= __xstat64 (_STAT_VER
, name
, &st
) >= 0 ? 1 : -1;
1238 __set_errno (save_errno
);