Back to index

glibc  2.9
sysconf.c
Go to the documentation of this file.
00001 /* Copyright (C) 1991,1993,1995-1997,2001,2002,2003
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 <grp.h>
00022 #include <pwd.h>
00023 #include <stdio.h>
00024 #include <unistd.h>
00025 #include <time.h>
00026 #include <limits.h>
00027 #include <sys/param.h>
00028 #include <sys/sysinfo.h>
00029 
00030 
00031 /* Get the value of the system variable NAME.  */
00032 long int
00033 __sysconf (name)
00034      int name;
00035 {
00036   switch (name)
00037     {
00038     default:
00039       __set_errno (EINVAL);
00040       return -1;
00041 
00042     case _SC_TZNAME_MAX:
00043       return MAX (__tzname_max (), _POSIX_TZNAME_MAX);
00044 
00045     case _SC_CHARCLASS_NAME_MAX:
00046 #ifdef CHARCLASS_NAME_MAX
00047       return CHARCLASS_NAME_MAX;
00048 #else
00049       return -1;
00050 #endif
00051 
00052     case _SC_COLL_WEIGHTS_MAX:
00053 #ifdef COLL_WEIGHTS_MAX
00054       return COLL_WEIGHTS_MAX;
00055 #else
00056       return -1;
00057 #endif
00058 
00059     case _SC_EQUIV_CLASS_MAX:
00060 #ifdef EQUIV_CLASS_MAX
00061       return EQUIV_CLASS_MAX;
00062 #else
00063       return -1;
00064 #endif
00065 
00066     case _SC_2_LOCALEDEF:
00067 #ifdef _POSIX2_LOCALEDEF
00068       return _POSIX2_LOCALEDEF;
00069 #else
00070       return -1;
00071 #endif
00072 
00073     case _SC_NPROCESSORS_CONF:
00074       return __get_nprocs_conf ();
00075 
00076     case _SC_NPROCESSORS_ONLN:
00077       return __get_nprocs ();
00078 
00079     case _SC_PHYS_PAGES:
00080       return __get_phys_pages ();
00081 
00082     case _SC_AVPHYS_PAGES:
00083       return __get_avphys_pages ();
00084 
00085     case _SC_ATEXIT_MAX:
00086       /* We have no limit since we use lists.  */
00087       return INT_MAX;
00088 
00089     case _SC_PASS_MAX:
00090       /* We have no limit but since the return value might be used to
00091         allocate a buffer we restrict the value.  */
00092       return BUFSIZ;
00093 
00094     case _SC_CHAR_BIT:
00095       return CHAR_BIT;
00096 
00097     case _SC_CHAR_MAX:
00098       return CHAR_MAX;
00099 
00100     case _SC_CHAR_MIN:
00101       return CHAR_MIN;
00102 
00103     case _SC_INT_MAX:
00104       return INT_MAX;
00105 
00106     case _SC_INT_MIN:
00107       return INT_MIN;
00108 
00109     case _SC_LONG_BIT:
00110       return sizeof (long int) * CHAR_BIT;
00111 
00112     case _SC_WORD_BIT:
00113       return sizeof (int) * CHAR_BIT;
00114 
00115     case _SC_MB_LEN_MAX:
00116       return MB_LEN_MAX;
00117 
00118     case _SC_NZERO:
00119       return NZERO;
00120 
00121     case _SC_SSIZE_MAX:
00122       return _POSIX_SSIZE_MAX;
00123 
00124     case _SC_SCHAR_MAX:
00125       return SCHAR_MAX;
00126 
00127     case _SC_SCHAR_MIN:
00128       return SCHAR_MIN;
00129 
00130     case _SC_SHRT_MAX:
00131       return SHRT_MAX;
00132 
00133     case _SC_SHRT_MIN:
00134       return SHRT_MIN;
00135 
00136     case _SC_UCHAR_MAX:
00137       return UCHAR_MAX;
00138 
00139     case _SC_UINT_MAX:
00140       return UINT_MAX;
00141 
00142     case _SC_ULONG_MAX:
00143       return ULONG_MAX;
00144 
00145     case _SC_USHRT_MAX:
00146       return USHRT_MAX;
00147 
00148     case _SC_GETGR_R_SIZE_MAX:
00149       return NSS_BUFLEN_GROUP;
00150 
00151     case _SC_GETPW_R_SIZE_MAX:
00152       return NSS_BUFLEN_PASSWD;
00153 
00154     case _SC_ARG_MAX:
00155     case _SC_CHILD_MAX:
00156     case _SC_CLK_TCK:
00157     case _SC_NGROUPS_MAX:
00158     case _SC_OPEN_MAX:
00159     case _SC_STREAM_MAX:
00160     case _SC_JOB_CONTROL:
00161     case _SC_SAVED_IDS:
00162     case _SC_REALTIME_SIGNALS:
00163     case _SC_PRIORITY_SCHEDULING:
00164     case _SC_TIMERS:
00165     case _SC_ASYNCHRONOUS_IO:
00166     case _SC_PRIORITIZED_IO:
00167     case _SC_SYNCHRONIZED_IO:
00168     case _SC_FSYNC:
00169     case _SC_MAPPED_FILES:
00170     case _SC_MEMLOCK:
00171     case _SC_MEMLOCK_RANGE:
00172     case _SC_MEMORY_PROTECTION:
00173     case _SC_MESSAGE_PASSING:
00174     case _SC_SEMAPHORES:
00175     case _SC_SHARED_MEMORY_OBJECTS:
00176 
00177     case _SC_AIO_LISTIO_MAX:
00178     case _SC_AIO_MAX:
00179     case _SC_AIO_PRIO_DELTA_MAX:
00180     case _SC_DELAYTIMER_MAX:
00181     case _SC_MQ_OPEN_MAX:
00182     case _SC_MQ_PRIO_MAX:
00183     case _SC_VERSION:
00184     case _SC_PAGESIZE:
00185     case _SC_RTSIG_MAX:
00186     case _SC_SEM_NSEMS_MAX:
00187     case _SC_SEM_VALUE_MAX:
00188     case _SC_SIGQUEUE_MAX:
00189     case _SC_TIMER_MAX:
00190 
00191     case _SC_PII:
00192     case _SC_PII_XTI:
00193     case _SC_PII_SOCKET:
00194     case _SC_PII_OSI:
00195     case _SC_POLL:
00196     case _SC_SELECT:
00197     case _SC_UIO_MAXIOV:
00198     case _SC_PII_INTERNET_STREAM:
00199     case _SC_PII_INTERNET_DGRAM:
00200     case _SC_PII_OSI_COTS:
00201     case _SC_PII_OSI_CLTS:
00202     case _SC_PII_OSI_M:
00203     case _SC_T_IOV_MAX:
00204 
00205     case _SC_BC_BASE_MAX:
00206     case _SC_BC_DIM_MAX:
00207     case _SC_BC_SCALE_MAX:
00208     case _SC_BC_STRING_MAX:
00209     case _SC_EXPR_NEST_MAX:
00210     case _SC_LINE_MAX:
00211     case _SC_RE_DUP_MAX:
00212     case _SC_2_VERSION:
00213     case _SC_2_C_BIND:
00214     case _SC_2_C_DEV:
00215     case _SC_2_FORT_DEV:
00216     case _SC_2_SW_DEV:
00217     case _SC_2_CHAR_TERM:
00218     case _SC_2_C_VERSION:
00219     case _SC_2_UPE:
00220 
00221     case _SC_THREADS:
00222     case _SC_THREAD_SAFE_FUNCTIONS:
00223     case _SC_LOGIN_NAME_MAX:
00224     case _SC_TTY_NAME_MAX:
00225     case _SC_THREAD_DESTRUCTOR_ITERATIONS:
00226     case _SC_THREAD_KEYS_MAX:
00227     case _SC_THREAD_STACK_MIN:
00228     case _SC_THREAD_THREADS_MAX:
00229     case _SC_THREAD_ATTR_STACKADDR:
00230     case _SC_THREAD_ATTR_STACKSIZE:
00231     case _SC_THREAD_PRIORITY_SCHEDULING:
00232     case _SC_THREAD_PRIO_INHERIT:
00233     case _SC_THREAD_PRIO_PROTECT:
00234     case _SC_THREAD_PROCESS_SHARED:
00235 
00236     case _SC_XOPEN_VERSION:
00237     case _SC_XOPEN_XCU_VERSION:
00238     case _SC_XOPEN_UNIX:
00239     case _SC_XOPEN_CRYPT:
00240     case _SC_XOPEN_ENH_I18N:
00241     case _SC_XOPEN_SHM:
00242     case _SC_XOPEN_XPG2:
00243     case _SC_XOPEN_XPG3:
00244     case _SC_XOPEN_XPG4:
00245 
00246     case _SC_NL_ARGMAX:
00247     case _SC_NL_LANGMAX:
00248     case _SC_NL_MSGMAX:
00249     case _SC_NL_NMAX:
00250     case _SC_NL_SETMAX:
00251     case _SC_NL_TEXTMAX:
00252 
00253     case _SC_XBS5_ILP32_OFF32:
00254     case _SC_XBS5_ILP32_OFFBIG:
00255     case _SC_XBS5_LP64_OFF64:
00256     case _SC_XBS5_LPBIG_OFFBIG:
00257 
00258     case _SC_XOPEN_LEGACY:
00259     case _SC_XOPEN_REALTIME:
00260     case _SC_XOPEN_REALTIME_THREADS:
00261 
00262       break;
00263     }
00264 
00265   __set_errno (ENOSYS);
00266   return -1;
00267 }
00268 
00269 weak_alias (__sysconf, sysconf)
00270 libc_hidden_def (__sysconf)
00271 
00272 stub_warning (sysconf)
00273 #include <stub-tag.h>