sysconf.c 17 KB

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