sysconf.c 19 KB

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