sysconf.c 19 KB

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