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