sysconf.c 20 KB

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