sysconf.c 16 KB

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