sysconf.c 19 KB

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