1 /* Copyright (C) 1991-2014 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
28 #include <sys/param.h>
30 #include <sys/sysinfo.h>
31 #include <sys/types.h>
35 #define NEED_CHECK_SPEC \
36 (!defined _XBS5_ILP32_OFF32 || !defined _XBS5_ILP32_OFFBIG \
37 || !defined _XBS5_LP64_OFF64 || !defined _XBS5_LPBIG_OFFBIG \
38 || !defined _POSIX_V6_ILP32_OFF32 || !defined _POSIX_V6_ILP32_OFFBIG \
39 || !defined _POSIX_V6_LP64_OFF64 || !defined _POSIX_V6_LPBIG_OFFBIG \
40 || !defined _POSIX_V7_ILP32_OFF32 || !defined _POSIX_V7_ILP32_OFFBIG \
41 || !defined _POSIX_V7_LP64_OFF64 || !defined _POSIX_V7_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 #define START_ENV_GROUP(VERSION) \
796 #define END_ENV_GROUP(VERSION) \
799 #define KNOWN_ABSENT_ENVIRONMENT(SC_PREFIX, ENV_PREFIX, SUFFIX) \
800 case _SC_##SC_PREFIX##_##SUFFIX: \
801 return _##ENV_PREFIX##_##SUFFIX;
803 #define KNOWN_PRESENT_ENVIRONMENT(SC_PREFIX, ENV_PREFIX, SUFFIX) \
804 case _SC_##SC_PREFIX##_##SUFFIX: \
805 return _##ENV_PREFIX##_##SUFFIX;
807 #define UNKNOWN_ENVIRONMENT(SC_PREFIX, ENV_PREFIX, SUFFIX) \
808 case _SC_##SC_PREFIX##_##SUFFIX: \
809 return __sysconf_check_spec (#SUFFIX);
811 #include <posix/posix-envs.def>
813 #undef START_ENV_GROUP
815 #undef KNOWN_ABSENT_ENVIRONMENT
816 #undef KNOWN_PRESENT_ENVIRONMENT
817 #undef UNKNOWN_ENVIRONMENT
819 case _SC_XOPEN_LEGACY
:
820 return _XOPEN_LEGACY
;
822 case _SC_XOPEN_REALTIME
:
823 #ifdef _XOPEN_REALTIME
824 return _XOPEN_REALTIME
;
828 case _SC_XOPEN_REALTIME_THREADS
:
829 #ifdef _XOPEN_REALTIME_THREADS
830 return _XOPEN_REALTIME_THREADS
;
835 case _SC_ADVISORY_INFO
:
836 #if _POSIX_ADVISORY_INFO > 0
837 return _POSIX_ADVISORY_INFO
;
843 #if _POSIX_BARRIERS > 0
844 return _POSIX_BARRIERS
;
855 case _SC_C_LANG_SUPPORT
:
856 #if _POSIX_C_LANG_SUPPORT > 0
857 return _POSIX_C_LANG_SUPPORT
;
861 case _SC_C_LANG_SUPPORT_R
:
862 #if _POSIX_C_LANG_SUPPORT_R > 0
863 return _POSIX_C_LANG_SUPPORT_R
;
868 case _SC_CLOCK_SELECTION
:
869 #if _POSIX_CLOCK_SELECTION > 0
870 return _POSIX_CLOCK_SELECTION
;
876 #if _POSIX_CPUTIME > 0
877 return _POSIX_CPUTIME
;
883 #if _POSIX_DEVICE_IO > 0
884 return _POSIX_DEVICE_IO
;
888 case _SC_DEVICE_SPECIFIC
:
889 #if _POSIX_DEVICE_SPECIFIC > 0
890 return _POSIX_DEVICE_SPECIFIC
;
894 case _SC_DEVICE_SPECIFIC_R
:
895 #if _POSIX_DEVICE_SPECIFIC_R > 0
896 return _POSIX_DEVICE_SPECIFIC_R
;
902 #if _POSIX_FD_MGMT > 0
903 return _POSIX_FD_MGMT
;
921 case _SC_FILE_ATTRIBUTES
:
922 #if _POSIX_FILE_ATTRIBUTES > 0
923 return _POSIX_FILE_ATTRIBUTES
;
927 case _SC_FILE_LOCKING
:
928 #if _POSIX_FILE_LOCKING > 0
929 return _POSIX_FILE_LOCKING
;
933 case _SC_FILE_SYSTEM
:
934 #if _POSIX_FILE_SYSTEM > 0
935 return _POSIX_FILE_SYSTEM
;
940 case _SC_MONOTONIC_CLOCK
:
941 #if _POSIX_MONOTONIC_CLOCK
942 return _POSIX_MONOTONIC_CLOCK
;
947 case _SC_MULTI_PROCESS
:
948 #if _POSIX_MULTI_PROCESS > 0
949 return _POSIX_MULTI_PROCESS
;
953 case _SC_SINGLE_PROCESS
:
954 #if _POSIX_SINGLE_PROCESS > 0
955 return _POSIX_SINGLE_PROCESS
;
961 #if _POSIX_NETWORKING > 0
962 return _POSIX_NETWORKING
;
967 case _SC_READER_WRITER_LOCKS
:
968 #if _POSIX_READER_WRITER_LOCKS > 0
969 return _POSIX_READER_WRITER_LOCKS
;
974 #if _POSIX_SPIN_LOCKS > 0
975 return _POSIX_SPIN_LOCKS
;
981 #if _POSIX_REGEXP > 0
982 return _POSIX_REGEXP
;
986 /* _REGEX_VERSION has been removed with IEEE Std 1003.1-2001/Cor 2-2004,
987 item XSH/TC2/D6/137. */
988 case _SC_REGEX_VERSION
:
999 #ifdef _POSIX_SIGNALS
1000 return _POSIX_SIGNALS
;
1006 #if _POSIX_SPAWN > 0
1007 return _POSIX_SPAWN
;
1012 case _SC_SPORADIC_SERVER
:
1013 #if _POSIX_SPORADIC_SERVER > 0
1014 return _POSIX_SPORADIC_SERVER
;
1018 case _SC_THREAD_SPORADIC_SERVER
:
1019 #if _POSIX_THREAD_SPORADIC_SERVER > 0
1020 return _POSIX_THREAD_SPORADIC_SERVER
;
1025 case _SC_SYSTEM_DATABASE
:
1026 #if _POSIX_SYSTEM_DATABASE > 0
1027 return _POSIX_SYSTEM_DATABASE
;
1031 case _SC_SYSTEM_DATABASE_R
:
1032 #if _POSIX_SYSTEM_DATABASE_R > 0
1033 return _POSIX_SYSTEM_DATABASE_R
;
1038 case _SC_THREAD_CPUTIME
:
1039 #if _POSIX_THREAD_CPUTIME > 0
1040 return _POSIX_THREAD_CPUTIME
;
1046 #if _POSIX_TIMEOUTS > 0
1047 return _POSIX_TIMEOUTS
;
1052 case _SC_TYPED_MEMORY_OBJECTS
:
1053 #if _POSIX_TYPED_MEMORY_OBJECTS > 0
1054 return _POSIX_TYPED_MEMORY_OBJECTS
;
1059 case _SC_USER_GROUPS
:
1060 #if _POSIX_USER_GROUPS > 0
1061 return _POSIX_USER_GROUPS
;
1065 case _SC_USER_GROUPS_R
:
1066 #if _POSIX_USER_GROUPS_R > 0
1067 return _POSIX_USER_GROUPS_R
;
1078 case _SC_2_PBS_ACCOUNTING
:
1079 #ifdef _POSIX2_PBS_ACCOUNTING
1080 return _POSIX2_PBS_ACCOUNTING
;
1084 case _SC_2_PBS_CHECKPOINT
:
1085 #ifdef _POSIX2_PBS_CHECKPOINT
1086 return _POSIX2_PBS_CHECKPOINT
;
1090 case _SC_2_PBS_LOCATE
:
1091 #ifdef _POSIX2_PBS_LOCATE
1092 return _POSIX2_PBS_LOCATE
;
1096 case _SC_2_PBS_MESSAGE
:
1097 #ifdef _POSIX2_PBS_MESSAGE
1098 return _POSIX2_PBS_MESSAGE
;
1102 case _SC_2_PBS_TRACK
:
1103 #ifdef _POSIX2_PBS_TRACK
1104 return _POSIX2_PBS_TRACK
;
1109 case _SC_SYMLOOP_MAX
:
1117 #ifdef _XOPEN_STREAMS
1118 return _XOPEN_STREAMS
;
1123 case _SC_HOST_NAME_MAX
:
1124 #ifdef HOST_NAME_MAX
1125 return HOST_NAME_MAX
;
1131 #if _POSIX_TRACE > 0
1132 return _POSIX_TRACE
;
1136 case _SC_TRACE_EVENT_FILTER
:
1137 #if _POSIX_TRACE_EVENT_FILTER > 0
1138 return _POSIX_TRACE_EVENT_FILTER
;
1142 case _SC_TRACE_INHERIT
:
1143 #if _POSIX_TRACE_INHERIT > 0
1144 return _POSIX_TRACE_INHERIT
;
1149 #if _POSIX_TRACE_LOG > 0
1150 return _POSIX_TRACE_LOG
;
1155 case _SC_TRACE_EVENT_NAME_MAX
:
1156 case _SC_TRACE_NAME_MAX
:
1157 case _SC_TRACE_SYS_MAX
:
1158 case _SC_TRACE_USER_EVENT_MAX
:
1159 /* No support for tracing. */
1161 case _SC_XOPEN_STREAMS
:
1162 /* No support for STREAMS. */
1165 case _SC_LEVEL1_ICACHE_SIZE
:
1166 case _SC_LEVEL1_ICACHE_ASSOC
:
1167 case _SC_LEVEL1_ICACHE_LINESIZE
:
1168 case _SC_LEVEL1_DCACHE_SIZE
:
1169 case _SC_LEVEL1_DCACHE_ASSOC
:
1170 case _SC_LEVEL1_DCACHE_LINESIZE
:
1171 case _SC_LEVEL2_CACHE_SIZE
:
1172 case _SC_LEVEL2_CACHE_ASSOC
:
1173 case _SC_LEVEL2_CACHE_LINESIZE
:
1174 case _SC_LEVEL3_CACHE_SIZE
:
1175 case _SC_LEVEL3_CACHE_ASSOC
:
1176 case _SC_LEVEL3_CACHE_LINESIZE
:
1177 case _SC_LEVEL4_CACHE_SIZE
:
1178 case _SC_LEVEL4_CACHE_ASSOC
:
1179 case _SC_LEVEL4_CACHE_LINESIZE
:
1180 /* In general we cannot determine these values. Therefore we
1181 return zero which indicates that no information is
1192 case _SC_RAW_SOCKETS
:
1193 #if _POSIX_RAW_SOCKETS > 0
1194 return _POSIX_RAW_SOCKETS
;
1202 weak_alias (__sysconf
, sysconf
)
1203 libc_hidden_def (__sysconf
)
1207 __sysconf_check_spec (const char *spec
)
1209 int save_errno
= errno
;
1211 const char *getconf_dir
= __libc_secure_getenv ("GETCONF_DIR") ?: GETCONF_DIR
;
1212 size_t getconf_dirlen
= strlen (getconf_dir
);
1213 size_t speclen
= strlen (spec
);
1215 char name
[getconf_dirlen
+ sizeof ("/POSIX_V6_") + speclen
];
1216 memcpy (mempcpy (mempcpy (name
, getconf_dir
, getconf_dirlen
),
1217 "/POSIX_V6_", sizeof ("/POSIX_V6_") - 1),
1221 long int ret
= __xstat64 (_STAT_VER
, name
, &st
) >= 0 ? 1 : -1;
1223 __set_errno (save_errno
);