sysconf.c 18 KB

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