sysconf.c 19 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061
  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. RETURN_NEG_1;
  583. #endif
  584. case _SC_NPROCESSORS_ONLN:
  585. #if 0
  586. RETURN_FUNCTION(get_nprocs());
  587. #else
  588. RETURN_NEG_1;
  589. #endif
  590. case _SC_PHYS_PAGES:
  591. #if 0
  592. RETURN_FUNCTION(get_phys_pages());
  593. #else
  594. RETURN_NEG_1;
  595. #endif
  596. case _SC_AVPHYS_PAGES:
  597. #if 0
  598. RETURN_FUNCTION(get_avphys_pages());
  599. #else
  600. RETURN_NEG_1;
  601. #endif
  602. case _SC_ATEXIT_MAX:
  603. return __UCLIBC_MAX_ATEXIT;
  604. case _SC_PASS_MAX:
  605. /* We have no limit but since the return value might be used to
  606. allocate a buffer we restrict the value. */
  607. return BUFSIZ;
  608. case _SC_XOPEN_VERSION:
  609. return _XOPEN_VERSION;
  610. case _SC_XOPEN_XCU_VERSION:
  611. return _XOPEN_XCU_VERSION;
  612. case _SC_XOPEN_UNIX:
  613. return _XOPEN_UNIX;
  614. case _SC_XOPEN_CRYPT:
  615. #ifdef _XOPEN_CRYPT
  616. return _XOPEN_CRYPT;
  617. #else
  618. RETURN_NEG_1;
  619. #endif
  620. case _SC_XOPEN_ENH_I18N:
  621. #ifdef _XOPEN_ENH_I18N
  622. return _XOPEN_ENH_I18N;
  623. #else
  624. RETURN_NEG_1;
  625. #endif
  626. case _SC_XOPEN_SHM:
  627. #ifdef _XOPEN_SHM
  628. return _XOPEN_SHM;
  629. #else
  630. RETURN_NEG_1;
  631. #endif
  632. case _SC_XOPEN_XPG2:
  633. #ifdef _XOPEN_XPG2
  634. return _XOPEN_XPG2;
  635. #else
  636. RETURN_NEG_1;
  637. #endif
  638. case _SC_XOPEN_XPG3:
  639. #ifdef _XOPEN_XPG3
  640. return _XOPEN_XPG3;
  641. #else
  642. RETURN_NEG_1;
  643. #endif
  644. case _SC_XOPEN_XPG4:
  645. #ifdef _XOPEN_XPG4
  646. return _XOPEN_XPG4;
  647. #else
  648. RETURN_NEG_1;
  649. #endif
  650. case _SC_CHAR_BIT:
  651. return CHAR_BIT;
  652. case _SC_CHAR_MAX:
  653. return CHAR_MAX;
  654. case _SC_CHAR_MIN:
  655. return CHAR_MIN;
  656. case _SC_INT_MAX:
  657. return INT_MAX;
  658. case _SC_INT_MIN:
  659. return INT_MIN;
  660. case _SC_LONG_BIT:
  661. return sizeof (long int) * CHAR_BIT;
  662. case _SC_WORD_BIT:
  663. return sizeof (int) * CHAR_BIT;
  664. case _SC_MB_LEN_MAX:
  665. return MB_LEN_MAX;
  666. case _SC_NZERO:
  667. return NZERO;
  668. case _SC_SSIZE_MAX:
  669. return _POSIX_SSIZE_MAX;
  670. case _SC_SCHAR_MAX:
  671. return SCHAR_MAX;
  672. case _SC_SCHAR_MIN:
  673. return SCHAR_MIN;
  674. case _SC_SHRT_MAX:
  675. return SHRT_MAX;
  676. case _SC_SHRT_MIN:
  677. return SHRT_MIN;
  678. case _SC_UCHAR_MAX:
  679. return UCHAR_MAX;
  680. case _SC_UINT_MAX:
  681. return UINT_MAX;
  682. case _SC_ULONG_MAX:
  683. return ULONG_MAX;
  684. case _SC_USHRT_MAX:
  685. return USHRT_MAX;
  686. case _SC_NL_ARGMAX:
  687. #ifdef NL_ARGMAX
  688. return NL_ARGMAX;
  689. #else
  690. RETURN_NEG_1;
  691. #endif
  692. case _SC_NL_LANGMAX:
  693. #ifdef NL_LANGMAX
  694. return NL_LANGMAX;
  695. #else
  696. RETURN_NEG_1;
  697. #endif
  698. case _SC_NL_MSGMAX:
  699. #ifdef NL_MSGMAX
  700. return NL_MSGMAX;
  701. #else
  702. RETURN_NEG_1;
  703. #endif
  704. case _SC_NL_NMAX:
  705. #ifdef NL_NMAX
  706. return NL_NMAX;
  707. #else
  708. RETURN_NEG_1;
  709. #endif
  710. case _SC_NL_SETMAX:
  711. #ifdef NL_SETMAX
  712. return NL_SETMAX;
  713. #else
  714. RETURN_NEG_1;
  715. #endif
  716. case _SC_NL_TEXTMAX:
  717. #ifdef NL_TEXTMAX
  718. return NL_TEXTMAX;
  719. #else
  720. RETURN_NEG_1;
  721. #endif
  722. case _SC_XBS5_ILP32_OFF32:
  723. #ifdef _XBS5_ILP32_OFF32
  724. return _XBS5_ILP32_OFF32;
  725. #else
  726. RETURN_NEG_1;
  727. #endif
  728. case _SC_XBS5_ILP32_OFFBIG:
  729. #ifdef _XBS5_ILP32_OFFBIG
  730. return _XBS5_ILP32_OFFBIG;
  731. #else
  732. RETURN_NEG_1;
  733. #endif
  734. case _SC_XBS5_LP64_OFF64:
  735. #ifdef _XBS5_LP64_OFF64
  736. return _XBS5_LP64_OFF64;
  737. #else
  738. RETURN_NEG_1;
  739. #endif
  740. case _SC_XBS5_LPBIG_OFFBIG:
  741. #ifdef _XBS5_LPBIG_OFFBIG
  742. return _XBS5_LPBIG_OFFBIG;
  743. #else
  744. RETURN_NEG_1;
  745. #endif
  746. case _SC_XOPEN_LEGACY:
  747. return _XOPEN_LEGACY;
  748. case _SC_XOPEN_REALTIME:
  749. #ifdef _XOPEN_REALTIME
  750. return _XOPEN_REALTIME;
  751. #else
  752. RETURN_NEG_1;
  753. #endif
  754. case _SC_XOPEN_REALTIME_THREADS:
  755. #ifdef _XOPEN_REALTIME_THREADS
  756. return _XOPEN_REALTIME_THREADS;
  757. #else
  758. RETURN_NEG_1;
  759. #endif
  760. }
  761. }
  762. weak_alias(__sysconf, sysconf);
  763. #endif /* _UCLIBC_GENERATE_SYSCONF_MAIN */
  764. /***********************************************************************/
  765. #ifdef _UCLIBC_GENERATE_SYSCONF_MAIN
  766. static long int ret_vals[_UCLIBC_SYSCONF_NUM_VALID_ARGS];
  767. static const char *type_str[] = {
  768. "char", "short", "int", "long"
  769. };
  770. static const char *type_fmt[] = { " %4ld", " %6ld", " %8ld", " %8ld" };
  771. static const int type_mod[] = { 13, 9, 6, 6 };
  772. static int find_or_add_in_table(int index, long int val, int *table,
  773. int *num_in_table, int add_flag)
  774. {
  775. int i;
  776. for (i=0 ; i<*num_in_table ; i++) {
  777. if (ret_vals[table[i]] == val) {
  778. return i;
  779. }
  780. }
  781. if (add_flag) {
  782. table[(*num_in_table)++] = index;
  783. return i;
  784. } else {
  785. return -1;
  786. }
  787. }
  788. int main(void)
  789. {
  790. long int r;
  791. int type_table[5][_UCLIBC_SYSCONF_NUM_VALID_ARGS];
  792. int ret_type[_UCLIBC_SYSCONF_NUM_VALID_ARGS];
  793. int num_type[5];
  794. int i, j, k, code;
  795. for (i=0 ; i<5 ; i++) {
  796. num_type[i] = 0;
  797. }
  798. for (i=0; i<_UCLIBC_SYSCONF_NUM_VALID_ARGS ; i++) {
  799. __set_errno(0);
  800. r = ret_vals[i] = sysconf(i);
  801. switch(errno) {
  802. case EINVAL: /* we're missing a case! */
  803. fprintf(stderr,"sysconf.c is broken! case %d missing!\n", i);
  804. return EXIT_FAILURE;
  805. case EISNAM: /* function */
  806. find_or_add_in_table(i,r,type_table[4],num_type+4,1);
  807. ret_type[i] = 4;
  808. break;
  809. case ENOSYS: /* defaults to -1 */
  810. /* why does this break for shared???? */
  811. fprintf(stderr,"gen_sysconf advisory --"
  812. "case %d defaults to -1\n", i);
  813. /* fall through */
  814. case 0:
  815. if ((r>=CHAR_MIN) && (r<=CHAR_MAX)) {
  816. ret_type[i] = 0;
  817. find_or_add_in_table(i,r,type_table[0],num_type+0,1);
  818. } else if ((r>=SHRT_MIN) && (r<=SHRT_MAX)) {
  819. ret_type[i] = 1;
  820. find_or_add_in_table(i,r,type_table[1],num_type+1,1);
  821. } else if ((r>=INT_MIN) && (r<=INT_MAX)) {
  822. ret_type[i] = 2;
  823. find_or_add_in_table(i,r,type_table[2],num_type+2,1);
  824. } else {
  825. ret_type[i] = 3;
  826. find_or_add_in_table(i,r,type_table[3],num_type+3,1);
  827. }
  828. break;
  829. default:
  830. fprintf(stderr,"sysconf.c is broken! errno = %d!\n", errno);
  831. break;
  832. }
  833. }
  834. printf("#include <errno.h>\n#include <unistd.h>\n#include <limits.h>\n\n");
  835. printf("static const unsigned char index[%d] = {",
  836. _UCLIBC_SYSCONF_NUM_VALID_ARGS);
  837. for (i=0 ; i<_UCLIBC_SYSCONF_NUM_VALID_ARGS ; i++) {
  838. if (i) printf(",");
  839. if (i%15 == 0) printf("\n");
  840. code = 0;
  841. for (j=0 ; j<4 ; j++) {
  842. k = find_or_add_in_table(i,ret_vals[i],type_table[j],num_type+j,0);
  843. if (k>=0) {
  844. code += k;
  845. break;
  846. }
  847. code += num_type[j];
  848. }
  849. printf(" %3d", code);
  850. }
  851. printf("\n};\n\n");
  852. for (j=0 ; j < 4 ; j++) {
  853. if (num_type[j]) {
  854. printf("static const %s %s_vals[%d] = {",
  855. type_str[j], type_str[j], num_type[j]);
  856. for (i = 0 ; i<num_type[j] ; i++) {
  857. if (i) printf(",");
  858. if (i%13 == 0) printf("\n");
  859. if (ret_vals[type_table[j][i]] == INT_MIN) {
  860. printf("%12s","INT_MIN");
  861. } else {
  862. printf(type_fmt[j], ret_vals[type_table[j][i]]);
  863. }
  864. }
  865. printf("\n};\n\n");
  866. }
  867. }
  868. printf("long int sysconf(int name)\n{\n\tint i;\n\n"
  869. "\tif ((name < 0) || (name >= %d)) {\n"
  870. "\t\terrno=EINVAL;\n"
  871. "\t\treturn -1;\n"
  872. "\t}\n\n", _UCLIBC_SYSCONF_NUM_VALID_ARGS);
  873. printf("\ti = index[name];\n\n");
  874. k = 0;
  875. for (i=0 ; i<4 ; i++) {
  876. if (num_type[i]) {
  877. if (k>0) {
  878. printf("\ti -= %d;\n", k);
  879. }
  880. printf("\tif (i < %d) {\n"
  881. "\t\treturn %s_vals[i];\n"
  882. "\t}\n\n",
  883. num_type[i], type_str[i]);
  884. k = num_type[i];
  885. }
  886. }
  887. if (num_type[4]) {
  888. if (k>0) {
  889. printf("\ti -= %d;\n", k);
  890. }
  891. printf("\tswitch(i) {\n");
  892. for (i = 0 ; i<num_type[4] ; i++) {
  893. printf("\t\tcase %d:\n"
  894. "\t\t\treturn %s;\n",
  895. i, (const char *)ret_vals[type_table[4][i]]);
  896. }
  897. printf("\t}\n\n");
  898. }
  899. printf("\treturn -1;\n"
  900. "}\n");
  901. return EXIT_SUCCESS;
  902. }
  903. /***********************************************************************/
  904. #endif