sysconf.c 17 KB

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