PageRenderTime 38ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/posix/sysconf.c

https://github.com/hjl-tools/glibc
C | 279 lines | 210 code | 49 blank | 20 comment | 1 complexity | 6f1d4ab5749a4b0db32893fd319aa3e6 MD5 | raw file
  1. /* Copyright (C) 1991-2020 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <https://www.gnu.org/licenses/>. */
  14. #include <errno.h>
  15. #include <grp.h>
  16. #include <pwd.h>
  17. #include <stdio.h>
  18. #include <unistd.h>
  19. #include <time.h>
  20. #include <limits.h>
  21. #include <sys/param.h>
  22. #include <sys/sysinfo.h>
  23. /* Get the value of the system variable NAME. */
  24. long int
  25. __sysconf (int name)
  26. {
  27. switch (name)
  28. {
  29. default:
  30. __set_errno (EINVAL);
  31. return -1;
  32. case _SC_TZNAME_MAX:
  33. return -1;
  34. case _SC_CHARCLASS_NAME_MAX:
  35. #ifdef CHARCLASS_NAME_MAX
  36. return CHARCLASS_NAME_MAX;
  37. #else
  38. return -1;
  39. #endif
  40. case _SC_COLL_WEIGHTS_MAX:
  41. #ifdef COLL_WEIGHTS_MAX
  42. return COLL_WEIGHTS_MAX;
  43. #else
  44. return -1;
  45. #endif
  46. case _SC_EQUIV_CLASS_MAX:
  47. #ifdef EQUIV_CLASS_MAX
  48. return EQUIV_CLASS_MAX;
  49. #else
  50. return -1;
  51. #endif
  52. case _SC_2_LOCALEDEF:
  53. #ifdef _POSIX2_LOCALEDEF
  54. return _POSIX2_LOCALEDEF;
  55. #else
  56. return -1;
  57. #endif
  58. case _SC_NPROCESSORS_CONF:
  59. return __get_nprocs_conf ();
  60. case _SC_NPROCESSORS_ONLN:
  61. return __get_nprocs ();
  62. case _SC_PHYS_PAGES:
  63. return __get_phys_pages ();
  64. case _SC_AVPHYS_PAGES:
  65. return __get_avphys_pages ();
  66. case _SC_ATEXIT_MAX:
  67. /* We have no limit since we use lists. */
  68. return INT_MAX;
  69. case _SC_PASS_MAX:
  70. /* We have no limit but since the return value might be used to
  71. allocate a buffer we restrict the value. */
  72. return BUFSIZ;
  73. case _SC_CHAR_BIT:
  74. return CHAR_BIT;
  75. case _SC_CHAR_MAX:
  76. return CHAR_MAX;
  77. case _SC_CHAR_MIN:
  78. return CHAR_MIN;
  79. case _SC_INT_MAX:
  80. return INT_MAX;
  81. case _SC_INT_MIN:
  82. return INT_MIN;
  83. case _SC_LONG_BIT:
  84. return sizeof (long int) * CHAR_BIT;
  85. case _SC_WORD_BIT:
  86. return sizeof (int) * CHAR_BIT;
  87. case _SC_MB_LEN_MAX:
  88. return MB_LEN_MAX;
  89. case _SC_NZERO:
  90. return NZERO;
  91. case _SC_SSIZE_MAX:
  92. return _POSIX_SSIZE_MAX;
  93. case _SC_SCHAR_MAX:
  94. return SCHAR_MAX;
  95. case _SC_SCHAR_MIN:
  96. return SCHAR_MIN;
  97. case _SC_SHRT_MAX:
  98. return SHRT_MAX;
  99. case _SC_SHRT_MIN:
  100. return SHRT_MIN;
  101. case _SC_UCHAR_MAX:
  102. return UCHAR_MAX;
  103. case _SC_UINT_MAX:
  104. return UINT_MAX;
  105. case _SC_ULONG_MAX:
  106. return ULONG_MAX;
  107. case _SC_USHRT_MAX:
  108. return USHRT_MAX;
  109. case _SC_GETGR_R_SIZE_MAX:
  110. return NSS_BUFLEN_GROUP;
  111. case _SC_GETPW_R_SIZE_MAX:
  112. return NSS_BUFLEN_PASSWD;
  113. case _SC_ARG_MAX:
  114. case _SC_CHILD_MAX:
  115. case _SC_CLK_TCK:
  116. case _SC_NGROUPS_MAX:
  117. case _SC_OPEN_MAX:
  118. case _SC_STREAM_MAX:
  119. case _SC_JOB_CONTROL:
  120. case _SC_SAVED_IDS:
  121. case _SC_REALTIME_SIGNALS:
  122. case _SC_PRIORITY_SCHEDULING:
  123. case _SC_TIMERS:
  124. case _SC_ASYNCHRONOUS_IO:
  125. case _SC_PRIORITIZED_IO:
  126. case _SC_SYNCHRONIZED_IO:
  127. case _SC_FSYNC:
  128. case _SC_MAPPED_FILES:
  129. case _SC_MEMLOCK:
  130. case _SC_MEMLOCK_RANGE:
  131. case _SC_MEMORY_PROTECTION:
  132. case _SC_MESSAGE_PASSING:
  133. case _SC_SEMAPHORES:
  134. case _SC_SHARED_MEMORY_OBJECTS:
  135. case _SC_AIO_LISTIO_MAX:
  136. case _SC_AIO_MAX:
  137. case _SC_AIO_PRIO_DELTA_MAX:
  138. case _SC_DELAYTIMER_MAX:
  139. case _SC_MQ_OPEN_MAX:
  140. case _SC_MQ_PRIO_MAX:
  141. case _SC_VERSION:
  142. case _SC_PAGESIZE:
  143. case _SC_RTSIG_MAX:
  144. case _SC_SEM_NSEMS_MAX:
  145. case _SC_SEM_VALUE_MAX:
  146. case _SC_SIGQUEUE_MAX:
  147. case _SC_TIMER_MAX:
  148. case _SC_PII:
  149. case _SC_PII_XTI:
  150. case _SC_PII_SOCKET:
  151. case _SC_PII_OSI:
  152. case _SC_POLL:
  153. case _SC_SELECT:
  154. case _SC_UIO_MAXIOV:
  155. case _SC_PII_INTERNET_STREAM:
  156. case _SC_PII_INTERNET_DGRAM:
  157. case _SC_PII_OSI_COTS:
  158. case _SC_PII_OSI_CLTS:
  159. case _SC_PII_OSI_M:
  160. case _SC_T_IOV_MAX:
  161. case _SC_BC_BASE_MAX:
  162. case _SC_BC_DIM_MAX:
  163. case _SC_BC_SCALE_MAX:
  164. case _SC_BC_STRING_MAX:
  165. case _SC_EXPR_NEST_MAX:
  166. case _SC_LINE_MAX:
  167. case _SC_RE_DUP_MAX:
  168. case _SC_2_VERSION:
  169. case _SC_2_C_BIND:
  170. case _SC_2_C_DEV:
  171. case _SC_2_FORT_DEV:
  172. case _SC_2_SW_DEV:
  173. case _SC_2_CHAR_TERM:
  174. case _SC_2_C_VERSION:
  175. case _SC_2_UPE:
  176. case _SC_THREADS:
  177. case _SC_THREAD_SAFE_FUNCTIONS:
  178. case _SC_LOGIN_NAME_MAX:
  179. case _SC_TTY_NAME_MAX:
  180. case _SC_THREAD_DESTRUCTOR_ITERATIONS:
  181. case _SC_THREAD_KEYS_MAX:
  182. case _SC_THREAD_STACK_MIN:
  183. case _SC_THREAD_THREADS_MAX:
  184. case _SC_THREAD_ATTR_STACKADDR:
  185. case _SC_THREAD_ATTR_STACKSIZE:
  186. case _SC_THREAD_PRIORITY_SCHEDULING:
  187. case _SC_THREAD_PRIO_INHERIT:
  188. case _SC_THREAD_PRIO_PROTECT:
  189. case _SC_THREAD_PROCESS_SHARED:
  190. case _SC_XOPEN_VERSION:
  191. case _SC_XOPEN_XCU_VERSION:
  192. case _SC_XOPEN_UNIX:
  193. case _SC_XOPEN_CRYPT:
  194. case _SC_XOPEN_ENH_I18N:
  195. case _SC_XOPEN_SHM:
  196. case _SC_XOPEN_XPG2:
  197. case _SC_XOPEN_XPG3:
  198. case _SC_XOPEN_XPG4:
  199. case _SC_NL_ARGMAX:
  200. case _SC_NL_LANGMAX:
  201. case _SC_NL_MSGMAX:
  202. case _SC_NL_NMAX:
  203. case _SC_NL_SETMAX:
  204. case _SC_NL_TEXTMAX:
  205. case _SC_XBS5_ILP32_OFF32:
  206. case _SC_XBS5_ILP32_OFFBIG:
  207. case _SC_XBS5_LP64_OFF64:
  208. case _SC_XBS5_LPBIG_OFFBIG:
  209. case _SC_POSIX_V6_ILP32_OFF32:
  210. case _SC_POSIX_V6_ILP32_OFFBIG:
  211. case _SC_POSIX_V6_LP64_OFF64:
  212. case _SC_POSIX_V6_LPBIG_OFFBIG:
  213. case _SC_POSIX_V7_ILP32_OFF32:
  214. case _SC_POSIX_V7_ILP32_OFFBIG:
  215. case _SC_POSIX_V7_LP64_OFF64:
  216. case _SC_POSIX_V7_LPBIG_OFFBIG:
  217. case _SC_XOPEN_LEGACY:
  218. case _SC_XOPEN_REALTIME:
  219. case _SC_XOPEN_REALTIME_THREADS:
  220. break;
  221. }
  222. __set_errno (ENOSYS);
  223. return -1;
  224. }
  225. weak_alias (__sysconf, sysconf)
  226. libc_hidden_def (__sysconf)
  227. stub_warning (sysconf)