sysconf.c 19 KB

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