sysconf.c 19 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018
  1. /* Copyright (C) 1991,1993,1995-1997,2000
  2. Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public
  13. License along with the GNU C Library; see the file COPYING.LIB. If not,
  14. see <http://www.gnu.org/licenses/>. */
  15. #define _XOPEN_SOURCE 500
  16. #include <features.h>
  17. #include <ctype.h>
  18. #include <errno.h>
  19. #include <limits.h>
  20. #include <grp.h>
  21. #include <pwd.h>
  22. #include <stddef.h>
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <time.h>
  26. #include <unistd.h>
  27. #include <sys/syscall.h>
  28. #include <sys/sysinfo.h>
  29. #include <sys/types.h>
  30. #include <sys/param.h>
  31. #ifdef __UCLIBC_HAS_REGEX__
  32. #include <regex.h>
  33. #endif
  34. #ifdef __UCLIBC_HAS_THREADS_NATIVE__
  35. #include <sysdep.h>
  36. #endif
  37. #include <sys/resource.h>
  38. #include <string.h>
  39. #include <dirent.h>
  40. #include "internal/parse_config.h"
  41. long int get_phys_pages(void)
  42. {
  43. struct sysinfo si;
  44. int ps = getpagesize();;
  45. sysinfo(&si);
  46. if (ps >= si.mem_unit)
  47. return si.totalram / (ps / si.mem_unit);
  48. else
  49. return si.totalram * (si.mem_unit / ps);
  50. }
  51. long int get_avphys_pages(void)
  52. {
  53. struct sysinfo si;
  54. int ps = getpagesize();;
  55. sysinfo(&si);
  56. if (ps >= si.mem_unit)
  57. return si.freeram / (ps / si.mem_unit);
  58. else
  59. return si.freeram * (si.mem_unit / ps);
  60. }
  61. static int nprocessors_onln(void)
  62. {
  63. char **l = NULL;
  64. parser_t *p = config_open("/proc/stat");
  65. int ret = 0;
  66. if (p) {
  67. while (config_read(p, &l, 2, 1, " ", 0))
  68. if (l[0][0] == 'c'
  69. && l[0][1] == 'p'
  70. && l[0][2] == 'u'
  71. && isdigit(l[0][3]))
  72. ++ret;
  73. } else if ((p = config_open("/proc/cpuinfo"))) {
  74. #if defined __sparc__
  75. while (config_read(p, &l, 2, 2, "\0:", PARSE_NORMAL))
  76. if (strncmp("ncpus active", l[0], 12) == 0) {
  77. ret = atoi(l[1]);
  78. break;
  79. }
  80. #else
  81. while (config_read(p, &l, 2, 2, "\0:\t", PARSE_NORMAL))
  82. if (strcmp("processor", l[0]) == 0)
  83. ++ret;
  84. #endif
  85. }
  86. config_close(p);
  87. return ret != 0 ? ret : 1;
  88. }
  89. #if defined __UCLIBC__ && !defined __UCLIBC_HAS_LFS__
  90. # define readdir64 readdir
  91. # define dirent64 dirent
  92. #endif
  93. static int nprocessors_conf(void)
  94. {
  95. int ret = 0;
  96. DIR *dir = opendir("/sys/devices/system/cpu");
  97. if (dir) {
  98. struct dirent64 *dp;
  99. while ((dp = readdir64(dir))) {
  100. if (dp->d_type == DT_DIR
  101. && dp->d_name[0] == 'c'
  102. && dp->d_name[1] == 'p'
  103. && dp->d_name[2] == 'u'
  104. && isdigit(dp->d_name[3]))
  105. ++ret;
  106. }
  107. closedir(dir);
  108. } else
  109. {
  110. #if defined __sparc__
  111. char **l = NULL;
  112. parser_t *p = config_open("/proc/stat");
  113. while (config_read(p, &l, 2, 2, "\0:", PARSE_NORMAL))
  114. if (strncmp("ncpus probed", l[0], 13) == 0) {
  115. ret = atoi(l[1]);
  116. break;
  117. }
  118. config_close(p);
  119. #else
  120. ret = nprocessors_onln();
  121. #endif
  122. }
  123. return ret != 0 ? ret : 1;
  124. }
  125. #ifndef __UCLIBC_CLK_TCK_CONST
  126. #error __UCLIBC_CLK_TCK_CONST not defined!
  127. #endif
  128. /***********************************************************************/
  129. /*
  130. * Manuel Novoa III Jan 2001
  131. *
  132. * On i386, the switch-based implementation generates 796 bytes of code.
  133. * However, many of the return values are repeats. By collecting these
  134. * repeats and moving to a table-based implementation, we generate 283
  135. * bytes on i386 (-Os -fomit-frame-pointer).
  136. */
  137. #ifdef _UCLIBC_GENERATE_SYSCONF_ARCH
  138. /*
  139. * Set some errno's so the auto-gen code knows what it is dealing with.
  140. * 1) ENOSYS signifies that we're returning a default value.
  141. * This is just extra info for development.
  142. * 2) EISNAM signifies that the value returned varies at runtime.
  143. *
  144. * Option: GETPAGESIZE_IS_DYNAMIC
  145. * The current implementation of getpagesize in uClibc returns
  146. * a constant. The pagesize on the target arch should not vary,
  147. * so it should be safe to set this as 0.
  148. */
  149. #define RETURN_NEG_1 __set_errno(ENOSYS); return -1
  150. #define RETURN_FUNCTION(f) __set_errno(EISNAM); return (long int) #f
  151. #define GETPAGESIZE_IS_DYNAMIC 0
  152. #else
  153. #define RETURN_NEG_1 return -1
  154. #define RETURN_FUNCTION(f) return f;
  155. #endif /* _UCLIBC_GENERATE_SYSCONF_ARCH */
  156. /* Legacy value of ARG_MAX. The macro is now not defined since the
  157. actual value varies based on the stack size. */
  158. #define legacy_ARG_MAX 131072
  159. /* Get the value of the system variable NAME. */
  160. long int sysconf(int name)
  161. {
  162. struct rlimit rlimit;
  163. switch (name)
  164. {
  165. default:
  166. __set_errno(EINVAL);
  167. return -1;
  168. case _SC_ARG_MAX:
  169. /* Use getrlimit to get the stack limit. */
  170. if (getrlimit (RLIMIT_STACK, &rlimit) == 0)
  171. return MAX (legacy_ARG_MAX, rlimit.rlim_cur / 4);
  172. #if defined ARG_MAX
  173. return ARG_MAX;
  174. #else
  175. return legacy_ARG_MAX;
  176. #endif
  177. case _SC_CHILD_MAX:
  178. #ifdef CHILD_MAX
  179. return CHILD_MAX;
  180. #else
  181. RETURN_NEG_1;
  182. #endif
  183. case _SC_CLK_TCK:
  184. /* Can't use CLK_TCK here since that calls __sysconf(_SC_CLK_TCK) */
  185. return __UCLIBC_CLK_TCK_CONST;
  186. case _SC_NGROUPS_MAX:
  187. #ifdef NGROUPS_MAX
  188. return NGROUPS_MAX;
  189. #else
  190. RETURN_NEG_1;
  191. #endif
  192. case _SC_OPEN_MAX:
  193. RETURN_FUNCTION(getdtablesize());
  194. case _SC_STREAM_MAX:
  195. #ifdef STREAM_MAX
  196. return STREAM_MAX;
  197. #else
  198. return FOPEN_MAX;
  199. #endif
  200. case _SC_TZNAME_MAX:
  201. return _POSIX_TZNAME_MAX;
  202. case _SC_JOB_CONTROL:
  203. #ifdef _POSIX_JOB_CONTROL
  204. return 1;
  205. #else
  206. RETURN_NEG_1;
  207. #endif
  208. case _SC_SAVED_IDS:
  209. #ifdef _POSIX_SAVED_IDS
  210. return 1;
  211. #else
  212. RETURN_NEG_1;
  213. #endif
  214. case _SC_REALTIME_SIGNALS:
  215. #ifdef _POSIX_REALTIME_SIGNALS
  216. return 1;
  217. #else
  218. RETURN_NEG_1;
  219. #endif
  220. case _SC_PRIORITY_SCHEDULING:
  221. #ifdef _POSIX_PRIORITY_SCHEDULING
  222. return 1;
  223. #else
  224. RETURN_NEG_1;
  225. #endif
  226. case _SC_TIMERS:
  227. #ifdef _POSIX_TIMERS
  228. return 1;
  229. #else
  230. RETURN_NEG_1;
  231. #endif
  232. case _SC_ASYNCHRONOUS_IO:
  233. #ifdef _POSIX_ASYNCHRONOUS_IO
  234. return 1;
  235. #else
  236. RETURN_NEG_1;
  237. #endif
  238. case _SC_PRIORITIZED_IO:
  239. #ifdef _POSIX_PRIORITIZED_IO
  240. return 1;
  241. #else
  242. RETURN_NEG_1;
  243. #endif
  244. case _SC_SYNCHRONIZED_IO:
  245. #ifdef _POSIX_SYNCHRONIZED_IO
  246. return 1;
  247. #else
  248. RETURN_NEG_1;
  249. #endif
  250. case _SC_FSYNC:
  251. #ifdef _POSIX_FSYNC
  252. return 1;
  253. #else
  254. RETURN_NEG_1;
  255. #endif
  256. case _SC_MAPPED_FILES:
  257. #ifdef _POSIX_MAPPED_FILES
  258. return 1;
  259. #else
  260. RETURN_NEG_1;
  261. #endif
  262. case _SC_MEMLOCK:
  263. #ifdef _POSIX_MEMLOCK
  264. return 1;
  265. #else
  266. RETURN_NEG_1;
  267. #endif
  268. case _SC_MEMLOCK_RANGE:
  269. #ifdef _POSIX_MEMLOCK_RANGE
  270. return 1;
  271. #else
  272. RETURN_NEG_1;
  273. #endif
  274. case _SC_MEMORY_PROTECTION:
  275. #ifdef _POSIX_MEMORY_PROTECTION
  276. return 1;
  277. #else
  278. RETURN_NEG_1;
  279. #endif
  280. case _SC_MESSAGE_PASSING:
  281. #ifdef _POSIX_MESSAGE_PASSING
  282. return 1;
  283. #else
  284. RETURN_NEG_1;
  285. #endif
  286. case _SC_SEMAPHORES:
  287. #ifdef _POSIX_SEMAPHORES
  288. return 1;
  289. #else
  290. RETURN_NEG_1;
  291. #endif
  292. case _SC_SHARED_MEMORY_OBJECTS:
  293. #ifdef _POSIX_SHARED_MEMORY_OBJECTS
  294. return 1;
  295. #else
  296. RETURN_NEG_1;
  297. #endif
  298. case _SC_VERSION:
  299. return _POSIX_VERSION;
  300. case _SC_PAGESIZE:
  301. #if defined(GETPAGESIZE_IS_DYNAMIC) && (GETPAGESIZE_IS_DYNAMIC == 1)
  302. RETURN_FUNCTION(getpagesize());
  303. #else
  304. return getpagesize(); /* note: currently this is not dynamic */
  305. #endif
  306. case _SC_AIO_LISTIO_MAX:
  307. #ifdef AIO_LISTIO_MAX
  308. return AIO_LISTIO_MAX;
  309. #else
  310. RETURN_NEG_1;
  311. #endif
  312. case _SC_AIO_MAX:
  313. #ifdef AIO_MAX
  314. return AIO_MAX;
  315. #else
  316. RETURN_NEG_1;
  317. #endif
  318. case _SC_AIO_PRIO_DELTA_MAX:
  319. #ifdef AIO_PRIO_DELTA_MAX
  320. return AIO_PRIO_DELTA_MAX;
  321. #else
  322. RETURN_NEG_1;
  323. #endif
  324. case _SC_DELAYTIMER_MAX:
  325. #ifdef DELAYTIMER_MAX
  326. return DELAYTIMER_MAX;
  327. #else
  328. RETURN_NEG_1;
  329. #endif
  330. case _SC_MQ_OPEN_MAX:
  331. #ifdef MQ_OPEN_MAX
  332. return MQ_OPEN_MAX;
  333. #else
  334. RETURN_NEG_1;
  335. #endif
  336. case _SC_MQ_PRIO_MAX:
  337. #ifdef MQ_PRIO_MAX
  338. return MQ_PRIO_MAX;
  339. #else
  340. RETURN_NEG_1;
  341. #endif
  342. case _SC_RTSIG_MAX:
  343. #ifdef RTSIG_MAX
  344. return RTSIG_MAX;
  345. #else
  346. RETURN_NEG_1;
  347. #endif
  348. case _SC_SEM_NSEMS_MAX:
  349. #ifdef SEM_NSEMS_MAX
  350. return SEM_NSEMS_MAX;
  351. #else
  352. RETURN_NEG_1;
  353. #endif
  354. case _SC_SEM_VALUE_MAX:
  355. #ifdef SEM_VALUE_MAX
  356. return SEM_VALUE_MAX;
  357. #else
  358. RETURN_NEG_1;
  359. #endif
  360. case _SC_SIGQUEUE_MAX:
  361. #ifdef SIGQUEUE_MAX
  362. return SIGQUEUE_MAX;
  363. #else
  364. RETURN_NEG_1;
  365. #endif
  366. case _SC_TIMER_MAX:
  367. #ifdef TIMER_MAX
  368. return TIMER_MAX;
  369. #else
  370. RETURN_NEG_1;
  371. #endif
  372. case _SC_BC_BASE_MAX:
  373. #ifdef BC_BASE_MAX
  374. return BC_BASE_MAX;
  375. #else
  376. RETURN_NEG_1;
  377. #endif
  378. case _SC_BC_DIM_MAX:
  379. #ifdef BC_DIM_MAX
  380. return BC_DIM_MAX;
  381. #else
  382. RETURN_NEG_1;
  383. #endif
  384. case _SC_BC_SCALE_MAX:
  385. #ifdef BC_SCALE_MAX
  386. return BC_SCALE_MAX;
  387. #else
  388. RETURN_NEG_1;
  389. #endif
  390. case _SC_BC_STRING_MAX:
  391. #ifdef BC_STRING_MAX
  392. return BC_STRING_MAX;
  393. #else
  394. RETURN_NEG_1;
  395. #endif
  396. case _SC_COLL_WEIGHTS_MAX:
  397. #ifdef COLL_WEIGHTS_MAX
  398. return COLL_WEIGHTS_MAX;
  399. #else
  400. RETURN_NEG_1;
  401. #endif
  402. case _SC_EQUIV_CLASS_MAX:
  403. #ifdef EQUIV_CLASS_MAX
  404. return EQUIV_CLASS_MAX;
  405. #else
  406. RETURN_NEG_1;
  407. #endif
  408. case _SC_EXPR_NEST_MAX:
  409. #ifdef EXPR_NEST_MAX
  410. return EXPR_NEST_MAX;
  411. #else
  412. RETURN_NEG_1;
  413. #endif
  414. case _SC_LINE_MAX:
  415. #ifdef LINE_MAX
  416. return LINE_MAX;
  417. #else
  418. RETURN_NEG_1;
  419. #endif
  420. case _SC_RE_DUP_MAX:
  421. #ifdef RE_DUP_MAX
  422. return RE_DUP_MAX;
  423. #else
  424. RETURN_NEG_1;
  425. #endif
  426. case _SC_CHARCLASS_NAME_MAX:
  427. #ifdef CHARCLASS_NAME_MAX
  428. return CHARCLASS_NAME_MAX;
  429. #else
  430. RETURN_NEG_1;
  431. #endif
  432. case _SC_PII:
  433. #ifdef _POSIX_PII
  434. return 1;
  435. #else
  436. RETURN_NEG_1;
  437. #endif
  438. case _SC_PII_XTI:
  439. #ifdef _POSIX_PII_XTI
  440. return 1;
  441. #else
  442. RETURN_NEG_1;
  443. #endif
  444. case _SC_PII_SOCKET:
  445. #ifdef _POSIX_PII_SOCKET
  446. return 1;
  447. #else
  448. RETURN_NEG_1;
  449. #endif
  450. case _SC_PII_INTERNET:
  451. #ifdef _POSIX_PII_INTERNET
  452. return 1;
  453. #else
  454. RETURN_NEG_1;
  455. #endif
  456. case _SC_PII_OSI:
  457. #ifdef _POSIX_PII_OSI
  458. return 1;
  459. #else
  460. RETURN_NEG_1;
  461. #endif
  462. case _SC_POLL:
  463. #ifdef _POSIX_POLL
  464. return 1;
  465. #else
  466. RETURN_NEG_1;
  467. #endif
  468. case _SC_SELECT:
  469. #ifdef _POSIX_SELECT
  470. return 1;
  471. #else
  472. RETURN_NEG_1;
  473. #endif
  474. case _SC_UIO_MAXIOV:
  475. #ifdef UIO_MAXIOV
  476. return UIO_MAXIOV;
  477. #else
  478. RETURN_NEG_1;
  479. #endif
  480. case _SC_PII_INTERNET_STREAM:
  481. #ifdef _POSIX_PII_INTERNET_STREAM
  482. return 1;
  483. #else
  484. RETURN_NEG_1;
  485. #endif
  486. case _SC_PII_INTERNET_DGRAM:
  487. #ifdef _POSIX_PII_INTERNET_DGRAM
  488. return 1;
  489. #else
  490. RETURN_NEG_1;
  491. #endif
  492. case _SC_PII_OSI_COTS:
  493. #ifdef _POSIX_PII_OSI_COTS
  494. return 1;
  495. #else
  496. RETURN_NEG_1;
  497. #endif
  498. case _SC_PII_OSI_CLTS:
  499. #ifdef _POSIX_PII_OSI_CLTS
  500. return 1;
  501. #else
  502. RETURN_NEG_1;
  503. #endif
  504. case _SC_PII_OSI_M:
  505. #ifdef _POSIX_PII_OSI_M
  506. return 1;
  507. #else
  508. RETURN_NEG_1;
  509. #endif
  510. case _SC_T_IOV_MAX:
  511. #ifdef _T_IOV_MAX
  512. return _T_IOV_MAX;
  513. #else
  514. RETURN_NEG_1;
  515. #endif
  516. case _SC_2_VERSION:
  517. return _POSIX2_VERSION;
  518. case _SC_2_C_BIND:
  519. #ifdef _POSIX2_C_BIND
  520. return _POSIX2_C_BIND;
  521. #else
  522. RETURN_NEG_1;
  523. #endif
  524. case _SC_2_C_DEV:
  525. #ifdef _POSIX2_C_DEV
  526. return _POSIX2_C_DEV;
  527. #else
  528. RETURN_NEG_1;
  529. #endif
  530. case _SC_2_C_VERSION:
  531. #ifdef _POSIX2_C_VERSION
  532. return _POSIX2_C_VERSION;
  533. #else
  534. RETURN_NEG_1;
  535. #endif
  536. case _SC_2_FORT_DEV:
  537. #ifdef _POSIX2_FORT_DEV
  538. return _POSIX2_FORT_DEV;
  539. #else
  540. RETURN_NEG_1;
  541. #endif
  542. case _SC_2_FORT_RUN:
  543. #ifdef _POSIX2_FORT_RUN
  544. return _POSIX2_FORT_RUN;
  545. #else
  546. RETURN_NEG_1;
  547. #endif
  548. case _SC_2_LOCALEDEF:
  549. #ifdef _POSIX2_LOCALEDEF
  550. return _POSIX2_LOCALEDEF;
  551. #else
  552. RETURN_NEG_1;
  553. #endif
  554. case _SC_2_SW_DEV:
  555. #ifdef _POSIX2_SW_DEV
  556. return _POSIX2_SW_DEV;
  557. #else
  558. RETURN_NEG_1;
  559. #endif
  560. case _SC_2_CHAR_TERM:
  561. #ifdef _POSIX2_CHAR_TERM
  562. return _POSIX2_CHAR_TERM;
  563. #else
  564. RETURN_NEG_1;
  565. #endif
  566. case _SC_2_UPE:
  567. #ifdef _POSIX2_UPE
  568. return _POSIX2_UPE;
  569. #else
  570. RETURN_NEG_1;
  571. #endif
  572. /* POSIX 1003.1c (POSIX Threads). */
  573. case _SC_THREADS:
  574. #ifdef __UCLIBC_HAS_THREADS__
  575. return 1;
  576. #else
  577. RETURN_NEG_1;
  578. #endif
  579. case _SC_THREAD_SAFE_FUNCTIONS:
  580. #ifdef __UCLIBC_HAS_THREADS__
  581. return 1;
  582. #else
  583. RETURN_NEG_1;
  584. #endif
  585. /* If you change these, also change libc/pwd_grp/pwd_grp.c to match */
  586. case _SC_GETGR_R_SIZE_MAX:
  587. return __UCLIBC_GRP_BUFFER_SIZE__;
  588. case _SC_GETPW_R_SIZE_MAX:
  589. return __UCLIBC_PWD_BUFFER_SIZE__;
  590. /* getlogin() is a worthless interface. In uClibc we let the user specify
  591. * whatever they want via the LOGNAME environment variable, or we return NULL
  592. * if getenv() fails to find anything. So this is merely how large a env
  593. * variable can be. Lets use 256 */
  594. case _SC_LOGIN_NAME_MAX:
  595. return 256;
  596. /* If you change this, also change _SC_TTY_NAME_MAX in libc/unistd/sysconf.c */
  597. #define TTYNAME_BUFLEN 32
  598. case _SC_TTY_NAME_MAX:
  599. return TTYNAME_BUFLEN;
  600. case _SC_THREAD_DESTRUCTOR_ITERATIONS:
  601. #ifdef _POSIX_THREAD_DESTRUCTOR_ITERATIONS
  602. return _POSIX_THREAD_DESTRUCTOR_ITERATIONS;
  603. #else
  604. RETURN_NEG_1;
  605. #endif
  606. case _SC_THREAD_KEYS_MAX:
  607. #ifdef PTHREAD_KEYS_MAX
  608. return PTHREAD_KEYS_MAX;
  609. #else
  610. RETURN_NEG_1;
  611. #endif
  612. case _SC_THREAD_STACK_MIN:
  613. #ifdef PTHREAD_STACK_MIN
  614. return PTHREAD_STACK_MIN;
  615. #else
  616. RETURN_NEG_1;
  617. #endif
  618. case _SC_THREAD_THREADS_MAX:
  619. #ifdef PTHREAD_THREADS_MAX
  620. return PTHREAD_THREADS_MAX;
  621. #else
  622. RETURN_NEG_1;
  623. #endif
  624. case _SC_THREAD_ATTR_STACKADDR:
  625. #ifdef _POSIX_THREAD_ATTR_STACKADDR
  626. return 1;
  627. #else
  628. RETURN_NEG_1;
  629. #endif
  630. case _SC_THREAD_ATTR_STACKSIZE:
  631. #ifdef _POSIX_THREAD_ATTR_STACKSIZE
  632. return 1;
  633. #else
  634. RETURN_NEG_1;
  635. #endif
  636. case _SC_THREAD_PRIORITY_SCHEDULING:
  637. #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
  638. return 1;
  639. #else
  640. RETURN_NEG_1;
  641. #endif
  642. case _SC_THREAD_PRIO_INHERIT:
  643. #ifdef _POSIX_THREAD_PRIO_INHERIT
  644. return 1;
  645. #else
  646. RETURN_NEG_1;
  647. #endif
  648. case _SC_THREAD_PRIO_PROTECT:
  649. #ifdef _POSIX_THREAD_PRIO_PROTECT
  650. return 1;
  651. #else
  652. RETURN_NEG_1;
  653. #endif
  654. case _SC_THREAD_PROCESS_SHARED:
  655. #ifdef _POSIX_THREAD_PROCESS_SHARED
  656. return 1;
  657. #else
  658. RETURN_NEG_1;
  659. #endif
  660. case _SC_NPROCESSORS_CONF:
  661. RETURN_FUNCTION(nprocessors_conf());
  662. case _SC_NPROCESSORS_ONLN:
  663. RETURN_FUNCTION(nprocessors_onln());
  664. case _SC_PHYS_PAGES:
  665. RETURN_FUNCTION(get_phys_pages());
  666. case _SC_AVPHYS_PAGES:
  667. RETURN_FUNCTION(get_avphys_pages());
  668. case _SC_ATEXIT_MAX:
  669. return __UCLIBC_MAX_ATEXIT;
  670. case _SC_PASS_MAX:
  671. /* We have no limit but since the return value might be used to
  672. allocate a buffer we restrict the value. */
  673. return BUFSIZ;
  674. case _SC_XOPEN_VERSION:
  675. return _XOPEN_VERSION;
  676. case _SC_XOPEN_XCU_VERSION:
  677. return _XOPEN_XCU_VERSION;
  678. case _SC_XOPEN_UNIX:
  679. return _XOPEN_UNIX;
  680. case _SC_XOPEN_CRYPT:
  681. #ifdef _XOPEN_CRYPT
  682. return _XOPEN_CRYPT;
  683. #else
  684. RETURN_NEG_1;
  685. #endif
  686. case _SC_XOPEN_ENH_I18N:
  687. #ifdef _XOPEN_ENH_I18N
  688. return _XOPEN_ENH_I18N;
  689. #else
  690. RETURN_NEG_1;
  691. #endif
  692. case _SC_XOPEN_SHM:
  693. #ifdef _XOPEN_SHM
  694. return _XOPEN_SHM;
  695. #else
  696. RETURN_NEG_1;
  697. #endif
  698. case _SC_XOPEN_XPG2:
  699. #ifdef _XOPEN_XPG2
  700. return _XOPEN_XPG2;
  701. #else
  702. RETURN_NEG_1;
  703. #endif
  704. case _SC_XOPEN_XPG3:
  705. #ifdef _XOPEN_XPG3
  706. return _XOPEN_XPG3;
  707. #else
  708. RETURN_NEG_1;
  709. #endif
  710. case _SC_XOPEN_XPG4:
  711. #ifdef _XOPEN_XPG4
  712. return _XOPEN_XPG4;
  713. #else
  714. RETURN_NEG_1;
  715. #endif
  716. case _SC_CHAR_BIT:
  717. return CHAR_BIT;
  718. case _SC_CHAR_MAX:
  719. return CHAR_MAX;
  720. case _SC_CHAR_MIN:
  721. return CHAR_MIN;
  722. case _SC_INT_MAX:
  723. return INT_MAX;
  724. case _SC_INT_MIN:
  725. return INT_MIN;
  726. case _SC_LONG_BIT:
  727. return sizeof (long int) * CHAR_BIT;
  728. case _SC_WORD_BIT:
  729. return sizeof (int) * CHAR_BIT;
  730. case _SC_MB_LEN_MAX:
  731. return MB_LEN_MAX;
  732. case _SC_NZERO:
  733. return NZERO;
  734. case _SC_SSIZE_MAX:
  735. return _POSIX_SSIZE_MAX;
  736. case _SC_SCHAR_MAX:
  737. return SCHAR_MAX;
  738. case _SC_SCHAR_MIN:
  739. return SCHAR_MIN;
  740. case _SC_SHRT_MAX:
  741. return SHRT_MAX;
  742. case _SC_SHRT_MIN:
  743. return SHRT_MIN;
  744. case _SC_UCHAR_MAX:
  745. return UCHAR_MAX;
  746. case _SC_UINT_MAX:
  747. return UINT_MAX;
  748. case _SC_ULONG_MAX:
  749. return ULONG_MAX;
  750. case _SC_USHRT_MAX:
  751. return USHRT_MAX;
  752. case _SC_NL_ARGMAX:
  753. #ifdef NL_ARGMAX
  754. return NL_ARGMAX;
  755. #else
  756. RETURN_NEG_1;
  757. #endif
  758. case _SC_NL_LANGMAX:
  759. #ifdef NL_LANGMAX
  760. return NL_LANGMAX;
  761. #else
  762. RETURN_NEG_1;
  763. #endif
  764. case _SC_NL_MSGMAX:
  765. #ifdef NL_MSGMAX
  766. return NL_MSGMAX;
  767. #else
  768. RETURN_NEG_1;
  769. #endif
  770. case _SC_NL_NMAX:
  771. #ifdef NL_NMAX
  772. return NL_NMAX;
  773. #else
  774. RETURN_NEG_1;
  775. #endif
  776. case _SC_NL_SETMAX:
  777. #ifdef NL_SETMAX
  778. return NL_SETMAX;
  779. #else
  780. RETURN_NEG_1;
  781. #endif
  782. case _SC_NL_TEXTMAX:
  783. #ifdef NL_TEXTMAX
  784. return NL_TEXTMAX;
  785. #else
  786. RETURN_NEG_1;
  787. #endif
  788. case _SC_XBS5_ILP32_OFF32:
  789. #ifdef _XBS5_ILP32_OFF32
  790. return _XBS5_ILP32_OFF32;
  791. #else
  792. RETURN_NEG_1;
  793. #endif
  794. case _SC_XBS5_ILP32_OFFBIG:
  795. #ifdef _XBS5_ILP32_OFFBIG
  796. return _XBS5_ILP32_OFFBIG;
  797. #else
  798. RETURN_NEG_1;
  799. #endif
  800. case _SC_XBS5_LP64_OFF64:
  801. #ifdef _XBS5_LP64_OFF64
  802. return _XBS5_LP64_OFF64;
  803. #else
  804. RETURN_NEG_1;
  805. #endif
  806. case _SC_XBS5_LPBIG_OFFBIG:
  807. #ifdef _XBS5_LPBIG_OFFBIG
  808. return _XBS5_LPBIG_OFFBIG;
  809. #else
  810. RETURN_NEG_1;
  811. #endif
  812. case _SC_V7_ILP32_OFF32:
  813. #ifdef _POSIX_V7_ILP32_OFF32
  814. return _POSIX_V7_ILP32_OFF32;
  815. #else
  816. RETURN_NEG_1;
  817. #endif
  818. case _SC_V7_ILP32_OFFBIG:
  819. #ifdef _POSIX_V7_ILP32_OFFBIG
  820. return _POSIX_V7_ILP32_OFFBIG;
  821. #else
  822. RETURN_NEG_1;
  823. #endif
  824. case _SC_V7_LP64_OFF64:
  825. #ifdef _POSIX_V7_LP64_OFF64
  826. return _POSIX_V7_LP64_OFF64;
  827. #else
  828. RETURN_NEG_1;
  829. #endif
  830. case _SC_V7_LPBIG_OFFBIG:
  831. #ifdef _POSIX_V7_LPBIG_OFFBIG
  832. return _POSIX_V7_LPBIG_OFFBIG;
  833. #else
  834. RETURN_NEG_1;
  835. #endif
  836. case _SC_XOPEN_LEGACY:
  837. return _XOPEN_LEGACY;
  838. case _SC_XOPEN_REALTIME:
  839. #ifdef _XOPEN_REALTIME
  840. return _XOPEN_REALTIME;
  841. #else
  842. RETURN_NEG_1;
  843. #endif
  844. case _SC_XOPEN_REALTIME_THREADS:
  845. #ifdef _XOPEN_REALTIME_THREADS
  846. return _XOPEN_REALTIME_THREADS;
  847. #else
  848. RETURN_NEG_1;
  849. #endif
  850. case _SC_MONOTONIC_CLOCK:
  851. #if defined __UCLIBC_HAS_REALTIME__ && defined __NR_clock_getres
  852. if (clock_getres(CLOCK_MONOTONIC, NULL) >= 0)
  853. return _POSIX_VERSION;
  854. #endif
  855. RETURN_NEG_1;
  856. #ifdef __UCLIBC_HAS_THREADS_NATIVE__
  857. case _SC_THREAD_CPUTIME:
  858. # if _POSIX_THREAD_CPUTIME > 0
  859. return _POSIX_THREAD_CPUTIME;
  860. # else
  861. RETURN_NEG_1;
  862. # endif
  863. #endif
  864. }
  865. }
  866. libc_hidden_def(sysconf)