Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

848 lines
25KB

  1. /* This header file provides the reentrancy. */
  2. /* WARNING: All identifiers here must begin with an underscore. This file is
  3. included by stdio.h and others and we therefore must only use identifiers
  4. in the namespace allotted to us. */
  5. #ifndef _SYS_REENT_H_
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. #define _SYS_REENT_H_
  10. #include <_ansi.h>
  11. #include <stddef.h>
  12. #include <sys/_types.h>
  13. #define _NULL 0
  14. #ifndef __Long
  15. #if __LONG_MAX__ == 2147483647L
  16. #define __Long long
  17. typedef unsigned __Long __ULong;
  18. #elif __INT_MAX__ == 2147483647
  19. #define __Long int
  20. typedef unsigned __Long __ULong;
  21. #endif
  22. #endif
  23. #if !defined( __Long)
  24. #include <sys/types.h>
  25. #endif
  26. #ifndef __machine_flock_t_defined
  27. #include <sys/lock.h>
  28. typedef _LOCK_RECURSIVE_T _flock_t;
  29. #endif
  30. #ifndef __Long
  31. #define __Long __int32_t
  32. typedef __uint32_t __ULong;
  33. #endif
  34. struct _reent;
  35. struct __locale_t;
  36. /*
  37. * If _REENT_SMALL is defined, we make struct _reent as small as possible,
  38. * by having nearly everything possible allocated at first use.
  39. */
  40. struct _Bigint
  41. {
  42. struct _Bigint *_next;
  43. int _k, _maxwds, _sign, _wds;
  44. __ULong _x[1];
  45. };
  46. /* needed by reentrant structure */
  47. struct __tm
  48. {
  49. int __tm_sec;
  50. int __tm_min;
  51. int __tm_hour;
  52. int __tm_mday;
  53. int __tm_mon;
  54. int __tm_year;
  55. int __tm_wday;
  56. int __tm_yday;
  57. int __tm_isdst;
  58. };
  59. /*
  60. * atexit() support.
  61. */
  62. #define _ATEXIT_SIZE 32 /* must be at least 32 to guarantee ANSI conformance */
  63. struct _on_exit_args {
  64. void * _fnargs[_ATEXIT_SIZE]; /* user fn args */
  65. void * _dso_handle[_ATEXIT_SIZE];
  66. /* Bitmask is set if user function takes arguments. */
  67. __ULong _fntypes; /* type of exit routine -
  68. Must have at least _ATEXIT_SIZE bits */
  69. /* Bitmask is set if function was registered via __cxa_atexit. */
  70. __ULong _is_cxa;
  71. };
  72. #ifdef _REENT_SMALL
  73. struct _atexit {
  74. struct _atexit *_next; /* next in list */
  75. int _ind; /* next index in this table */
  76. void (*_fns[_ATEXIT_SIZE])(void); /* the table itself */
  77. struct _on_exit_args * _on_exit_args_ptr;
  78. };
  79. # define _ATEXIT_INIT {_NULL, 0, {_NULL}, _NULL}
  80. #else
  81. struct _atexit {
  82. struct _atexit *_next; /* next in list */
  83. int _ind; /* next index in this table */
  84. /* Some entries may already have been called, and will be NULL. */
  85. void (*_fns[_ATEXIT_SIZE])(void); /* the table itself */
  86. struct _on_exit_args _on_exit_args;
  87. };
  88. # define _ATEXIT_INIT {_NULL, 0, {_NULL}, {{_NULL}, {_NULL}, 0, 0}}
  89. #endif
  90. #ifdef _REENT_GLOBAL_ATEXIT
  91. # define _REENT_INIT_ATEXIT
  92. #else
  93. # define _REENT_INIT_ATEXIT \
  94. _NULL, _ATEXIT_INIT,
  95. #endif
  96. /*
  97. * Stdio buffers.
  98. *
  99. * This and __FILE are defined here because we need them for struct _reent,
  100. * but we don't want stdio.h included when stdlib.h is.
  101. */
  102. struct __sbuf {
  103. unsigned char *_base;
  104. int _size;
  105. };
  106. /*
  107. * Stdio state variables.
  108. *
  109. * The following always hold:
  110. *
  111. * if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR),
  112. * _lbfsize is -_bf._size, else _lbfsize is 0
  113. * if _flags&__SRD, _w is 0
  114. * if _flags&__SWR, _r is 0
  115. *
  116. * This ensures that the getc and putc macros (or inline functions) never
  117. * try to write or read from a file that is in `read' or `write' mode.
  118. * (Moreover, they can, and do, automatically switch from read mode to
  119. * write mode, and back, on "r+" and "w+" files.)
  120. *
  121. * _lbfsize is used only to make the inline line-buffered output stream
  122. * code as compact as possible.
  123. *
  124. * _ub, _up, and _ur are used when ungetc() pushes back more characters
  125. * than fit in the current _bf, or when ungetc() pushes back a character
  126. * that does not match the previous one in _bf. When this happens,
  127. * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff
  128. * _ub._base!=NULL) and _up and _ur save the current values of _p and _r.
  129. */
  130. #if defined(_REENT_SMALL) && !defined(_REENT_GLOBAL_STDIO_STREAMS)
  131. /*
  132. * struct __sFILE_fake is the start of a struct __sFILE, with only the
  133. * minimal fields allocated. In __sinit() we really allocate the 3
  134. * standard streams, etc., and point away from this fake.
  135. */
  136. struct __sFILE_fake {
  137. unsigned char *_p; /* current position in (some) buffer */
  138. int _r; /* read space left for getc() */
  139. int _w; /* write space left for putc() */
  140. short _flags; /* flags, below; this FILE is free if 0 */
  141. short _file; /* fileno, if Unix descriptor, else -1 */
  142. struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */
  143. int _lbfsize; /* 0 or -_bf._size, for inline putc */
  144. struct _reent *_data;
  145. };
  146. /* Following is needed both in libc/stdio and libc/stdlib so we put it
  147. * here instead of libc/stdio/local.h where it was previously. */
  148. extern void __sinit (struct _reent *);
  149. # define _REENT_SMALL_CHECK_INIT(ptr) \
  150. do \
  151. { \
  152. if ((ptr) && !(ptr)->__sdidinit) \
  153. __sinit (ptr); \
  154. } \
  155. while (0)
  156. #else /* _REENT_SMALL && !_REENT_GLOBAL_STDIO_STREAMS */
  157. # define _REENT_SMALL_CHECK_INIT(ptr) /* nothing */
  158. #endif /* _REENT_SMALL && !_REENT_GLOBAL_STDIO_STREAMS */
  159. struct __sFILE {
  160. unsigned char *_p; /* current position in (some) buffer */
  161. int _r; /* read space left for getc() */
  162. int _w; /* write space left for putc() */
  163. short _flags; /* flags, below; this FILE is free if 0 */
  164. short _file; /* fileno, if Unix descriptor, else -1 */
  165. struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */
  166. int _lbfsize; /* 0 or -_bf._size, for inline putc */
  167. #ifdef _REENT_SMALL
  168. struct _reent *_data;
  169. #endif
  170. /* operations */
  171. void * _cookie; /* cookie passed to io functions */
  172. _READ_WRITE_RETURN_TYPE (*_read) (struct _reent *, void *,
  173. char *, _READ_WRITE_BUFSIZE_TYPE);
  174. _READ_WRITE_RETURN_TYPE (*_write) (struct _reent *, void *,
  175. const char *,
  176. _READ_WRITE_BUFSIZE_TYPE);
  177. _fpos_t (*_seek) (struct _reent *, void *, _fpos_t, int);
  178. int (*_close) (struct _reent *, void *);
  179. /* separate buffer for long sequences of ungetc() */
  180. struct __sbuf _ub; /* ungetc buffer */
  181. unsigned char *_up; /* saved _p when _p is doing ungetc data */
  182. int _ur; /* saved _r when _r is counting ungetc data */
  183. /* tricks to meet minimum requirements even when malloc() fails */
  184. unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */
  185. unsigned char _nbuf[1]; /* guarantee a getc() buffer */
  186. /* separate buffer for fgetline() when line crosses buffer boundary */
  187. struct __sbuf _lb; /* buffer for fgetline() */
  188. /* Unix stdio files get aligned to block boundaries on fseek() */
  189. int _blksize; /* stat.st_blksize (may be != _bf._size) */
  190. _off_t _offset; /* current lseek offset */
  191. #ifndef _REENT_SMALL
  192. struct _reent *_data; /* Here for binary compatibility? Remove? */
  193. #endif
  194. #ifndef __SINGLE_THREAD__
  195. _flock_t _lock; /* for thread-safety locking */
  196. #endif
  197. _mbstate_t _mbstate; /* for wide char stdio functions. */
  198. int _flags2; /* for future use */
  199. };
  200. #ifdef __CUSTOM_FILE_IO__
  201. /* Get custom _FILE definition. */
  202. #include <sys/custom_file.h>
  203. #else /* !__CUSTOM_FILE_IO__ */
  204. #ifdef __LARGE64_FILES
  205. struct __sFILE64 {
  206. unsigned char *_p; /* current position in (some) buffer */
  207. int _r; /* read space left for getc() */
  208. int _w; /* write space left for putc() */
  209. short _flags; /* flags, below; this FILE is free if 0 */
  210. short _file; /* fileno, if Unix descriptor, else -1 */
  211. struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */
  212. int _lbfsize; /* 0 or -_bf._size, for inline putc */
  213. struct _reent *_data;
  214. /* operations */
  215. void * _cookie; /* cookie passed to io functions */
  216. _READ_WRITE_RETURN_TYPE (*_read) (struct _reent *, void *,
  217. char *, _READ_WRITE_BUFSIZE_TYPE);
  218. _READ_WRITE_RETURN_TYPE (*_write) (struct _reent *, void *,
  219. const char *,
  220. _READ_WRITE_BUFSIZE_TYPE);
  221. _fpos_t (*_seek) (struct _reent *, void *, _fpos_t, int);
  222. int (*_close) (struct _reent *, void *);
  223. /* separate buffer for long sequences of ungetc() */
  224. struct __sbuf _ub; /* ungetc buffer */
  225. unsigned char *_up; /* saved _p when _p is doing ungetc data */
  226. int _ur; /* saved _r when _r is counting ungetc data */
  227. /* tricks to meet minimum requirements even when malloc() fails */
  228. unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */
  229. unsigned char _nbuf[1]; /* guarantee a getc() buffer */
  230. /* separate buffer for fgetline() when line crosses buffer boundary */
  231. struct __sbuf _lb; /* buffer for fgetline() */
  232. /* Unix stdio files get aligned to block boundaries on fseek() */
  233. int _blksize; /* stat.st_blksize (may be != _bf._size) */
  234. int _flags2; /* for future use */
  235. _off64_t _offset; /* current lseek offset */
  236. _fpos64_t (*_seek64) (struct _reent *, void *, _fpos64_t, int);
  237. #ifndef __SINGLE_THREAD__
  238. _flock_t _lock; /* for thread-safety locking */
  239. #endif
  240. _mbstate_t _mbstate; /* for wide char stdio functions. */
  241. };
  242. typedef struct __sFILE64 __FILE;
  243. #else
  244. typedef struct __sFILE __FILE;
  245. #endif /* __LARGE64_FILES */
  246. #endif /* !__CUSTOM_FILE_IO__ */
  247. struct _glue
  248. {
  249. struct _glue *_next;
  250. int _niobs;
  251. __FILE *_iobs;
  252. };
  253. /*
  254. * rand48 family support
  255. *
  256. * Copyright (c) 1993 Martin Birgmeier
  257. * All rights reserved.
  258. *
  259. * You may redistribute unmodified or modified versions of this source
  260. * code provided that the above copyright notice and this and the
  261. * following conditions are retained.
  262. *
  263. * This software is provided ``as is'', and comes with no warranties
  264. * of any kind. I shall in no event be liable for anything that happens
  265. * to anyone/anything when using this software.
  266. */
  267. #define _RAND48_SEED_0 (0x330e)
  268. #define _RAND48_SEED_1 (0xabcd)
  269. #define _RAND48_SEED_2 (0x1234)
  270. #define _RAND48_MULT_0 (0xe66d)
  271. #define _RAND48_MULT_1 (0xdeec)
  272. #define _RAND48_MULT_2 (0x0005)
  273. #define _RAND48_ADD (0x000b)
  274. struct _rand48 {
  275. unsigned short _seed[3];
  276. unsigned short _mult[3];
  277. unsigned short _add;
  278. #ifdef _REENT_SMALL
  279. /* Put this in here as well, for good luck. */
  280. __extension__ unsigned long long _rand_next;
  281. #endif
  282. };
  283. /* How big the some arrays are. */
  284. #define _REENT_EMERGENCY_SIZE 25
  285. #define _REENT_ASCTIME_SIZE 26
  286. #define _REENT_SIGNAL_SIZE 24
  287. /*
  288. * struct _reent
  289. *
  290. * This structure contains *all* globals needed by the library.
  291. * It's raison d'etre is to facilitate threads by making all library routines
  292. * reentrant. IE: All state information is contained here.
  293. */
  294. #ifdef _REENT_SMALL
  295. struct _mprec
  296. {
  297. /* used by mprec routines */
  298. struct _Bigint *_result;
  299. int _result_k;
  300. struct _Bigint *_p5s;
  301. struct _Bigint **_freelist;
  302. };
  303. struct _misc_reent
  304. {
  305. /* miscellaneous reentrant data */
  306. char *_strtok_last;
  307. _mbstate_t _mblen_state;
  308. _mbstate_t _wctomb_state;
  309. _mbstate_t _mbtowc_state;
  310. char _l64a_buf[8];
  311. int _getdate_err;
  312. _mbstate_t _mbrlen_state;
  313. _mbstate_t _mbrtowc_state;
  314. _mbstate_t _mbsrtowcs_state;
  315. _mbstate_t _wcrtomb_state;
  316. _mbstate_t _wcsrtombs_state;
  317. };
  318. /* This version of _reent is laid out with "int"s in pairs, to help
  319. * ports with 16-bit int's but 32-bit pointers, align nicely. */
  320. struct _reent
  321. {
  322. /* As an exception to the above put _errno first for binary
  323. compatibility with non _REENT_SMALL targets. */
  324. int _errno; /* local copy of errno */
  325. /* FILE is a big struct and may change over time. To try to achieve binary
  326. compatibility with future versions, put stdin,stdout,stderr here.
  327. These are pointers into member __sf defined below. */
  328. __FILE *_stdin, *_stdout, *_stderr; /* XXX */
  329. int _inc; /* used by tmpnam */
  330. char *_emergency;
  331. int __sdidinit; /* 1 means stdio has been init'd */
  332. int _unspecified_locale_info; /* unused, reserved for locale stuff */
  333. struct __locale_t *_locale;/* per-thread locale */
  334. struct _mprec *_mp;
  335. void (*__cleanup) (struct _reent *);
  336. int _gamma_signgam;
  337. /* used by some fp conversion routines */
  338. int _cvtlen; /* should be size_t */
  339. char *_cvtbuf;
  340. struct _rand48 *_r48;
  341. struct __tm *_localtime_buf;
  342. char *_asctime_buf;
  343. /* signal info */
  344. void (**(_sig_func))(int);
  345. # ifndef _REENT_GLOBAL_ATEXIT
  346. /* atexit stuff */
  347. struct _atexit *_atexit;
  348. struct _atexit _atexit0;
  349. # endif
  350. struct _glue __sglue; /* root of glue chain */
  351. __FILE *__sf; /* file descriptors */
  352. struct _misc_reent *_misc; /* strtok, multibyte states */
  353. char *_signal_buf; /* strsignal */
  354. };
  355. #ifdef _REENT_GLOBAL_STDIO_STREAMS
  356. extern __FILE __sf[3];
  357. # define _REENT_INIT(var) \
  358. { 0, \
  359. &__sf[0], \
  360. &__sf[1], \
  361. &__sf[2], \
  362. 0, \
  363. _NULL, \
  364. 0, \
  365. 0, \
  366. _NULL, \
  367. _NULL, \
  368. _NULL, \
  369. 0, \
  370. 0, \
  371. _NULL, \
  372. _NULL, \
  373. _NULL, \
  374. _NULL, \
  375. _NULL, \
  376. _REENT_INIT_ATEXIT \
  377. {_NULL, 0, _NULL}, \
  378. _NULL, \
  379. _NULL, \
  380. _NULL \
  381. }
  382. #define _REENT_INIT_PTR_ZEROED(var) \
  383. { (var)->_stdin = &__sf[0]; \
  384. (var)->_stdout = &__sf[1]; \
  385. (var)->_stderr = &__sf[2]; \
  386. }
  387. #else /* _REENT_GLOBAL_STDIO_STREAMS */
  388. extern const struct __sFILE_fake __sf_fake_stdin;
  389. extern const struct __sFILE_fake __sf_fake_stdout;
  390. extern const struct __sFILE_fake __sf_fake_stderr;
  391. # define _REENT_INIT(var) \
  392. { 0, \
  393. (__FILE *)&__sf_fake_stdin, \
  394. (__FILE *)&__sf_fake_stdout, \
  395. (__FILE *)&__sf_fake_stderr, \
  396. 0, \
  397. _NULL, \
  398. 0, \
  399. 0, \
  400. _NULL, \
  401. _NULL, \
  402. _NULL, \
  403. 0, \
  404. 0, \
  405. _NULL, \
  406. _NULL, \
  407. _NULL, \
  408. _NULL, \
  409. _NULL, \
  410. _REENT_INIT_ATEXIT \
  411. {_NULL, 0, _NULL}, \
  412. _NULL, \
  413. _NULL, \
  414. _NULL \
  415. }
  416. #define _REENT_INIT_PTR_ZEROED(var) \
  417. { (var)->_stdin = (__FILE *)&__sf_fake_stdin; \
  418. (var)->_stdout = (__FILE *)&__sf_fake_stdout; \
  419. (var)->_stderr = (__FILE *)&__sf_fake_stderr; \
  420. }
  421. #endif /* _REENT_GLOBAL_STDIO_STREAMS */
  422. /* Specify how to handle reent_check malloc failures. */
  423. #ifdef _REENT_CHECK_VERIFY
  424. #include <assert.h>
  425. #define __reent_assert(x) ((x) ? (void)0 : __assert_func(__FILE__, __LINE__, (char *)0, "REENT malloc succeeded"))
  426. #else
  427. #define __reent_assert(x) ((void)0)
  428. #endif
  429. #ifdef __CUSTOM_FILE_IO__
  430. #error Custom FILE I/O and _REENT_SMALL not currently supported.
  431. #endif
  432. /* Generic _REENT check macro. */
  433. #define _REENT_CHECK(var, what, type, size, init) do { \
  434. struct _reent *_r = (var); \
  435. if (_r->what == NULL) { \
  436. _r->what = (type)malloc(size); \
  437. __reent_assert(_r->what); \
  438. init; \
  439. } \
  440. } while (0)
  441. #define _REENT_CHECK_TM(var) \
  442. _REENT_CHECK(var, _localtime_buf, struct __tm *, sizeof *((var)->_localtime_buf), \
  443. /* nothing */)
  444. #define _REENT_CHECK_ASCTIME_BUF(var) \
  445. _REENT_CHECK(var, _asctime_buf, char *, _REENT_ASCTIME_SIZE, \
  446. memset((var)->_asctime_buf, 0, _REENT_ASCTIME_SIZE))
  447. /* Handle the dynamically allocated rand48 structure. */
  448. #define _REENT_INIT_RAND48(var) do { \
  449. struct _reent *_r = (var); \
  450. _r->_r48->_seed[0] = _RAND48_SEED_0; \
  451. _r->_r48->_seed[1] = _RAND48_SEED_1; \
  452. _r->_r48->_seed[2] = _RAND48_SEED_2; \
  453. _r->_r48->_mult[0] = _RAND48_MULT_0; \
  454. _r->_r48->_mult[1] = _RAND48_MULT_1; \
  455. _r->_r48->_mult[2] = _RAND48_MULT_2; \
  456. _r->_r48->_add = _RAND48_ADD; \
  457. _r->_r48->_rand_next = 1; \
  458. } while (0)
  459. #define _REENT_CHECK_RAND48(var) \
  460. _REENT_CHECK(var, _r48, struct _rand48 *, sizeof *((var)->_r48), _REENT_INIT_RAND48((var)))
  461. #define _REENT_INIT_MP(var) do { \
  462. struct _reent *_r = (var); \
  463. _r->_mp->_result_k = 0; \
  464. _r->_mp->_result = _r->_mp->_p5s = _NULL; \
  465. _r->_mp->_freelist = _NULL; \
  466. } while (0)
  467. #define _REENT_CHECK_MP(var) \
  468. _REENT_CHECK(var, _mp, struct _mprec *, sizeof *((var)->_mp), _REENT_INIT_MP(var))
  469. #define _REENT_CHECK_EMERGENCY(var) \
  470. _REENT_CHECK(var, _emergency, char *, _REENT_EMERGENCY_SIZE, /* nothing */)
  471. #define _REENT_INIT_MISC(var) do { \
  472. struct _reent *_r = (var); \
  473. _r->_misc->_strtok_last = _NULL; \
  474. _r->_misc->_mblen_state.__count = 0; \
  475. _r->_misc->_mblen_state.__value.__wch = 0; \
  476. _r->_misc->_wctomb_state.__count = 0; \
  477. _r->_misc->_wctomb_state.__value.__wch = 0; \
  478. _r->_misc->_mbtowc_state.__count = 0; \
  479. _r->_misc->_mbtowc_state.__value.__wch = 0; \
  480. _r->_misc->_mbrlen_state.__count = 0; \
  481. _r->_misc->_mbrlen_state.__value.__wch = 0; \
  482. _r->_misc->_mbrtowc_state.__count = 0; \
  483. _r->_misc->_mbrtowc_state.__value.__wch = 0; \
  484. _r->_misc->_mbsrtowcs_state.__count = 0; \
  485. _r->_misc->_mbsrtowcs_state.__value.__wch = 0; \
  486. _r->_misc->_wcrtomb_state.__count = 0; \
  487. _r->_misc->_wcrtomb_state.__value.__wch = 0; \
  488. _r->_misc->_wcsrtombs_state.__count = 0; \
  489. _r->_misc->_wcsrtombs_state.__value.__wch = 0; \
  490. _r->_misc->_l64a_buf[0] = '\0'; \
  491. _r->_misc->_getdate_err = 0; \
  492. } while (0)
  493. #define _REENT_CHECK_MISC(var) \
  494. _REENT_CHECK(var, _misc, struct _misc_reent *, sizeof *((var)->_misc), _REENT_INIT_MISC(var))
  495. #define _REENT_CHECK_SIGNAL_BUF(var) \
  496. _REENT_CHECK(var, _signal_buf, char *, _REENT_SIGNAL_SIZE, /* nothing */)
  497. #define _REENT_SIGNGAM(ptr) ((ptr)->_gamma_signgam)
  498. #define _REENT_RAND_NEXT(ptr) ((ptr)->_r48->_rand_next)
  499. #define _REENT_RAND48_SEED(ptr) ((ptr)->_r48->_seed)
  500. #define _REENT_RAND48_MULT(ptr) ((ptr)->_r48->_mult)
  501. #define _REENT_RAND48_ADD(ptr) ((ptr)->_r48->_add)
  502. #define _REENT_MP_RESULT(ptr) ((ptr)->_mp->_result)
  503. #define _REENT_MP_RESULT_K(ptr) ((ptr)->_mp->_result_k)
  504. #define _REENT_MP_P5S(ptr) ((ptr)->_mp->_p5s)
  505. #define _REENT_MP_FREELIST(ptr) ((ptr)->_mp->_freelist)
  506. #define _REENT_ASCTIME_BUF(ptr) ((ptr)->_asctime_buf)
  507. #define _REENT_TM(ptr) ((ptr)->_localtime_buf)
  508. #define _REENT_EMERGENCY(ptr) ((ptr)->_emergency)
  509. #define _REENT_STRTOK_LAST(ptr) ((ptr)->_misc->_strtok_last)
  510. #define _REENT_MBLEN_STATE(ptr) ((ptr)->_misc->_mblen_state)
  511. #define _REENT_MBTOWC_STATE(ptr)((ptr)->_misc->_mbtowc_state)
  512. #define _REENT_WCTOMB_STATE(ptr)((ptr)->_misc->_wctomb_state)
  513. #define _REENT_MBRLEN_STATE(ptr) ((ptr)->_misc->_mbrlen_state)
  514. #define _REENT_MBRTOWC_STATE(ptr) ((ptr)->_misc->_mbrtowc_state)
  515. #define _REENT_MBSRTOWCS_STATE(ptr) ((ptr)->_misc->_mbsrtowcs_state)
  516. #define _REENT_WCRTOMB_STATE(ptr) ((ptr)->_misc->_wcrtomb_state)
  517. #define _REENT_WCSRTOMBS_STATE(ptr) ((ptr)->_misc->_wcsrtombs_state)
  518. #define _REENT_L64A_BUF(ptr) ((ptr)->_misc->_l64a_buf)
  519. #define _REENT_GETDATE_ERR_P(ptr) (&((ptr)->_misc->_getdate_err))
  520. #define _REENT_SIGNAL_BUF(ptr) ((ptr)->_signal_buf)
  521. #else /* !_REENT_SMALL */
  522. struct _reent
  523. {
  524. int _errno; /* local copy of errno */
  525. /* FILE is a big struct and may change over time. To try to achieve binary
  526. compatibility with future versions, put stdin,stdout,stderr here.
  527. These are pointers into member __sf defined below. */
  528. __FILE *_stdin, *_stdout, *_stderr;
  529. int _inc; /* used by tmpnam */
  530. char _emergency[_REENT_EMERGENCY_SIZE];
  531. /* TODO */
  532. int _unspecified_locale_info; /* unused, reserved for locale stuff */
  533. struct __locale_t *_locale;/* per-thread locale */
  534. int __sdidinit; /* 1 means stdio has been init'd */
  535. void (*__cleanup) (struct _reent *);
  536. /* used by mprec routines */
  537. struct _Bigint *_result;
  538. int _result_k;
  539. struct _Bigint *_p5s;
  540. struct _Bigint **_freelist;
  541. /* used by some fp conversion routines */
  542. int _cvtlen; /* should be size_t */
  543. char *_cvtbuf;
  544. union
  545. {
  546. struct
  547. {
  548. unsigned int _unused_rand;
  549. char * _strtok_last;
  550. char _asctime_buf[_REENT_ASCTIME_SIZE];
  551. struct __tm _localtime_buf;
  552. int _gamma_signgam;
  553. __extension__ unsigned long long _rand_next;
  554. struct _rand48 _r48;
  555. _mbstate_t _mblen_state;
  556. _mbstate_t _mbtowc_state;
  557. _mbstate_t _wctomb_state;
  558. char _l64a_buf[8];
  559. char _signal_buf[_REENT_SIGNAL_SIZE];
  560. int _getdate_err;
  561. _mbstate_t _mbrlen_state;
  562. _mbstate_t _mbrtowc_state;
  563. _mbstate_t _mbsrtowcs_state;
  564. _mbstate_t _wcrtomb_state;
  565. _mbstate_t _wcsrtombs_state;
  566. int _h_errno;
  567. } _reent;
  568. /* Two next two fields were once used by malloc. They are no longer
  569. used. They are used to preserve the space used before so as to
  570. allow addition of new reent fields and keep binary compatibility. */
  571. struct
  572. {
  573. #define _N_LISTS 30
  574. unsigned char * _nextf[_N_LISTS];
  575. unsigned int _nmalloc[_N_LISTS];
  576. } _unused;
  577. } _new;
  578. # ifndef _REENT_GLOBAL_ATEXIT
  579. /* atexit stuff */
  580. struct _atexit *_atexit; /* points to head of LIFO stack */
  581. struct _atexit _atexit0; /* one guaranteed table, required by ANSI */
  582. # endif
  583. /* signal info */
  584. void (**(_sig_func))(int);
  585. /* These are here last so that __FILE can grow without changing the offsets
  586. of the above members (on the off chance that future binary compatibility
  587. would be broken otherwise). */
  588. struct _glue __sglue; /* root of glue chain */
  589. # ifndef _REENT_GLOBAL_STDIO_STREAMS
  590. __FILE __sf[3]; /* first three file descriptors */
  591. # endif
  592. };
  593. #ifdef _REENT_GLOBAL_STDIO_STREAMS
  594. extern __FILE __sf[3];
  595. #define _REENT_STDIO_STREAM(var, index) &__sf[index]
  596. #else
  597. #define _REENT_STDIO_STREAM(var, index) &(var)->__sf[index]
  598. #endif
  599. #define _REENT_INIT(var) \
  600. { 0, \
  601. _REENT_STDIO_STREAM(&(var), 0), \
  602. _REENT_STDIO_STREAM(&(var), 1), \
  603. _REENT_STDIO_STREAM(&(var), 2), \
  604. 0, \
  605. "", \
  606. 0, \
  607. _NULL, \
  608. 0, \
  609. _NULL, \
  610. _NULL, \
  611. 0, \
  612. _NULL, \
  613. _NULL, \
  614. 0, \
  615. _NULL, \
  616. { \
  617. { \
  618. 0, \
  619. _NULL, \
  620. "", \
  621. {0, 0, 0, 0, 0, 0, 0, 0, 0}, \
  622. 0, \
  623. 1, \
  624. { \
  625. {_RAND48_SEED_0, _RAND48_SEED_1, _RAND48_SEED_2}, \
  626. {_RAND48_MULT_0, _RAND48_MULT_1, _RAND48_MULT_2}, \
  627. _RAND48_ADD \
  628. }, \
  629. {0, {0}}, \
  630. {0, {0}}, \
  631. {0, {0}}, \
  632. "", \
  633. "", \
  634. 0, \
  635. {0, {0}}, \
  636. {0, {0}}, \
  637. {0, {0}}, \
  638. {0, {0}}, \
  639. {0, {0}} \
  640. } \
  641. }, \
  642. _REENT_INIT_ATEXIT \
  643. _NULL, \
  644. {_NULL, 0, _NULL} \
  645. }
  646. #define _REENT_INIT_PTR_ZEROED(var) \
  647. { (var)->_stdin = _REENT_STDIO_STREAM(var, 0); \
  648. (var)->_stdout = _REENT_STDIO_STREAM(var, 1); \
  649. (var)->_stderr = _REENT_STDIO_STREAM(var, 2); \
  650. (var)->_new._reent._rand_next = 1; \
  651. (var)->_new._reent._r48._seed[0] = _RAND48_SEED_0; \
  652. (var)->_new._reent._r48._seed[1] = _RAND48_SEED_1; \
  653. (var)->_new._reent._r48._seed[2] = _RAND48_SEED_2; \
  654. (var)->_new._reent._r48._mult[0] = _RAND48_MULT_0; \
  655. (var)->_new._reent._r48._mult[1] = _RAND48_MULT_1; \
  656. (var)->_new._reent._r48._mult[2] = _RAND48_MULT_2; \
  657. (var)->_new._reent._r48._add = _RAND48_ADD; \
  658. }
  659. #define _REENT_CHECK_RAND48(ptr) /* nothing */
  660. #define _REENT_CHECK_MP(ptr) /* nothing */
  661. #define _REENT_CHECK_TM(ptr) /* nothing */
  662. #define _REENT_CHECK_ASCTIME_BUF(ptr) /* nothing */
  663. #define _REENT_CHECK_EMERGENCY(ptr) /* nothing */
  664. #define _REENT_CHECK_MISC(ptr) /* nothing */
  665. #define _REENT_CHECK_SIGNAL_BUF(ptr) /* nothing */
  666. #define _REENT_SIGNGAM(ptr) ((ptr)->_new._reent._gamma_signgam)
  667. #define _REENT_RAND_NEXT(ptr) ((ptr)->_new._reent._rand_next)
  668. #define _REENT_RAND48_SEED(ptr) ((ptr)->_new._reent._r48._seed)
  669. #define _REENT_RAND48_MULT(ptr) ((ptr)->_new._reent._r48._mult)
  670. #define _REENT_RAND48_ADD(ptr) ((ptr)->_new._reent._r48._add)
  671. #define _REENT_MP_RESULT(ptr) ((ptr)->_result)
  672. #define _REENT_MP_RESULT_K(ptr) ((ptr)->_result_k)
  673. #define _REENT_MP_P5S(ptr) ((ptr)->_p5s)
  674. #define _REENT_MP_FREELIST(ptr) ((ptr)->_freelist)
  675. #define _REENT_ASCTIME_BUF(ptr) ((ptr)->_new._reent._asctime_buf)
  676. #define _REENT_TM(ptr) (&(ptr)->_new._reent._localtime_buf)
  677. #define _REENT_EMERGENCY(ptr) ((ptr)->_emergency)
  678. #define _REENT_STRTOK_LAST(ptr) ((ptr)->_new._reent._strtok_last)
  679. #define _REENT_MBLEN_STATE(ptr) ((ptr)->_new._reent._mblen_state)
  680. #define _REENT_MBTOWC_STATE(ptr)((ptr)->_new._reent._mbtowc_state)
  681. #define _REENT_WCTOMB_STATE(ptr)((ptr)->_new._reent._wctomb_state)
  682. #define _REENT_MBRLEN_STATE(ptr)((ptr)->_new._reent._mbrlen_state)
  683. #define _REENT_MBRTOWC_STATE(ptr)((ptr)->_new._reent._mbrtowc_state)
  684. #define _REENT_MBSRTOWCS_STATE(ptr)((ptr)->_new._reent._mbsrtowcs_state)
  685. #define _REENT_WCRTOMB_STATE(ptr)((ptr)->_new._reent._wcrtomb_state)
  686. #define _REENT_WCSRTOMBS_STATE(ptr)((ptr)->_new._reent._wcsrtombs_state)
  687. #define _REENT_L64A_BUF(ptr) ((ptr)->_new._reent._l64a_buf)
  688. #define _REENT_SIGNAL_BUF(ptr) ((ptr)->_new._reent._signal_buf)
  689. #define _REENT_GETDATE_ERR_P(ptr) (&((ptr)->_new._reent._getdate_err))
  690. #endif /* !_REENT_SMALL */
  691. #define _REENT_INIT_PTR(var) \
  692. { memset((var), 0, sizeof(*(var))); \
  693. _REENT_INIT_PTR_ZEROED(var); \
  694. }
  695. /* This value is used in stdlib/misc.c. reent/reent.c has to know it
  696. as well to make sure the freelist is correctly free'd. Therefore
  697. we define it here, rather than in stdlib/misc.c, as before. */
  698. #define _Kmax (sizeof (size_t) << 3)
  699. /*
  700. * All references to struct _reent are via this pointer.
  701. * Internally, newlib routines that need to reference it should use _REENT.
  702. */
  703. #ifndef __ATTRIBUTE_IMPURE_PTR__
  704. #define __ATTRIBUTE_IMPURE_PTR__
  705. #endif
  706. extern struct _reent *_impure_ptr __ATTRIBUTE_IMPURE_PTR__;
  707. extern struct _reent *const _global_impure_ptr __ATTRIBUTE_IMPURE_PTR__;
  708. void _reclaim_reent (struct _reent *);
  709. /* #define _REENT_ONLY define this to get only reentrant routines */
  710. #if defined(__DYNAMIC_REENT__) && !defined(__SINGLE_THREAD__)
  711. #ifndef __getreent
  712. struct _reent * __getreent (void);
  713. #endif
  714. # define _REENT (__getreent())
  715. #else /* __SINGLE_THREAD__ || !__DYNAMIC_REENT__ */
  716. # define _REENT _impure_ptr
  717. #endif /* __SINGLE_THREAD__ || !__DYNAMIC_REENT__ */
  718. #define _GLOBAL_REENT _global_impure_ptr
  719. #ifdef _REENT_GLOBAL_ATEXIT
  720. extern struct _atexit *_global_atexit; /* points to head of LIFO stack */
  721. # define _GLOBAL_ATEXIT _global_atexit
  722. #else
  723. # define _GLOBAL_ATEXIT (_GLOBAL_REENT->_atexit)
  724. #endif
  725. #ifdef __cplusplus
  726. }
  727. #endif
  728. #endif /* _SYS_REENT_H_ */