Back to index

glibc  2.9
sysconf.c
Go to the documentation of this file.
00001 /* Copyright (C) 1991,1993,1995-1997,1999-2003,2004,2006
00002        Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <errno.h>
00021 #include <limits.h>
00022 #include <grp.h>
00023 #include <pwd.h>
00024 #include <stddef.h>
00025 #include <stdio.h>
00026 #include <stdlib.h>
00027 #include <string.h>
00028 #include <time.h>
00029 #include <unistd.h>
00030 #include <sys/param.h>
00031 #include <sys/stat.h>
00032 #include <sys/sysinfo.h>
00033 #include <sys/types.h>
00034 #include <regex.h>
00035 
00036 
00037 #define NEED_CHECK_SPEC \
00038   (!defined _XBS5_ILP32_OFF32 || !defined _XBS5_ILP32_OFFBIG \
00039    || !defined _XBS5_LP64_OFF64 || !defined _XBS5_LPBIG_OFFBIG \
00040    || !defined _POSIX_V6_ILP32_OFF32 || !defined _POSIX_V6_ILP32_OFFBIG \
00041    || !defined _POSIX_V6_LP64_OFF64 || !defined _POSIX_V6_LPBIG_OFFBIG)
00042 #if NEED_CHECK_SPEC
00043 static long int __sysconf_check_spec (const char *spec);
00044 #endif
00045 
00046 
00047 /* Get the value of the system variable NAME.  */
00048 long int
00049 __sysconf (name)
00050      int name;
00051 {
00052   switch (name)
00053     {
00054       /* Also add obsolete or unnecessarily added constants here.  */
00055     case _SC_EQUIV_CLASS_MAX:
00056     default:
00057       __set_errno (EINVAL);
00058       return -1;
00059 
00060     case _SC_ARG_MAX:
00061 #ifdef ARG_MAX
00062       return ARG_MAX;
00063 #else
00064       return -1;
00065 #endif
00066 
00067     case _SC_CHILD_MAX:
00068 #ifdef CHILD_MAX
00069       return CHILD_MAX;
00070 #else
00071       return __get_child_max ();
00072 #endif
00073 
00074     case _SC_CLK_TCK:
00075       return __getclktck ();
00076 
00077     case _SC_NGROUPS_MAX:
00078 #ifdef NGROUPS_MAX
00079       return NGROUPS_MAX;
00080 #else
00081       return -1;
00082 #endif
00083 
00084     case _SC_OPEN_MAX:
00085       return __getdtablesize ();
00086 
00087     case _SC_STREAM_MAX:
00088 #ifdef STREAM_MAX
00089       return STREAM_MAX;
00090 #else
00091       return FOPEN_MAX;
00092 #endif
00093 
00094     case _SC_TZNAME_MAX:
00095       return MAX (__tzname_max (), _POSIX_TZNAME_MAX);
00096 
00097     case _SC_JOB_CONTROL:
00098 #if _POSIX_JOB_CONTROL > 0
00099       return _POSIX_JOB_CONTROL;
00100 #else
00101       return -1;
00102 #endif
00103 
00104     case _SC_SAVED_IDS:
00105 #if _POSIX_SAVED_IDS > 0
00106       return 1;
00107 #else
00108       return -1;
00109 #endif
00110 
00111     case _SC_REALTIME_SIGNALS:
00112 #if _POSIX_REALTIME_SIGNALS > 0
00113       return _POSIX_REALTIME_SIGNALS;
00114 #else
00115       return -1;
00116 #endif
00117 
00118     case _SC_PRIORITY_SCHEDULING:
00119 #if _POSIX_PRIORITY_SCHEDULING > 0
00120       return _POSIX_PRIORITY_SCHEDULING;
00121 #else
00122       return -1;
00123 #endif
00124 
00125     case _SC_TIMERS:
00126 #if _POSIX_TIMERS > 0
00127       return _POSIX_TIMERS;
00128 #else
00129       return -1;
00130 #endif
00131 
00132     case _SC_ASYNCHRONOUS_IO:
00133 #if _POSIX_ASYNCHRONOUS_IO > 0
00134       return _POSIX_ASYNCHRONOUS_IO;
00135 #else
00136       return -1;
00137 #endif
00138 
00139     case _SC_PRIORITIZED_IO:
00140 #if _POSIX_PRIORITIZED_IO > 0
00141       return _POSIX_PRIORITIZED_IO;
00142 #else
00143       return -1;
00144 #endif
00145 
00146     case _SC_SYNCHRONIZED_IO:
00147 #if _POSIX_SYNCHRONIZED_IO > 0
00148       return _POSIX_SYNCHRONIZED_IO;
00149 #else
00150       return -1;
00151 #endif
00152 
00153     case _SC_FSYNC:
00154 #if _POSIX_FSYNC > 0
00155       return _POSIX_FSYNC;
00156 #else
00157       return -1;
00158 #endif
00159 
00160     case _SC_MAPPED_FILES:
00161 #if _POSIX_MAPPED_FILES > 0
00162       return _POSIX_MAPPED_FILES;
00163 #else
00164       return -1;
00165 #endif
00166 
00167     case _SC_MEMLOCK:
00168 #if _POSIX_MEMLOCK > 0
00169       return _POSIX_MEMLOCK;
00170 #else
00171       return -1;
00172 #endif
00173 
00174     case _SC_MEMLOCK_RANGE:
00175 #if _POSIX_MEMLOCK_RANGE > 0
00176       return _POSIX_MEMLOCK_RANGE;
00177 #else
00178       return -1;
00179 #endif
00180 
00181     case _SC_MEMORY_PROTECTION:
00182 #if _POSIX_MEMORY_PROTECTION > 0
00183       return _POSIX_MEMORY_PROTECTION;
00184 #else
00185       return -1;
00186 #endif
00187 
00188     case _SC_MESSAGE_PASSING:
00189 #if _POSIX_MESSAGE_PASSING > 0
00190       return _POSIX_MESSAGE_PASSING;
00191 #else
00192       return -1;
00193 #endif
00194 
00195     case _SC_SEMAPHORES:
00196 #if _POSIX_SEMAPHORES > 0
00197       return _POSIX_SEMAPHORES;
00198 #else
00199       return -1;
00200 #endif
00201 
00202     case _SC_SHARED_MEMORY_OBJECTS:
00203 #if _POSIX_SHARED_MEMORY_OBJECTS > 0
00204       return _POSIX_SHARED_MEMORY_OBJECTS;
00205 #else
00206       return -1;
00207 #endif
00208 
00209     case _SC_VERSION:
00210       return _POSIX_VERSION;
00211 
00212     case _SC_PAGESIZE:
00213       return __getpagesize ();
00214 
00215     case _SC_AIO_LISTIO_MAX:
00216 #ifdef AIO_LISTIO_MAX
00217       return AIO_LISTIO_MAX;
00218 #else
00219       return -1;
00220 #endif
00221 
00222     case _SC_AIO_MAX:
00223 #ifdef AIO_MAX
00224       return AIO_MAX;
00225 #else
00226       return -1;
00227 #endif
00228 
00229     case _SC_AIO_PRIO_DELTA_MAX:
00230 #ifdef AIO_PRIO_DELTA_MAX
00231       return AIO_PRIO_DELTA_MAX;
00232 #else
00233       return -1;
00234 #endif
00235 
00236     case _SC_DELAYTIMER_MAX:
00237 #ifdef DELAYTIMER_MAX
00238       return DELAYTIMER_MAX;
00239 #else
00240       return -1;
00241 #endif
00242 
00243     case _SC_MQ_OPEN_MAX:
00244 #ifdef MQ_OPEN_MAX
00245       return MQ_OPEN_MAX;
00246 #else
00247       return -1;
00248 #endif
00249 
00250     case _SC_MQ_PRIO_MAX:
00251 #ifdef MQ_PRIO_MAX
00252       return MQ_PRIO_MAX;
00253 #else
00254       return -1;
00255 #endif
00256 
00257     case _SC_RTSIG_MAX:
00258 #ifdef RTSIG_MAX
00259       return RTSIG_MAX;
00260 #else
00261       return -1;
00262 #endif
00263 
00264     case _SC_SEM_NSEMS_MAX:
00265 #ifdef SEM_NSEMS_MAX
00266       return SEM_NSEMS_MAX;
00267 #else
00268       return -1;
00269 #endif
00270 
00271     case _SC_SEM_VALUE_MAX:
00272 #ifdef SEM_VALUE_MAX
00273       return SEM_VALUE_MAX;
00274 #else
00275       return -1;
00276 #endif
00277 
00278     case _SC_SIGQUEUE_MAX:
00279 #ifdef SIGQUEUE_MAX
00280       return SIGQUEUE_MAX;
00281 #else
00282       return -1;
00283 #endif
00284 
00285     case _SC_TIMER_MAX:
00286 #ifdef TIMER_MAX
00287       return TIMER_MAX;
00288 #else
00289       return -1;
00290 #endif
00291 
00292     case _SC_BC_BASE_MAX:
00293 #ifdef BC_BASE_MAX
00294       return BC_BASE_MAX;
00295 #else
00296       return -1;
00297 #endif
00298 
00299     case _SC_BC_DIM_MAX:
00300 #ifdef BC_DIM_MAX
00301       return BC_DIM_MAX;
00302 #else
00303       return -1;
00304 #endif
00305 
00306     case _SC_BC_SCALE_MAX:
00307 #ifdef BC_SCALE_MAX
00308       return BC_SCALE_MAX;
00309 #else
00310       return -1;
00311 #endif
00312 
00313     case _SC_BC_STRING_MAX:
00314 #ifdef BC_STRING_MAX
00315       return BC_STRING_MAX;
00316 #else
00317       return -1;
00318 #endif
00319 
00320     case _SC_COLL_WEIGHTS_MAX:
00321 #ifdef COLL_WEIGHTS_MAX
00322       return COLL_WEIGHTS_MAX;
00323 #else
00324       return -1;
00325 #endif
00326 
00327     case _SC_EXPR_NEST_MAX:
00328 #ifdef EXPR_NEST_MAX
00329       return EXPR_NEST_MAX;
00330 #else
00331       return -1;
00332 #endif
00333 
00334     case _SC_LINE_MAX:
00335 #ifdef LINE_MAX
00336       return LINE_MAX;
00337 #else
00338       return -1;
00339 #endif
00340 
00341     case _SC_RE_DUP_MAX:
00342 #ifdef RE_DUP_MAX
00343       return RE_DUP_MAX;
00344 #else
00345       return -1;
00346 #endif
00347 
00348     case _SC_CHARCLASS_NAME_MAX:
00349 #ifdef CHARCLASS_NAME_MAX
00350       return CHARCLASS_NAME_MAX;
00351 #else
00352       return -1;
00353 #endif
00354 
00355     case _SC_PII:
00356 #if _POSIX_PII > 0
00357       return 1;
00358 #else
00359       return -1;
00360 #endif
00361 
00362     case _SC_PII_XTI:
00363 #if _POSIX_PII_XTI > 0
00364       return 1;
00365 #else
00366       return -1;
00367 #endif
00368 
00369     case _SC_PII_SOCKET:
00370 #if _POSIX_PII_SOCKET > 0
00371       return 1;
00372 #else
00373       return -1;
00374 #endif
00375 
00376     case _SC_PII_INTERNET:
00377 #if _POSIX_PII_INTERNET > 0
00378       return 1;
00379 #else
00380       return -1;
00381 #endif
00382 
00383     case _SC_PII_OSI:
00384 #if _POSIX_PII_OSI > 0
00385       return 1;
00386 #else
00387       return -1;
00388 #endif
00389 
00390     case _SC_POLL:
00391 #if _POSIX_POLL > 0
00392       return 1;
00393 #else
00394       return -1;
00395 #endif
00396 
00397     case _SC_SELECT:
00398 #if _POSIX_SELECT > 0
00399       return 1;
00400 #else
00401       return -1;
00402 #endif
00403 
00404       /* The same as _SC_IOV_MAX.  */
00405     case _SC_UIO_MAXIOV:
00406 #ifdef UIO_MAXIOV
00407       return UIO_MAXIOV;
00408 #else
00409       return -1;
00410 #endif
00411 
00412     case _SC_PII_INTERNET_STREAM:
00413 #if _POSIX_PII_INTERNET_STREAM > 0
00414       return 1;
00415 #else
00416       return -1;
00417 #endif
00418 
00419     case _SC_PII_INTERNET_DGRAM:
00420 #if _POSIX_PII_INTERNET_DGRAM > 0
00421       return 1;
00422 #else
00423       return -1;
00424 #endif
00425 
00426     case _SC_PII_OSI_COTS:
00427 #if _POSIX_PII_OSI_COTS > 0
00428       return 1;
00429 #else
00430       return -1;
00431 #endif
00432 
00433     case _SC_PII_OSI_CLTS:
00434 #if _POSIX_PII_OSI_CLTS > 0
00435       return 1;
00436 #else
00437       return -1;
00438 #endif
00439 
00440     case _SC_PII_OSI_M:
00441 #if _POSIX_PII_OSI_M > 0
00442       return 1;
00443 #else
00444       return -1;
00445 #endif
00446 
00447     case _SC_T_IOV_MAX:
00448 #ifdef _T_IOV_MAX
00449       return _T_IOV_MAX;
00450 #else
00451       return -1;
00452 #endif
00453 
00454     case _SC_2_VERSION:
00455       return _POSIX2_VERSION;
00456 
00457     case _SC_2_C_BIND:
00458 #ifdef _POSIX2_C_BIND
00459       return _POSIX2_C_BIND;
00460 #else
00461       return -1;
00462 #endif
00463 
00464     case _SC_2_C_DEV:
00465 #ifdef _POSIX2_C_DEV
00466       return _POSIX2_C_DEV;
00467 #else
00468       return -1;
00469 #endif
00470 
00471     case _SC_2_C_VERSION:
00472 #ifdef _POSIX2_C_VERSION
00473       return _POSIX2_C_VERSION;
00474 #else
00475       return -1;
00476 #endif
00477 
00478     case _SC_2_FORT_DEV:
00479 #ifdef _POSIX2_FORT_DEV
00480       return _POSIX2_FORT_DEV;
00481 #else
00482       return -1;
00483 #endif
00484 
00485     case _SC_2_FORT_RUN:
00486 #ifdef _POSIX2_FORT_RUN
00487       return _POSIX2_FORT_RUN;
00488 #else
00489       return -1;
00490 #endif
00491 
00492     case _SC_2_LOCALEDEF:
00493 #ifdef _POSIX2_LOCALEDEF
00494       return _POSIX2_LOCALEDEF;
00495 #else
00496       return -1;
00497 #endif
00498 
00499     case _SC_2_SW_DEV:
00500 #ifdef _POSIX2_SW_DEV
00501       return _POSIX2_SW_DEV;
00502 #else
00503       return -1;
00504 #endif
00505 
00506     case _SC_2_CHAR_TERM:
00507 #ifdef _POSIX2_CHAR_TERM
00508       return _POSIX2_CHAR_TERM;
00509 #else
00510       return -1;
00511 #endif
00512 
00513     case _SC_2_UPE:
00514 #ifdef _POSIX2_UPE
00515       return _POSIX2_UPE;
00516 #else
00517       return -1;
00518 #endif
00519 
00520       /* POSIX 1003.1c (POSIX Threads).  */
00521     case _SC_THREADS:
00522 #if _POSIX_THREADS > 0
00523       return _POSIX_THREADS;
00524 #else
00525       return -1;
00526 #endif
00527 
00528     case _SC_THREAD_SAFE_FUNCTIONS:
00529 #if _POSIX_THREAD_SAFE_FUNCTIONS > 0
00530       return _POSIX_THREAD_SAFE_FUNCTIONS;
00531 #else
00532       return -1;
00533 #endif
00534 
00535     case _SC_GETGR_R_SIZE_MAX:
00536       return NSS_BUFLEN_GROUP;
00537 
00538     case _SC_GETPW_R_SIZE_MAX:
00539       return NSS_BUFLEN_PASSWD;
00540 
00541     case _SC_LOGIN_NAME_MAX:
00542 #ifdef LOGIN_NAME_MAX
00543       return LOGIN_NAME_MAX;
00544 #else
00545       return -1;
00546 #endif
00547 
00548     case _SC_TTY_NAME_MAX:
00549 #ifdef TTY_NAME_MAX
00550       return TTY_NAME_MAX;
00551 #else
00552       return -1;
00553 #endif
00554 
00555     case _SC_THREAD_DESTRUCTOR_ITERATIONS:
00556 #if _POSIX_THREAD_DESTRUCTOR_ITERATIONS > 0
00557       return _POSIX_THREAD_DESTRUCTOR_ITERATIONS;
00558 #else
00559       return -1;
00560 #endif
00561 
00562     case _SC_THREAD_KEYS_MAX:
00563 #ifdef PTHREAD_KEYS_MAX
00564       return PTHREAD_KEYS_MAX;
00565 #else
00566       return -1;
00567 #endif
00568 
00569     case _SC_THREAD_STACK_MIN:
00570 #ifdef PTHREAD_STACK_MIN
00571       return PTHREAD_STACK_MIN;
00572 #else
00573       return -1;
00574 #endif
00575 
00576     case _SC_THREAD_THREADS_MAX:
00577 #ifdef PTHREAD_THREADS_MAX
00578       return PTHREAD_THREADS_MAX;
00579 #else
00580       return -1;
00581 #endif
00582 
00583     case _SC_THREAD_ATTR_STACKADDR:
00584 #if _POSIX_THREAD_ATTR_STACKADDR > 0
00585       return _POSIX_THREAD_ATTR_STACKADDR;
00586 #else
00587       return -1;
00588 #endif
00589 
00590     case _SC_THREAD_ATTR_STACKSIZE:
00591 #if _POSIX_THREAD_ATTR_STACKSIZE > 0
00592       return _POSIX_THREAD_ATTR_STACKSIZE;
00593 #else
00594       return -1;
00595 #endif
00596 
00597     case _SC_THREAD_PRIORITY_SCHEDULING:
00598 #if _POSIX_THREAD_PRIORITY_SCHEDULING > 0
00599       return _POSIX_THREAD_PRIORITY_SCHEDULING;
00600 #else
00601       return -1;
00602 #endif
00603 
00604     case _SC_THREAD_PRIO_INHERIT:
00605 #if _POSIX_THREAD_PRIO_INHERIT > 0
00606       return _POSIX_THREAD_PRIO_INHERIT;
00607 #else
00608       return -1;
00609 #endif
00610 
00611     case _SC_THREAD_PRIO_PROTECT:
00612 #if _POSIX_THREAD_PRIO_PROTECT > 0
00613       return _POSIX_THREAD_PRIO_PROTECT;
00614 #else
00615       return -1;
00616 #endif
00617 
00618     case _SC_THREAD_PROCESS_SHARED:
00619 #if _POSIX_THREAD_PROCESS_SHARED > 0
00620       return _POSIX_THREAD_PROCESS_SHARED;
00621 #else
00622       return -1;
00623 #endif
00624 
00625     case _SC_NPROCESSORS_CONF:
00626       return __get_nprocs_conf ();
00627 
00628     case _SC_NPROCESSORS_ONLN:
00629       return __get_nprocs ();
00630 
00631     case _SC_PHYS_PAGES:
00632       return __get_phys_pages ();
00633 
00634     case _SC_AVPHYS_PAGES:
00635       return __get_avphys_pages ();
00636 
00637     case _SC_ATEXIT_MAX:
00638       /* We have no limit since we use lists.  */
00639       return INT_MAX;
00640 
00641     case _SC_PASS_MAX:
00642       /* We have no limit but since the return value might be used to
00643         allocate a buffer we restrict the value.  */
00644       return BUFSIZ;
00645 
00646     case _SC_XOPEN_VERSION:
00647       return _XOPEN_VERSION;
00648 
00649     case _SC_XOPEN_XCU_VERSION:
00650       return _XOPEN_XCU_VERSION;
00651 
00652     case _SC_XOPEN_UNIX:
00653       return _XOPEN_UNIX;
00654 
00655     case _SC_XOPEN_CRYPT:
00656 #ifdef _XOPEN_CRYPT
00657       return _XOPEN_CRYPT;
00658 #else
00659       return -1;
00660 #endif
00661 
00662     case _SC_XOPEN_ENH_I18N:
00663 #ifdef _XOPEN_ENH_I18N
00664       return _XOPEN_ENH_I18N;
00665 #else
00666       return -1;
00667 #endif
00668 
00669     case _SC_XOPEN_SHM:
00670 #ifdef _XOPEN_SHM
00671       return _XOPEN_SHM;
00672 #else
00673       return -1;
00674 #endif
00675 
00676     case _SC_XOPEN_XPG2:
00677 #ifdef _XOPEN_XPG2
00678       return _XOPEN_XPG2;
00679 #else
00680       return -1;
00681 #endif
00682 
00683     case _SC_XOPEN_XPG3:
00684 #ifdef _XOPEN_XPG3
00685       return _XOPEN_XPG3;
00686 #else
00687       return -1;
00688 #endif
00689 
00690     case _SC_XOPEN_XPG4:
00691 #ifdef _XOPEN_XPG4
00692       return _XOPEN_XPG4;
00693 #else
00694       return -1;
00695 #endif
00696 
00697     case _SC_CHAR_BIT:
00698       return CHAR_BIT;
00699 
00700     case _SC_CHAR_MAX:
00701       return CHAR_MAX;
00702 
00703     case _SC_CHAR_MIN:
00704       return CHAR_MIN;
00705 
00706     case _SC_INT_MAX:
00707       return INT_MAX;
00708 
00709     case _SC_INT_MIN:
00710       return INT_MIN;
00711 
00712     case _SC_LONG_BIT:
00713       return sizeof (long int) * CHAR_BIT;
00714 
00715     case _SC_WORD_BIT:
00716       return sizeof (int) * CHAR_BIT;
00717 
00718     case _SC_MB_LEN_MAX:
00719       return MB_LEN_MAX;
00720 
00721     case _SC_NZERO:
00722       return NZERO;
00723 
00724     case _SC_SSIZE_MAX:
00725       return _POSIX_SSIZE_MAX;
00726 
00727     case _SC_SCHAR_MAX:
00728       return SCHAR_MAX;
00729 
00730     case _SC_SCHAR_MIN:
00731       return SCHAR_MIN;
00732 
00733     case _SC_SHRT_MAX:
00734       return SHRT_MAX;
00735 
00736     case _SC_SHRT_MIN:
00737       return SHRT_MIN;
00738 
00739     case _SC_UCHAR_MAX:
00740       return UCHAR_MAX;
00741 
00742     case _SC_UINT_MAX:
00743       return UINT_MAX;
00744 
00745     case _SC_ULONG_MAX:
00746       return ULONG_MAX;
00747 
00748     case _SC_USHRT_MAX:
00749       return USHRT_MAX;
00750 
00751     case _SC_NL_ARGMAX:
00752 #ifdef NL_ARGMAX
00753       return NL_ARGMAX;
00754 #else
00755       return -1;
00756 #endif
00757 
00758     case _SC_NL_LANGMAX:
00759 #ifdef NL_LANGMAX
00760       return NL_LANGMAX;
00761 #else
00762       return -1;
00763 #endif
00764 
00765     case _SC_NL_MSGMAX:
00766 #ifdef NL_MSGMAX
00767       return NL_MSGMAX;
00768 #else
00769       return -1;
00770 #endif
00771 
00772     case _SC_NL_NMAX:
00773 #ifdef NL_NMAX
00774       return NL_NMAX;
00775 #else
00776       return -1;
00777 #endif
00778 
00779     case _SC_NL_SETMAX:
00780 #ifdef NL_SETMAX
00781       return NL_SETMAX;
00782 #else
00783       return -1;
00784 #endif
00785 
00786     case _SC_NL_TEXTMAX:
00787 #ifdef NL_TEXTMAX
00788       return NL_TEXTMAX;
00789 #else
00790       return -1;
00791 #endif
00792 
00793     case _SC_XBS5_ILP32_OFF32:
00794 #ifdef _XBS5_ILP32_OFF32
00795       return _XBS5_ILP32_OFF32;
00796 #else
00797       return __sysconf_check_spec ("ILP32_OFF32");
00798 #endif
00799     case _SC_XBS5_ILP32_OFFBIG:
00800 #ifdef _XBS5_ILP32_OFFBIG
00801       return _XBS5_ILP32_OFFBIG;
00802 #else
00803       return __sysconf_check_spec ("ILP32_OFFBIG");
00804 #endif
00805     case _SC_XBS5_LP64_OFF64:
00806 #ifdef _XBS5_LP64_OFF64
00807       return _XBS5_LP64_OFF64;
00808 #else
00809       return __sysconf_check_spec ("LP64_OFF64");
00810 #endif
00811     case _SC_XBS5_LPBIG_OFFBIG:
00812 #ifdef _XBS5_LPBIG_OFFBIG
00813       return _XBS5_LPBIG_OFFBIG;
00814 #else
00815       return __sysconf_check_spec ("LPBIG_OFFBIG");
00816 #endif
00817 
00818     case _SC_V6_ILP32_OFF32:
00819 #ifdef _POSIX_V6_ILP32_OFF32
00820       return _POSIX_V6_ILP32_OFF32;
00821 #else
00822       return __sysconf_check_spec ("ILP32_OFF32");
00823 #endif
00824     case _SC_V6_ILP32_OFFBIG:
00825 #ifdef _POSIX_V6_ILP32_OFFBIG
00826       return _POSIX_V6_ILP32_OFFBIG;
00827 #else
00828       return __sysconf_check_spec ("ILP32_OFFBIG");
00829 #endif
00830     case _SC_V6_LP64_OFF64:
00831 #ifdef _POSIX_V6_LP64_OFF64
00832       return _POSIX_V6_LP64_OFF64;
00833 #else
00834       return __sysconf_check_spec ("LP64_OFF64");
00835 #endif
00836     case _SC_V6_LPBIG_OFFBIG:
00837 #ifdef _POSIX_V6_LPBIG_OFFBIG
00838       return _POSIX_V6_LPBIG_OFFBIG;
00839 #else
00840       return __sysconf_check_spec ("LPBIG_OFFBIG");
00841 #endif
00842 
00843     case _SC_XOPEN_LEGACY:
00844       return _XOPEN_LEGACY;
00845 
00846     case _SC_XOPEN_REALTIME:
00847 #ifdef _XOPEN_REALTIME
00848       return _XOPEN_REALTIME;
00849 #else
00850       return -1;
00851 #endif
00852     case _SC_XOPEN_REALTIME_THREADS:
00853 #ifdef _XOPEN_REALTIME_THREADS
00854       return _XOPEN_REALTIME_THREADS;
00855 #else
00856       return -1;
00857 #endif
00858 
00859     case _SC_ADVISORY_INFO:
00860 #if _POSIX_ADVISORY_INFO > 0
00861       return _POSIX_ADVISORY_INFO;
00862 #else
00863       return -1;
00864 #endif
00865 
00866     case _SC_BARRIERS:
00867 #if _POSIX_BARRIERS > 0
00868       return _POSIX_BARRIERS;
00869 #else
00870       return -1;
00871 #endif
00872 
00873     case _SC_BASE:
00874 #if _POSIX_BASE > 0
00875       return _POSIX_BASE;
00876 #else
00877       return -1;
00878 #endif
00879     case _SC_C_LANG_SUPPORT:
00880 #if _POSIX_C_LANG_SUPPORT > 0
00881       return _POSIX_C_LANG_SUPPORT;
00882 #else
00883       return -1;
00884 #endif
00885     case _SC_C_LANG_SUPPORT_R:
00886 #if _POSIX_C_LANG_SUPPORT_R > 0
00887       return _POSIX_C_LANG_SUPPORT_R;
00888 #else
00889       return -1;
00890 #endif
00891 
00892     case _SC_CLOCK_SELECTION:
00893 #if _POSIX_CLOCK_SELECTION > 0
00894       return _POSIX_CLOCK_SELECTION;
00895 #else
00896       return -1;
00897 #endif
00898 
00899     case _SC_CPUTIME:
00900 #if _POSIX_CPUTIME > 0
00901       return _POSIX_CPUTIME;
00902 #else
00903       return -1;
00904 #endif
00905 
00906     case _SC_DEVICE_IO:
00907 #if _POSIX_DEVICE_IO > 0
00908       return _POSIX_DEVICE_IO;
00909 #else
00910       return -1;
00911 #endif
00912     case _SC_DEVICE_SPECIFIC:
00913 #if _POSIX_DEVICE_SPCIFIC > 0
00914       return _POSIX_DEVICE_SPECIFIC;
00915 #else
00916       return -1;
00917 #endif
00918     case _SC_DEVICE_SPECIFIC_R:
00919 #if _POSIX_DEVICE_SPCIFIC_R > 0
00920       return _POSIX_DEVICE_SPECIFIC_R;
00921 #else
00922       return -1;
00923 #endif
00924 
00925     case _SC_FD_MGMT:
00926 #if _POSIX_FD_MGMT > 0
00927       return _POSIX_FD_MGMT;
00928 #else
00929       return -1;
00930 #endif
00931 
00932     case _SC_FIFO:
00933 #if _POSIX_FIFO > 0
00934       return _POSIX_FIFO;
00935 #else
00936       return -1;
00937 #endif
00938     case _SC_PIPE:
00939 #if _POSIX_PIPE > 0
00940       return _POSIX_PIPE;
00941 #else
00942       return -1;
00943 #endif
00944 
00945     case _SC_FILE_ATTRIBUTES:
00946 #if _POSIX_FILE_ATTRIBUTES > 0
00947       return _POSIX_FILE_ATTRIBUTES;
00948 #else
00949       return -1;
00950 #endif
00951     case _SC_FILE_LOCKING:
00952 #if _POSIX_FILE_LOCKING > 0
00953       return _POSIX_FILE_LOCKING;
00954 #else
00955       return -1;
00956 #endif
00957     case _SC_FILE_SYSTEM:
00958 #if _POSIX_FILE_SYSTEM > 0
00959       return _POSIX_FILE_SYSTEM;
00960 #else
00961       return -1;
00962 #endif
00963 
00964     case _SC_MONOTONIC_CLOCK:
00965 #if _POSIX_MONOTONIC_CLOCK
00966       return _POSIX_MONOTONIC_CLOCK;
00967 #else
00968       return -1;
00969 #endif
00970 
00971     case _SC_MULTI_PROCESS:
00972 #if _POSIX_MULTI_PROCESS > 0
00973       return _POSIX_MULTI_PROCESS;
00974 #else
00975       return -1;
00976 #endif
00977     case _SC_SINGLE_PROCESS:
00978 #if _POSIX_SINGLE_PROCESS > 0
00979       return _POSIX_SINGLE_PROCESS;
00980 #else
00981       return -1;
00982 #endif
00983 
00984     case _SC_NETWORKING:
00985 #if _POSIX_NETWORKING > 0
00986       return _POSIX_NETWORKING;
00987 #else
00988       return -1;
00989 #endif
00990 
00991     case _SC_READER_WRITER_LOCKS:
00992 #if _POSIX_READER_WRITER_LOCKS > 0
00993       return _POSIX_READER_WRITER_LOCKS;
00994 #else
00995       return -1;
00996 #endif
00997     case _SC_SPIN_LOCKS:
00998 #if _POSIX_SPIN_LOCKS > 0
00999       return _POSIX_SPIN_LOCKS;
01000 #else
01001       return -1;
01002 #endif
01003 
01004     case _SC_REGEXP:
01005 #if _POSIX_REGEXP > 0
01006       return _POSIX_REGEXP;
01007 #else
01008       return -1;
01009 #endif
01010     case _SC_REGEX_VERSION:
01011 #if _POSIX_REGEX_VERSION > 0
01012       return _POSIX_REGEX_VERSION;
01013 #else
01014       return -1;
01015 #endif
01016 
01017     case _SC_SHELL:
01018 #if _POSIX_SHELL > 0
01019       return _POSIX_SHELL;
01020 #else
01021       return -1;
01022 #endif
01023 
01024     case _SC_SIGNALS:
01025 #ifdef _POSUX_SIGNALS
01026       return _POSIX_SIGNALS;
01027 #else
01028       return -1;
01029 #endif
01030 
01031     case _SC_SPAWN:
01032 #if _POSIX_SPAWN > 0
01033       return _POSIX_SPAWN;
01034 #else
01035       return -1;
01036 #endif
01037 
01038     case _SC_SPORADIC_SERVER:
01039 #if _POSIX_SPORADIC_SERVER > 0
01040       return _POSIX_SPORADIC_SERVER;
01041 #else
01042       return -1;
01043 #endif
01044     case _SC_THREAD_SPORADIC_SERVER:
01045 #if _POSIX_THREAD_SPORADIC_SERVER > 0
01046       return _POSIX_THREAD_SPORADIC_SERVER;
01047 #else
01048       return -1;
01049 #endif
01050 
01051     case _SC_SYSTEM_DATABASE:
01052 #if _POSIX_SYSTEM_DATABASE > 0
01053       return _POSIX_SYSTEM_DATABASE;
01054 #else
01055       return -1;
01056 #endif
01057     case _SC_SYSTEM_DATABASE_R:
01058 #if _POSIX_SYSTEM_DATABASE_R > 0
01059       return _POSIX_SYSTEM_DATABASE_R;
01060 #else
01061       return -1;
01062 #endif
01063 
01064     case _SC_THREAD_CPUTIME:
01065 #if _POSIX_THREAD_CPUTIME > 0
01066       return _POSIX_THREAD_CPUTIME;
01067 #else
01068       return -1;
01069 #endif
01070 
01071     case _SC_TIMEOUTS:
01072 #if _POSIX_TIMEOUTS > 0
01073       return _POSIX_TIMEOUTS;
01074 #else
01075       return -1;
01076 #endif
01077 
01078     case _SC_TYPED_MEMORY_OBJECTS:
01079 #if _POSIX_TYPED_MEMORY_OBJECTS > 0
01080       return _POSIX_TYPED_MEMORY_OBJECTS;
01081 #else
01082       return -1;
01083 #endif
01084 
01085     case _SC_USER_GROUPS:
01086 #if _POSIX_USER_GROUPS > 0
01087       return _POSIX_USER_GROUPS;
01088 #else
01089       return -1;
01090 #endif
01091     case _SC_USER_GROUPS_R:
01092 #if _POSIX_USER_GROUPS_R > 0
01093       return _POSIX_USER_GROUPS_R;
01094 #else
01095       return -1;
01096 #endif
01097 
01098     case _SC_2_PBS:
01099 #ifdef _POSIX2_PBS
01100       return _POSIX2_PBS;
01101 #else
01102       return -1;
01103 #endif
01104     case _SC_2_PBS_ACCOUNTING:
01105 #ifdef _POSIX2_PBS_ACCOUNTING
01106       return _POSIX2_PBS_ACCOUNTING;
01107 #else
01108       return -1;
01109 #endif
01110     case _SC_2_PBS_CHECKPOINT:
01111 #ifdef _POSIX2_PBS_CHECKPOINT
01112       return _POSIX2_PBS_CHECKPOINT;
01113 #else
01114       return -1;
01115 #endif
01116     case _SC_2_PBS_LOCATE:
01117 #ifdef _POSIX2_PBS_LOCATE
01118       return _POSIX2_PBS_LOCATE;
01119 #else
01120       return -1;
01121 #endif
01122     case _SC_2_PBS_MESSAGE:
01123 #ifdef _POSIX2_PBS_MESSAGE
01124       return _POSIX2_PBS_MESSAGE;
01125 #else
01126       return -1;
01127 #endif
01128     case _SC_2_PBS_TRACK:
01129 #ifdef _POSIX2_PBS_TRACK
01130       return _POSIX2_PBS_TRACK;
01131 #else
01132       return -1;
01133 #endif
01134 
01135     case _SC_SYMLOOP_MAX:
01136 #ifdef SYMLOOP_MAX
01137       return SYMLOOP_MAX;
01138 #else
01139       return -1;
01140 #endif
01141 
01142     case _SC_STREAMS:
01143 #ifdef _XOPEN_STREAMS
01144       return _XOPEN_STREAMS;
01145 #else
01146       return -1;
01147 #endif
01148 
01149     case _SC_HOST_NAME_MAX:
01150 #ifdef HOST_NAME_MAX
01151       return HOST_NAME_MAX;
01152 #else
01153       return -1;
01154 #endif
01155 
01156     case _SC_TRACE:
01157 #if _POSIX_TRACE > 0
01158       return _POSIX_TRACE;
01159 #else
01160       return -1;
01161 #endif
01162     case _SC_TRACE_EVENT_FILTER:
01163 #if _POSIX_TRACE_EVENT_FILTER > 0
01164       return _POSIX_TRACE_EVENT_FILTER;
01165 #else
01166       return -1;
01167 #endif
01168     case _SC_TRACE_INHERIT:
01169 #if _POSIX_TRACE_INHERIT > 0
01170       return _POSIX_TRACE_INHERIT;
01171 #else
01172       return -1;
01173 #endif
01174     case _SC_TRACE_LOG:
01175 #if _POSIX_TRACE_LOG > 0
01176       return _POSIX_TRACE_LOG;
01177 #else
01178       return -1;
01179 #endif
01180 
01181     case _SC_LEVEL1_ICACHE_SIZE:
01182     case _SC_LEVEL1_ICACHE_ASSOC:
01183     case _SC_LEVEL1_ICACHE_LINESIZE:
01184     case _SC_LEVEL1_DCACHE_SIZE:
01185     case _SC_LEVEL1_DCACHE_ASSOC:
01186     case _SC_LEVEL1_DCACHE_LINESIZE:
01187     case _SC_LEVEL2_CACHE_SIZE:
01188     case _SC_LEVEL2_CACHE_ASSOC:
01189     case _SC_LEVEL2_CACHE_LINESIZE:
01190     case _SC_LEVEL3_CACHE_SIZE:
01191     case _SC_LEVEL3_CACHE_ASSOC:
01192     case _SC_LEVEL3_CACHE_LINESIZE:
01193     case _SC_LEVEL4_CACHE_SIZE:
01194     case _SC_LEVEL4_CACHE_ASSOC:
01195       /* In general we cannot determine these values.  Therefore we
01196         return zero which indicates that no information is
01197         available.  */
01198       return 0;
01199 
01200     case _SC_IPV6:
01201 #if _POSIX_IPV6 > 0
01202       return _POSIX_IPV6;
01203 #else
01204       return -1;
01205 #endif
01206 
01207     case _SC_RAW_SOCKETS:
01208 #if _POSIX_RAW_SOCKETS > 0
01209       return _POSIX_RAW_SOCKETS;
01210 #else
01211       return -1;
01212 #endif
01213     }
01214 }
01215 
01216 #undef __sysconf
01217 weak_alias (__sysconf, sysconf)
01218 libc_hidden_def (__sysconf)
01219 
01220 #if NEED_CHECK_SPEC
01221 static long int
01222 __sysconf_check_spec (const char *spec)
01223 {
01224   int save_errno = errno;
01225 
01226   const char *getconf_dir = __secure_getenv ("GETCONF_DIR") ?: GETCONF_DIR;
01227   size_t getconf_dirlen = strlen (getconf_dir);
01228   size_t speclen = strlen (spec);
01229 
01230   char name[getconf_dirlen + sizeof ("/POSIX_V6_") + speclen];
01231   memcpy (mempcpy (mempcpy (name, getconf_dir, getconf_dirlen),
01232                  "/POSIX_V6_", sizeof ("/POSIX_V6_") - 1),
01233          spec, speclen + 1);
01234 
01235   struct stat64 st;
01236   long int ret = __xstat64 (_STAT_VER, name, &st) >= 0 ? 1 : -1;
01237 
01238   __set_errno (save_errno);
01239   return ret;
01240 }
01241 #endif