sysconf.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059
  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. extern int getpagesize (void);
  30. extern int getdtablesize (void);
  31. /***********************************************************************/
  32. /*
  33. * Manuel Novoa III Jan 2001
  34. *
  35. * On i386, the switch-based implementation generates 796 bytes of code.
  36. * However, many of the return values are repeats. By collecting these
  37. * repeats and moving to a table-based implementation, we generate 283
  38. * bytes on i386 (-Os -fomit-frame-pointer).
  39. */
  40. #ifndef _UCLIBC_GENERATE_SYSCONF_MAIN
  41. #ifdef _UCLIBC_GENERATE_SYSCONF_ARCH
  42. /*
  43. * Set some errno's so the auto-gen code knows what it is dealing with.
  44. * 1) ENOSYS signifies that we're returning a default value.
  45. * This is just extra info for development.
  46. * 2) EISNAM signifies that the value returned varies at runtime.
  47. *
  48. * Option: GETPAGESIZE_IS_DYNAMIC
  49. * The current implementation of getpagesize in uClibc returns
  50. * a constant. The pagesize on the target arch should not vary,
  51. * so it should be safe to set this as 0.
  52. */
  53. #define RETURN_NEG_1 __set_errno(ENOSYS); return -1
  54. #define RETURN_FUNCTION(f) __set_errno(EISNAM); return (long int) #f
  55. #define GETPAGESIZE_IS_DYNAMIC 0
  56. #else
  57. #define RETURN_NEG_1 return -1
  58. #define RETURN_FUNCTION(f) return f;
  59. #endif /* _UCLIBC_GENERATE_SYSCONF_ARCH */
  60. /* Get the value of the system variable NAME. */
  61. long int __sysconf(int name)
  62. {
  63. switch (name)
  64. {
  65. default:
  66. __set_errno(EINVAL);
  67. return -1;
  68. case _SC_ARG_MAX:
  69. #ifdef ARG_MAX
  70. return ARG_MAX;
  71. #else
  72. RETURN_NEG_1;
  73. #endif
  74. case _SC_CHILD_MAX:
  75. #ifdef CHILD_MAX
  76. return CHILD_MAX;
  77. #else
  78. RETURN_NEG_1;
  79. #endif
  80. case _SC_CLK_TCK:
  81. #ifdef CLK_TCK
  82. return CLK_TCK;
  83. #else
  84. return 60;
  85. #endif
  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