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
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 \
42 || !defined _POSIX_V7_ILP32_OFF32 || !defined _POSIX_V7_ILP32_OFFBIG \
43 || !defined _POSIX_V7_LP64_OFF64 || !defined _POSIX_V7_LPBIG_OFFBIG)
45 static long int __sysconf_check_spec (const char *spec
);
49 /* Get the value of the system variable NAME. */
56 /* Also add obsolete or unnecessarily added constants here. */
57 case _SC_EQUIV_CLASS_MAX
:
73 return __get_child_max ();
77 return __getclktck ();
87 return __getdtablesize ();
97 return MAX (__tzname_max (), _POSIX_TZNAME_MAX
);
100 #if _POSIX_JOB_CONTROL > 0
101 return _POSIX_JOB_CONTROL
;
107 #if _POSIX_SAVED_IDS > 0
113 case _SC_REALTIME_SIGNALS
:
114 #if _POSIX_REALTIME_SIGNALS > 0
115 return _POSIX_REALTIME_SIGNALS
;
120 case _SC_PRIORITY_SCHEDULING
:
121 #if _POSIX_PRIORITY_SCHEDULING > 0
122 return _POSIX_PRIORITY_SCHEDULING
;
128 #if _POSIX_TIMERS > 0
129 return _POSIX_TIMERS
;
134 case _SC_ASYNCHRONOUS_IO
:
135 #if _POSIX_ASYNCHRONOUS_IO > 0
136 return _POSIX_ASYNCHRONOUS_IO
;
141 case _SC_PRIORITIZED_IO
:
142 #if _POSIX_PRIORITIZED_IO > 0
143 return _POSIX_PRIORITIZED_IO
;
148 case _SC_SYNCHRONIZED_IO
:
149 #if _POSIX_SYNCHRONIZED_IO > 0
150 return _POSIX_SYNCHRONIZED_IO
;
162 case _SC_MAPPED_FILES
:
163 #if _POSIX_MAPPED_FILES > 0
164 return _POSIX_MAPPED_FILES
;
170 #if _POSIX_MEMLOCK > 0
171 return _POSIX_MEMLOCK
;
176 case _SC_MEMLOCK_RANGE
:
177 #if _POSIX_MEMLOCK_RANGE > 0
178 return _POSIX_MEMLOCK_RANGE
;
183 case _SC_MEMORY_PROTECTION
:
184 #if _POSIX_MEMORY_PROTECTION > 0
185 return _POSIX_MEMORY_PROTECTION
;
190 case _SC_MESSAGE_PASSING
:
191 #if _POSIX_MESSAGE_PASSING > 0
192 return _POSIX_MESSAGE_PASSING
;
198 #if _POSIX_SEMAPHORES > 0
199 return _POSIX_SEMAPHORES
;
204 case _SC_SHARED_MEMORY_OBJECTS
:
205 #if _POSIX_SHARED_MEMORY_OBJECTS > 0
206 return _POSIX_SHARED_MEMORY_OBJECTS
;
212 return _POSIX_VERSION
;
215 return __getpagesize ();
217 case _SC_AIO_LISTIO_MAX
:
218 #ifdef AIO_LISTIO_MAX
219 return AIO_LISTIO_MAX
;
231 case _SC_AIO_PRIO_DELTA_MAX
:
232 #ifdef AIO_PRIO_DELTA_MAX
233 return AIO_PRIO_DELTA_MAX
;
238 case _SC_DELAYTIMER_MAX
:
239 #ifdef DELAYTIMER_MAX
240 return DELAYTIMER_MAX
;
245 case _SC_MQ_OPEN_MAX
:
252 case _SC_MQ_PRIO_MAX
:
266 case _SC_SEM_NSEMS_MAX
:
268 return SEM_NSEMS_MAX
;
273 case _SC_SEM_VALUE_MAX
:
275 return SEM_VALUE_MAX
;
280 case _SC_SIGQUEUE_MAX
:
294 case _SC_BC_BASE_MAX
:
308 case _SC_BC_SCALE_MAX
:
315 case _SC_BC_STRING_MAX
:
317 return BC_STRING_MAX
;
322 case _SC_COLL_WEIGHTS_MAX
:
323 #ifdef COLL_WEIGHTS_MAX
324 return COLL_WEIGHTS_MAX
;
329 case _SC_EXPR_NEST_MAX
:
331 return EXPR_NEST_MAX
;
350 case _SC_CHARCLASS_NAME_MAX
:
351 #ifdef CHARCLASS_NAME_MAX
352 return CHARCLASS_NAME_MAX
;
365 #if _POSIX_PII_XTI > 0
372 #if _POSIX_PII_SOCKET > 0
378 case _SC_PII_INTERNET
:
379 #if _POSIX_PII_INTERNET > 0
386 #if _POSIX_PII_OSI > 0
400 #if _POSIX_SELECT > 0
406 /* The same as _SC_IOV_MAX. */
414 case _SC_PII_INTERNET_STREAM
:
415 #if _POSIX_PII_INTERNET_STREAM > 0
421 case _SC_PII_INTERNET_DGRAM
:
422 #if _POSIX_PII_INTERNET_DGRAM > 0
428 case _SC_PII_OSI_COTS
:
429 #if _POSIX_PII_OSI_COTS > 0
435 case _SC_PII_OSI_CLTS
:
436 #if _POSIX_PII_OSI_CLTS > 0
443 #if _POSIX_PII_OSI_M > 0
457 return _POSIX2_VERSION
;
460 #ifdef _POSIX2_C_BIND
461 return _POSIX2_C_BIND
;
468 return _POSIX2_C_DEV
;
473 case _SC_2_C_VERSION
:
474 #ifdef _POSIX2_C_VERSION
475 return _POSIX2_C_VERSION
;
481 #ifdef _POSIX2_FORT_DEV
482 return _POSIX2_FORT_DEV
;
488 #ifdef _POSIX2_FORT_RUN
489 return _POSIX2_FORT_RUN
;
494 case _SC_2_LOCALEDEF
:
495 #ifdef _POSIX2_LOCALEDEF
496 return _POSIX2_LOCALEDEF
;
502 #ifdef _POSIX2_SW_DEV
503 return _POSIX2_SW_DEV
;
508 case _SC_2_CHAR_TERM
:
509 #ifdef _POSIX2_CHAR_TERM
510 return _POSIX2_CHAR_TERM
;
522 /* POSIX 1003.1c (POSIX Threads). */
524 #if _POSIX_THREADS > 0
525 return _POSIX_THREADS
;
530 case _SC_THREAD_SAFE_FUNCTIONS
:
531 #if _POSIX_THREAD_SAFE_FUNCTIONS > 0
532 return _POSIX_THREAD_SAFE_FUNCTIONS
;
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
;
550 case _SC_TTY_NAME_MAX
:
557 case _SC_THREAD_DESTRUCTOR_ITERATIONS
:
558 #if _POSIX_THREAD_DESTRUCTOR_ITERATIONS > 0
559 return _POSIX_THREAD_DESTRUCTOR_ITERATIONS
;
564 case _SC_THREAD_KEYS_MAX
:
565 #ifdef PTHREAD_KEYS_MAX
566 return PTHREAD_KEYS_MAX
;
571 case _SC_THREAD_STACK_MIN
:
572 #ifdef PTHREAD_STACK_MIN
573 return PTHREAD_STACK_MIN
;
578 case _SC_THREAD_THREADS_MAX
:
579 #ifdef PTHREAD_THREADS_MAX
580 return PTHREAD_THREADS_MAX
;
585 case _SC_THREAD_ATTR_STACKADDR
:
586 #if _POSIX_THREAD_ATTR_STACKADDR > 0
587 return _POSIX_THREAD_ATTR_STACKADDR
;
592 case _SC_THREAD_ATTR_STACKSIZE
:
593 #if _POSIX_THREAD_ATTR_STACKSIZE > 0
594 return _POSIX_THREAD_ATTR_STACKSIZE
;
599 case _SC_THREAD_PRIORITY_SCHEDULING
:
600 #if _POSIX_THREAD_PRIORITY_SCHEDULING > 0
601 return _POSIX_THREAD_PRIORITY_SCHEDULING
;
606 case _SC_THREAD_PRIO_INHERIT
:
607 #if _POSIX_THREAD_PRIO_INHERIT > 0
608 return _POSIX_THREAD_PRIO_INHERIT
;
613 case _SC_THREAD_PRIO_PROTECT
:
614 #if _POSIX_THREAD_PRIO_PROTECT > 0
615 return _POSIX_THREAD_PRIO_PROTECT
;
620 case _SC_THREAD_PROCESS_SHARED
:
621 #if _POSIX_THREAD_PROCESS_SHARED > 0
622 return _POSIX_THREAD_PROCESS_SHARED
;
627 case _SC_NPROCESSORS_CONF
:
628 return __get_nprocs_conf ();
630 case _SC_NPROCESSORS_ONLN
:
631 return __get_nprocs ();
634 return __get_phys_pages ();
636 case _SC_AVPHYS_PAGES
:
637 return __get_avphys_pages ();
640 /* We have no limit since we use lists. */
644 /* We have no limit but since the return value might be used to
645 allocate a buffer we restrict the value. */
648 case _SC_XOPEN_VERSION
:
649 return _XOPEN_VERSION
;
651 case _SC_XOPEN_XCU_VERSION
:
652 return _XOPEN_XCU_VERSION
;
657 case _SC_XOPEN_CRYPT
:
664 case _SC_XOPEN_ENH_I18N
:
665 #ifdef _XOPEN_ENH_I18N
666 return _XOPEN_ENH_I18N
;
715 return sizeof (long int) * CHAR_BIT
;
718 return sizeof (int) * CHAR_BIT
;
727 return _POSIX_SSIZE_MAX
;
795 case _SC_XBS5_ILP32_OFF32
:
796 #ifdef _XBS5_ILP32_OFF32
797 return _XBS5_ILP32_OFF32
;
799 return __sysconf_check_spec ("ILP32_OFF32");
801 case _SC_XBS5_ILP32_OFFBIG
:
802 #ifdef _XBS5_ILP32_OFFBIG
803 return _XBS5_ILP32_OFFBIG
;
805 return __sysconf_check_spec ("ILP32_OFFBIG");
807 case _SC_XBS5_LP64_OFF64
:
808 #ifdef _XBS5_LP64_OFF64
809 return _XBS5_LP64_OFF64
;
811 return __sysconf_check_spec ("LP64_OFF64");
813 case _SC_XBS5_LPBIG_OFFBIG
:
814 #ifdef _XBS5_LPBIG_OFFBIG
815 return _XBS5_LPBIG_OFFBIG
;
817 return __sysconf_check_spec ("LPBIG_OFFBIG");
820 case _SC_V6_ILP32_OFF32
:
821 #ifdef _POSIX_V6_ILP32_OFF32
822 return _POSIX_V6_ILP32_OFF32
;
824 return __sysconf_check_spec ("ILP32_OFF32");
826 case _SC_V6_ILP32_OFFBIG
:
827 #ifdef _POSIX_V6_ILP32_OFFBIG
828 return _POSIX_V6_ILP32_OFFBIG
;
830 return __sysconf_check_spec ("ILP32_OFFBIG");
832 case _SC_V6_LP64_OFF64
:
833 #ifdef _POSIX_V6_LP64_OFF64
834 return _POSIX_V6_LP64_OFF64
;
836 return __sysconf_check_spec ("LP64_OFF64");
838 case _SC_V6_LPBIG_OFFBIG
:
839 #ifdef _POSIX_V6_LPBIG_OFFBIG
840 return _POSIX_V6_LPBIG_OFFBIG
;
842 return __sysconf_check_spec ("LPBIG_OFFBIG");
845 case _SC_V7_ILP32_OFF32
:
846 #ifdef _POSIX_V7_ILP32_OFF32
847 return _POSIX_V7_ILP32_OFF32
;
849 return __sysconf_check_spec ("ILP32_OFF32");
851 case _SC_V7_ILP32_OFFBIG
:
852 #ifdef _POSIX_V7_ILP32_OFFBIG
853 return _POSIX_V7_ILP32_OFFBIG
;
855 return __sysconf_check_spec ("ILP32_OFFBIG");
857 case _SC_V7_LP64_OFF64
:
858 #ifdef _POSIX_V7_LP64_OFF64
859 return _POSIX_V7_LP64_OFF64
;
861 return __sysconf_check_spec ("LP64_OFF64");
863 case _SC_V7_LPBIG_OFFBIG
:
864 #ifdef _POSIX_V7_LPBIG_OFFBIG
865 return _POSIX_V7_LPBIG_OFFBIG
;
867 return __sysconf_check_spec ("LPBIG_OFFBIG");
870 case _SC_XOPEN_LEGACY
:
871 return _XOPEN_LEGACY
;
873 case _SC_XOPEN_REALTIME
:
874 #ifdef _XOPEN_REALTIME
875 return _XOPEN_REALTIME
;
879 case _SC_XOPEN_REALTIME_THREADS
:
880 #ifdef _XOPEN_REALTIME_THREADS
881 return _XOPEN_REALTIME_THREADS
;
886 case _SC_ADVISORY_INFO
:
887 #if _POSIX_ADVISORY_INFO > 0
888 return _POSIX_ADVISORY_INFO
;
894 #if _POSIX_BARRIERS > 0
895 return _POSIX_BARRIERS
;
906 case _SC_C_LANG_SUPPORT
:
907 #if _POSIX_C_LANG_SUPPORT > 0
908 return _POSIX_C_LANG_SUPPORT
;
912 case _SC_C_LANG_SUPPORT_R
:
913 #if _POSIX_C_LANG_SUPPORT_R > 0
914 return _POSIX_C_LANG_SUPPORT_R
;
919 case _SC_CLOCK_SELECTION
:
920 #if _POSIX_CLOCK_SELECTION > 0
921 return _POSIX_CLOCK_SELECTION
;
927 #if _POSIX_CPUTIME > 0
928 return _POSIX_CPUTIME
;
934 #if _POSIX_DEVICE_IO > 0
935 return _POSIX_DEVICE_IO
;
939 case _SC_DEVICE_SPECIFIC
:
940 #if _POSIX_DEVICE_SPCIFIC > 0
941 return _POSIX_DEVICE_SPECIFIC
;
945 case _SC_DEVICE_SPECIFIC_R
:
946 #if _POSIX_DEVICE_SPCIFIC_R > 0
947 return _POSIX_DEVICE_SPECIFIC_R
;
953 #if _POSIX_FD_MGMT > 0
954 return _POSIX_FD_MGMT
;
972 case _SC_FILE_ATTRIBUTES
:
973 #if _POSIX_FILE_ATTRIBUTES > 0
974 return _POSIX_FILE_ATTRIBUTES
;
978 case _SC_FILE_LOCKING
:
979 #if _POSIX_FILE_LOCKING > 0
980 return _POSIX_FILE_LOCKING
;
984 case _SC_FILE_SYSTEM
:
985 #if _POSIX_FILE_SYSTEM > 0
986 return _POSIX_FILE_SYSTEM
;
991 case _SC_MONOTONIC_CLOCK
:
992 #if _POSIX_MONOTONIC_CLOCK
993 return _POSIX_MONOTONIC_CLOCK
;
998 case _SC_MULTI_PROCESS
:
999 #if _POSIX_MULTI_PROCESS > 0
1000 return _POSIX_MULTI_PROCESS
;
1004 case _SC_SINGLE_PROCESS
:
1005 #if _POSIX_SINGLE_PROCESS > 0
1006 return _POSIX_SINGLE_PROCESS
;
1011 case _SC_NETWORKING
:
1012 #if _POSIX_NETWORKING > 0
1013 return _POSIX_NETWORKING
;
1018 case _SC_READER_WRITER_LOCKS
:
1019 #if _POSIX_READER_WRITER_LOCKS > 0
1020 return _POSIX_READER_WRITER_LOCKS
;
1024 case _SC_SPIN_LOCKS
:
1025 #if _POSIX_SPIN_LOCKS > 0
1026 return _POSIX_SPIN_LOCKS
;
1032 #if _POSIX_REGEXP > 0
1033 return _POSIX_REGEXP
;
1037 case _SC_REGEX_VERSION
:
1038 #if _POSIX_REGEX_VERSION > 0
1039 return _POSIX_REGEX_VERSION
;
1045 #if _POSIX_SHELL > 0
1046 return _POSIX_SHELL
;
1052 #ifdef _POSUX_SIGNALS
1053 return _POSIX_SIGNALS
;
1059 #if _POSIX_SPAWN > 0
1060 return _POSIX_SPAWN
;
1065 case _SC_SPORADIC_SERVER
:
1066 #if _POSIX_SPORADIC_SERVER > 0
1067 return _POSIX_SPORADIC_SERVER
;
1071 case _SC_THREAD_SPORADIC_SERVER
:
1072 #if _POSIX_THREAD_SPORADIC_SERVER > 0
1073 return _POSIX_THREAD_SPORADIC_SERVER
;
1078 case _SC_SYSTEM_DATABASE
:
1079 #if _POSIX_SYSTEM_DATABASE > 0
1080 return _POSIX_SYSTEM_DATABASE
;
1084 case _SC_SYSTEM_DATABASE_R
:
1085 #if _POSIX_SYSTEM_DATABASE_R > 0
1086 return _POSIX_SYSTEM_DATABASE_R
;
1091 case _SC_THREAD_CPUTIME
:
1092 #if _POSIX_THREAD_CPUTIME > 0
1093 return _POSIX_THREAD_CPUTIME
;
1099 #if _POSIX_TIMEOUTS > 0
1100 return _POSIX_TIMEOUTS
;
1105 case _SC_TYPED_MEMORY_OBJECTS
:
1106 #if _POSIX_TYPED_MEMORY_OBJECTS > 0
1107 return _POSIX_TYPED_MEMORY_OBJECTS
;
1112 case _SC_USER_GROUPS
:
1113 #if _POSIX_USER_GROUPS > 0
1114 return _POSIX_USER_GROUPS
;
1118 case _SC_USER_GROUPS_R
:
1119 #if _POSIX_USER_GROUPS_R > 0
1120 return _POSIX_USER_GROUPS_R
;
1131 case _SC_2_PBS_ACCOUNTING
:
1132 #ifdef _POSIX2_PBS_ACCOUNTING
1133 return _POSIX2_PBS_ACCOUNTING
;
1137 case _SC_2_PBS_CHECKPOINT
:
1138 #ifdef _POSIX2_PBS_CHECKPOINT
1139 return _POSIX2_PBS_CHECKPOINT
;
1143 case _SC_2_PBS_LOCATE
:
1144 #ifdef _POSIX2_PBS_LOCATE
1145 return _POSIX2_PBS_LOCATE
;
1149 case _SC_2_PBS_MESSAGE
:
1150 #ifdef _POSIX2_PBS_MESSAGE
1151 return _POSIX2_PBS_MESSAGE
;
1155 case _SC_2_PBS_TRACK
:
1156 #ifdef _POSIX2_PBS_TRACK
1157 return _POSIX2_PBS_TRACK
;
1162 case _SC_SYMLOOP_MAX
:
1170 #ifdef _XOPEN_STREAMS
1171 return _XOPEN_STREAMS
;
1176 case _SC_HOST_NAME_MAX
:
1177 #ifdef HOST_NAME_MAX
1178 return HOST_NAME_MAX
;
1184 #if _POSIX_TRACE > 0
1185 return _POSIX_TRACE
;
1189 case _SC_TRACE_EVENT_FILTER
:
1190 #if _POSIX_TRACE_EVENT_FILTER > 0
1191 return _POSIX_TRACE_EVENT_FILTER
;
1195 case _SC_TRACE_INHERIT
:
1196 #if _POSIX_TRACE_INHERIT > 0
1197 return _POSIX_TRACE_INHERIT
;
1202 #if _POSIX_TRACE_LOG > 0
1203 return _POSIX_TRACE_LOG
;
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. */
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
1244 case _SC_RAW_SOCKETS
:
1245 #if _POSIX_RAW_SOCKETS > 0
1246 return _POSIX_RAW_SOCKETS
;
1254 weak_alias (__sysconf
, sysconf
)
1255 libc_hidden_def (__sysconf
)
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),
1273 long int ret
= __xstat64 (_STAT_VER
, name
, &st
) >= 0 ? 1 : -1;
1275 __set_errno (save_errno
);