1 /* Copyright (C) 1991,1993,1995-1997,1999-2003,2004
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 static long int __sysconf_check_spec (const char *spec
);
40 /* Get the value of the system variable NAME. */
47 /* Also add obsolete or unnecessarily added constants here. */
48 case _SC_EQUIV_CLASS_MAX
:
68 return __getclktck ();
78 return __getdtablesize ();
88 return MAX (__tzname_max (), _POSIX_TZNAME_MAX
);
91 #ifdef _POSIX_JOB_CONTROL
98 #ifdef _POSIX_SAVED_IDS
104 case _SC_REALTIME_SIGNALS
:
105 #ifdef _POSIX_REALTIME_SIGNALS
106 return _POSIX_REALTIME_SIGNALS
;
111 case _SC_PRIORITY_SCHEDULING
:
112 #ifdef _POSIX_PRIORITY_SCHEDULING
113 return _POSIX_PRIORITY_SCHEDULING
;
120 return _POSIX_TIMERS
;
125 case _SC_ASYNCHRONOUS_IO
:
126 #ifdef _POSIX_ASYNCHRONOUS_IO
127 return _POSIX_ASYNCHRONOUS_IO
;
132 case _SC_PRIORITIZED_IO
:
133 #ifdef _POSIX_PRIORITIZED_IO
134 return _POSIX_PRIORITIZED_IO
;
139 case _SC_SYNCHRONIZED_IO
:
140 #ifdef _POSIX_SYNCHRONIZED_IO
141 return _POSIX_SYNCHRONIZED_IO
;
153 case _SC_MAPPED_FILES
:
154 #ifdef _POSIX_MAPPED_FILES
155 return _POSIX_MAPPED_FILES
;
161 #ifdef _POSIX_MEMLOCK
162 return _POSIX_MEMLOCK
;
167 case _SC_MEMLOCK_RANGE
:
168 #ifdef _POSIX_MEMLOCK_RANGE
169 return _POSIX_MEMLOCK_RANGE
;
174 case _SC_MEMORY_PROTECTION
:
175 #ifdef _POSIX_MEMORY_PROTECTION
176 return _POSIX_MEMORY_PROTECTION
;
181 case _SC_MESSAGE_PASSING
:
182 #ifdef _POSIX_MESSAGE_PASSING
183 return _POSIX_MESSAGE_PASSING
;
189 #ifdef _POSIX_SEMAPHORES
190 return _POSIX_SEMAPHORES
;
195 case _SC_SHARED_MEMORY_OBJECTS
:
196 #ifdef _POSIX_SHARED_MEMORY_OBJECTS
197 return _POSIX_SHARED_MEMORY_OBJECTS
;
203 return _POSIX_VERSION
;
206 return __getpagesize ();
208 case _SC_AIO_LISTIO_MAX
:
209 #ifdef AIO_LISTIO_MAX
210 return AIO_LISTIO_MAX
;
222 case _SC_AIO_PRIO_DELTA_MAX
:
223 #ifdef AIO_PRIO_DELTA_MAX
224 return AIO_PRIO_DELTA_MAX
;
229 case _SC_DELAYTIMER_MAX
:
230 #ifdef DELAYTIMER_MAX
231 return DELAYTIMER_MAX
;
236 case _SC_MQ_OPEN_MAX
:
243 case _SC_MQ_PRIO_MAX
:
257 case _SC_SEM_NSEMS_MAX
:
259 return SEM_NSEMS_MAX
;
264 case _SC_SEM_VALUE_MAX
:
266 return SEM_VALUE_MAX
;
271 case _SC_SIGQUEUE_MAX
:
285 case _SC_BC_BASE_MAX
:
299 case _SC_BC_SCALE_MAX
:
306 case _SC_BC_STRING_MAX
:
308 return BC_STRING_MAX
;
313 case _SC_COLL_WEIGHTS_MAX
:
314 #ifdef COLL_WEIGHTS_MAX
315 return COLL_WEIGHTS_MAX
;
320 case _SC_EXPR_NEST_MAX
:
322 return EXPR_NEST_MAX
;
341 case _SC_CHARCLASS_NAME_MAX
:
342 #ifdef CHARCLASS_NAME_MAX
343 return CHARCLASS_NAME_MAX
;
356 #ifdef _POSIX_PII_XTI
363 #ifdef _POSIX_PII_SOCKET
369 case _SC_PII_INTERNET
:
370 #ifdef _POSIX_PII_INTERNET
377 #ifdef _POSIX_PII_OSI
397 /* The same as _SC_IOV_MAX. */
405 case _SC_PII_INTERNET_STREAM
:
406 #ifdef _POSIX_PII_INTERNET_STREAM
412 case _SC_PII_INTERNET_DGRAM
:
413 #ifdef _POSIX_PII_INTERNET_DGRAM
419 case _SC_PII_OSI_COTS
:
420 #ifdef _POSIX_PII_OSI_COTS
426 case _SC_PII_OSI_CLTS
:
427 #ifdef _POSIX_PII_OSI_CLTS
434 #ifdef _POSIX_PII_OSI_M
448 return _POSIX2_VERSION
;
451 #ifdef _POSIX2_C_BIND
452 return _POSIX2_C_BIND
;
459 return _POSIX2_C_DEV
;
464 case _SC_2_C_VERSION
:
465 #ifdef _POSIX2_C_VERSION
466 return _POSIX2_C_VERSION
;
472 #ifdef _POSIX2_FORT_DEV
473 return _POSIX2_FORT_DEV
;
479 #ifdef _POSIX2_FORT_RUN
480 return _POSIX2_FORT_RUN
;
485 case _SC_2_LOCALEDEF
:
486 #ifdef _POSIX2_LOCALEDEF
487 return _POSIX2_LOCALEDEF
;
493 #ifdef _POSIX2_SW_DEV
494 return _POSIX2_SW_DEV
;
499 case _SC_2_CHAR_TERM
:
500 #ifdef _POSIX2_CHAR_TERM
501 return _POSIX2_CHAR_TERM
;
513 /* POSIX 1003.1c (POSIX Threads). */
515 #ifdef _POSIX_THREADS
516 return _POSIX_THREADS
;
521 case _SC_THREAD_SAFE_FUNCTIONS
:
522 #ifdef _POSIX_THREAD_SAFE_FUNCTIONS
523 return _POSIX_THREAD_SAFE_FUNCTIONS
;
528 case _SC_GETGR_R_SIZE_MAX
:
529 return NSS_BUFLEN_GROUP
;
531 case _SC_GETPW_R_SIZE_MAX
:
532 return NSS_BUFLEN_PASSWD
;
534 case _SC_LOGIN_NAME_MAX
:
535 #ifdef LOGIN_NAME_MAX
536 return LOGIN_NAME_MAX
;
541 case _SC_TTY_NAME_MAX
:
548 case _SC_THREAD_DESTRUCTOR_ITERATIONS
:
549 #ifdef _POSIX_THREAD_DESTRUCTOR_ITERATIONS
550 return _POSIX_THREAD_DESTRUCTOR_ITERATIONS
;
555 case _SC_THREAD_KEYS_MAX
:
556 #ifdef PTHREAD_KEYS_MAX
557 return PTHREAD_KEYS_MAX
;
562 case _SC_THREAD_STACK_MIN
:
563 #ifdef PTHREAD_STACK_MIN
564 return PTHREAD_STACK_MIN
;
569 case _SC_THREAD_THREADS_MAX
:
570 #ifdef PTHREAD_THREADS_MAX
571 return PTHREAD_THREADS_MAX
;
576 case _SC_THREAD_ATTR_STACKADDR
:
577 #ifdef _POSIX_THREAD_ATTR_STACKADDR
578 return _POSIX_THREAD_ATTR_STACKADDR
;
583 case _SC_THREAD_ATTR_STACKSIZE
:
584 #ifdef _POSIX_THREAD_ATTR_STACKSIZE
585 return _POSIX_THREAD_ATTR_STACKSIZE
;
590 case _SC_THREAD_PRIORITY_SCHEDULING
:
591 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
592 return _POSIX_THREAD_PRIORITY_SCHEDULING
;
597 case _SC_THREAD_PRIO_INHERIT
:
598 #ifdef _POSIX_THREAD_PRIO_INHERIT
599 return _POSIX_THREAD_PRIO_INHERIT
;
604 case _SC_THREAD_PRIO_PROTECT
:
605 #ifdef _POSIX_THREAD_PRIO_PROTECT
606 return _POSIX_THREAD_PRIO_PROTECT
;
611 case _SC_THREAD_PROCESS_SHARED
:
612 #ifdef _POSIX_THREAD_PROCESS_SHARED
613 return _POSIX_THREAD_PROCESS_SHARED
;
618 case _SC_NPROCESSORS_CONF
:
619 return __get_nprocs_conf ();
621 case _SC_NPROCESSORS_ONLN
:
622 return __get_nprocs ();
625 return __get_phys_pages ();
627 case _SC_AVPHYS_PAGES
:
628 return __get_avphys_pages ();
631 /* We have no limit since we use lists. */
635 /* We have no limit but since the return value might be used to
636 allocate a buffer we restrict the value. */
639 case _SC_XOPEN_VERSION
:
640 return _XOPEN_VERSION
;
642 case _SC_XOPEN_XCU_VERSION
:
643 return _XOPEN_XCU_VERSION
;
648 case _SC_XOPEN_CRYPT
:
655 case _SC_XOPEN_ENH_I18N
:
656 #ifdef _XOPEN_ENH_I18N
657 return _XOPEN_ENH_I18N
;
706 return sizeof (long int) * CHAR_BIT
;
709 return sizeof (int) * CHAR_BIT
;
718 return _POSIX_SSIZE_MAX
;
786 case _SC_XBS5_ILP32_OFF32
:
787 #ifdef _XBS5_ILP32_OFF32
788 return _XBS5_ILP32_OFF32
;
790 return __sysconf_check_spec ("ILP32_OFF32");
792 case _SC_XBS5_ILP32_OFFBIG
:
793 #ifdef _XBS5_ILP32_OFFBIG
794 return _XBS5_ILP32_OFFBIG
;
796 return __sysconf_check_spec ("ILP32_OFFBIG");
798 case _SC_XBS5_LP64_OFF64
:
799 #ifdef _XBS5_LP64_OFF64
800 return _XBS5_LP64_OFF64
;
802 return __sysconf_check_spec ("LP64_OFF64");
804 case _SC_XBS5_LPBIG_OFFBIG
:
805 #ifdef _XBS5_LPBIG_OFFBIG
806 return _XBS5_LPBIG_OFFBIG
;
808 return __sysconf_check_spec ("LPBIG_OFFBIG");
811 case _SC_V6_ILP32_OFF32
:
812 #ifdef _POSIX_V6_ILP32_OFF32
813 return _POSIX_V6_ILP32_OFF32
;
815 return __sysconf_check_spec ("ILP32_OFF32");
817 case _SC_V6_ILP32_OFFBIG
:
818 #ifdef _POSIX_V6_ILP32_OFFBIG
819 return _POSIX_V6_ILP32_OFFBIG
;
821 return __sysconf_check_spec ("ILP32_OFFBIG");
823 case _SC_V6_LP64_OFF64
:
824 #ifdef _POSIX_V6_LP64_OFF64
825 return _POSIX_V6_LP64_OFF64
;
827 return __sysconf_check_spec ("LP64_OFF64");
829 case _SC_V6_LPBIG_OFFBIG
:
830 #ifdef _POSIX_V6_LPBIG_OFFBIG
831 return _POSIX_V6_LPBIG_OFFBIG
;
833 return __sysconf_check_spec ("LPBIG_OFFBIG");
836 case _SC_XOPEN_LEGACY
:
837 return _XOPEN_LEGACY
;
839 case _SC_XOPEN_REALTIME
:
840 #ifdef _XOPEN_REALTIME
841 return _XOPEN_REALTIME
;
845 case _SC_XOPEN_REALTIME_THREADS
:
846 #ifdef _XOPEN_REALTIME_THREADS
847 return _XOPEN_REALTIME_THREADS
;
852 case _SC_ADVISORY_INFO
:
853 #ifdef _POSIX_ADVISORY_INFO
854 return _POSIX_ADVISORY_INFO
;
860 #ifdef _POSIX_BARRIERS
861 return _POSIX_BARRIERS
;
872 case _SC_C_LANG_SUPPORT
:
873 #ifdef _POSIX_C_LANG_SUPPORT
874 return _POSIX_C_LANG_SUPPORT
;
878 case _SC_C_LANG_SUPPORT_R
:
879 #ifdef _POSIX_C_LANG_SUPPORT_R
880 return _POSIX_C_LANG_SUPPORT_R
;
885 case _SC_CLOCK_SELECTION
:
886 #ifdef _POSIX_CLOCK_SELECTION
887 return _POSIX_CLOCK_SELECTION
;
893 #ifdef _POSIX_CPUTIME
894 return _POSIX_CPUTIME
;
900 #ifdef _POSIX_DEVICE_IO
901 return _POSIX_DEVICE_IO
;
905 case _SC_DEVICE_SPECIFIC
:
906 #ifdef _POSIX_DEVICE_SPCIFIC
907 return _POSIX_DEVICE_SPECIFIC
;
911 case _SC_DEVICE_SPECIFIC_R
:
912 #ifdef _POSIX_DEVICE_SPCIFIC_R
913 return _POSIX_DEVICE_SPECIFIC_R
;
919 #ifdef _POSIX_FD_MGMT
920 return _POSIX_FD_MGMT
;
938 case _SC_FILE_ATTRIBUTES
:
939 #ifdef _POSIX_FILE_ATTRIBUTES
940 return _POSIX_FILE_ATTRIBUTES
;
944 case _SC_FILE_LOCKING
:
945 #ifdef _POSIX_FILE_LOCKING
946 return _POSIX_FILE_LOCKING
;
950 case _SC_FILE_SYSTEM
:
951 #ifdef _POSIX_FILE_SYSTEM
952 return _POSIX_FILE_SYSTEM
;
957 case _SC_MONOTONIC_CLOCK
:
958 #if _POSIX_MONOTONIC_CLOCK
959 return _POSIX_MONOTONIC_CLOCK
;
964 case _SC_MULTI_PROCESS
:
965 #ifdef _POSIX_MULTI_PROCESS
966 return _POSIX_MULTI_PROCESS
;
970 case _SC_SINGLE_PROCESS
:
971 #ifdef _POSIX_SINGLE_PROCESS
972 return _POSIX_SINGLE_PROCESS
;
978 #ifdef _POSIX_NETWORKING
979 return _POSIX_NETWORKING
;
984 case _SC_READER_WRITER_LOCKS
:
985 #ifdef _POSIX_READER_WRITER_LOCKS
986 return _POSIX_READER_WRITER_LOCKS
;
991 #ifdef _POSIX_SPIN_LOCKS
992 return _POSIX_SPIN_LOCKS
;
999 return _POSIX_REGEXP
;
1003 case _SC_REGEX_VERSION
:
1004 #ifdef _POSIX_REGEX_VERSION
1005 return _POSIX_REGEX_VERSION
;
1012 return _POSIX_SHELL
;
1018 #ifdef _POSUX_SIGNALS
1019 return _POSIX_SIGNALS
;
1026 return _POSIX_SPAWN
;
1031 case _SC_SPORADIC_SERVER
:
1032 #ifdef _POSIX_SPORADIC_SERVER
1033 return _POSIX_SPORADIC_SERVER
;
1037 case _SC_THREAD_SPORADIC_SERVER
:
1038 #ifdef _POSIX_THREAD_SPORADIC_SERVER
1039 return _POSIX_THREAD_SPORADIC_SERVER
;
1044 case _SC_SYSTEM_DATABASE
:
1045 #ifdef _POSIX_SYSTEM_DATABASE
1046 return _POSIX_SYSTEM_DATABASE
;
1050 case _SC_SYSTEM_DATABASE_R
:
1051 #ifdef _POSIX_SYSTEM_DATABASE_R
1052 return _POSIX_SYSTEM_DATABASE_R
;
1057 case _SC_THREAD_CPUTIME
:
1058 #ifdef _POSIX_THREAD_CPUTIME
1059 return _POSIX_THREAD_CPUTIME
;
1065 #ifdef _POSIX_TIMEOUTS
1066 return _POSIX_TIMEOUTS
;
1071 case _SC_TYPED_MEMORY_OBJECTS
:
1072 #ifdef _POSIX_TYPED_MEMORY_OBJECTS
1073 return _POSIX_TYPED_MEMORY_OBJECTS
;
1078 case _SC_USER_GROUPS
:
1079 #ifdef _POSIX_USER_GROUPS
1080 return _POSIX_USER_GROUPS
;
1084 case _SC_USER_GROUPS_R
:
1085 #ifdef _POSIX_USER_GROUPS_R
1086 return _POSIX_USER_GROUPS_R
;
1097 case _SC_2_PBS_ACCOUNTING
:
1098 #ifdef _POSIX2_PBS_ACCOUNTING
1099 return _POSIX2_PBS_ACCOUNTING
;
1103 case _SC_2_PBS_CHECKPOINT
:
1104 #ifdef _POSIX2_PBS_CHECKPOINT
1105 return _POSIX2_PBS_CHECKPOINT
;
1109 case _SC_2_PBS_LOCATE
:
1110 #ifdef _POSIX2_PBS_LOCATE
1111 return _POSIX2_PBS_LOCATE
;
1115 case _SC_2_PBS_MESSAGE
:
1116 #ifdef _POSIX2_PBS_MESSAGE
1117 return _POSIX2_PBS_MESSAGE
;
1121 case _SC_2_PBS_TRACK
:
1122 #ifdef _POSIX2_PBS_TRACK
1123 return _POSIX2_PBS_TRACK
;
1128 case _SC_SYMLOOP_MAX
:
1136 #ifdef _XOPEN_STREAMS
1137 return _XOPEN_STREAMS
;
1142 case _SC_HOST_NAME_MAX
:
1143 #ifdef HOST_NAME_MAX
1144 return HOST_NAME_MAX
;
1151 return _POSIX_TRACE
;
1155 case _SC_TRACE_EVENT_FILTER
:
1156 #ifdef _POSIX_TRACE_EVENT_FILTER
1157 return _POSIX_TRACE_EVENT_FILTER
;
1161 case _SC_TRACE_INHERIT
:
1162 #ifdef _POSIX_TRACE_INHERIT
1163 return _POSIX_TRACE_INHERIT
;
1168 #ifdef _POSIX_TRACE_LOG
1169 return _POSIX_TRACE_LOG
;
1174 case _SC_LEVEL1_ICACHE_SIZE
:
1175 case _SC_LEVEL1_ICACHE_ASSOC
:
1176 case _SC_LEVEL1_ICACHE_LINESIZE
:
1177 case _SC_LEVEL1_DCACHE_SIZE
:
1178 case _SC_LEVEL1_DCACHE_ASSOC
:
1179 case _SC_LEVEL1_DCACHE_LINESIZE
:
1180 case _SC_LEVEL2_CACHE_SIZE
:
1181 case _SC_LEVEL2_CACHE_ASSOC
:
1182 case _SC_LEVEL2_CACHE_LINESIZE
:
1183 case _SC_LEVEL3_CACHE_SIZE
:
1184 case _SC_LEVEL3_CACHE_ASSOC
:
1185 case _SC_LEVEL3_CACHE_LINESIZE
:
1186 case _SC_LEVEL4_CACHE_SIZE
:
1187 case _SC_LEVEL4_CACHE_ASSOC
:
1188 /* In general we cannot determine these values. Therefore we
1189 return zero which indicates that no information is
1196 weak_alias (__sysconf
, sysconf
)
1197 libc_hidden_def (__sysconf
)
1200 __sysconf_check_spec (const char *spec
)
1202 int save_errno
= errno
;
1204 const char *getconf_dir
= __secure_getenv ("GETCONF_DIR") ?: GETCONF_DIR
;
1205 size_t getconf_dirlen
= strlen (getconf_dir
);
1206 size_t speclen
= strlen (spec
);
1208 char name
[getconf_dirlen
+ sizeof ("/_POSIX_V6_") + speclen
];
1209 memcpy (mempcpy (mempcpy (name
, getconf_dir
, getconf_dirlen
),
1210 "/_POSIX_V6_", sizeof ("/_POSIX_V6_") - 1),
1214 long int ret
= __xstat64 (_STAT_VER
, name
, &st
) >= 0 ? 1 : -1;
1216 __set_errno (save_errno
);