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