sysconf.c 19 KB

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