1 /* This header file provides the reentrancy. */
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. */
14 #include <sys/_types.h>
17 #if __LONG_MAX__ == 2147483647L
19 typedef unsigned __Long __ULong
;
20 #elif __INT_MAX__ == 2147483647
22 typedef unsigned __Long __ULong
;
27 #define __Long __int32_t
28 typedef __uint32_t __ULong
;
35 struct __sFILE
*_iobs
;
40 struct _Bigint
*_next
;
41 int _k
, _maxwds
, _sign
, _wds
;
45 /* needed by reentrant structure */
63 #define _ATEXIT_SIZE 32 /* must be at least 32 to guarantee ANSI conformance */
66 struct _atexit
*_next
; /* next in list */
67 int _ind
; /* next index in this table */
68 void (*_fns
[_ATEXIT_SIZE
])(void); /* the table itself */
74 * This and __sFILE are defined here because we need them for struct _reent,
75 * but we don't want stdio.h included when stdlib.h is.
84 * We need fpos_t for the following, but it doesn't have a leading "_",
85 * so we use _fpos_t instead.
88 typedef long _fpos_t
; /* XXX must match off_t in <sys/types.h> */
89 /* (and must be `long' for now) */
92 * Stdio state variables.
94 * The following always hold:
96 * if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR),
97 * _lbfsize is -_bf._size, else _lbfsize is 0
98 * if _flags&__SRD, _w is 0
99 * if _flags&__SWR, _r is 0
101 * This ensures that the getc and putc macros (or inline functions) never
102 * try to write or read from a file that is in `read' or `write' mode.
103 * (Moreover, they can, and do, automatically switch from read mode to
104 * write mode, and back, on "r+" and "w+" files.)
106 * _lbfsize is used only to make the inline line-buffered output stream
107 * code as compact as possible.
109 * _ub, _up, and _ur are used when ungetc() pushes back more characters
110 * than fit in the current _bf, or when ungetc() pushes back a character
111 * that does not match the previous one in _bf. When this happens,
112 * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff
113 * _ub._base!=NULL) and _up and _ur save the current values of _p and _r.
117 unsigned char *_p
; /* current position in (some) buffer */
118 int _r
; /* read space left for getc() */
119 int _w
; /* write space left for putc() */
120 short _flags
; /* flags, below; this FILE is free if 0 */
121 short _file
; /* fileno, if Unix descriptor, else -1 */
122 struct __sbuf _bf
; /* the buffer (at least 1 byte, if !NULL) */
123 int _lbfsize
; /* 0 or -_bf._size, for inline putc */
126 _PTR _cookie
; /* cookie passed to io functions */
128 _READ_WRITE_RETURN_TYPE
_EXFUN((*_read
),(_PTR _cookie
, char *_buf
, int _n
));
129 _READ_WRITE_RETURN_TYPE
_EXFUN((*_write
),(_PTR _cookie
, const char *_buf
,
131 _fpos_t
_EXFUN((*_seek
),(_PTR _cookie
, _fpos_t _offset
, int _whence
));
132 int _EXFUN((*_close
),(_PTR _cookie
));
134 /* separate buffer for long sequences of ungetc() */
135 struct __sbuf _ub
; /* ungetc buffer */
136 unsigned char *_up
; /* saved _p when _p is doing ungetc data */
137 int _ur
; /* saved _r when _r is counting ungetc data */
139 /* tricks to meet minimum requirements even when malloc() fails */
140 unsigned char _ubuf
[3]; /* guarantee an ungetc() buffer */
141 unsigned char _nbuf
[1]; /* guarantee a getc() buffer */
143 /* separate buffer for fgetline() when line crosses buffer boundary */
144 struct __sbuf _lb
; /* buffer for fgetline() */
146 /* Unix stdio files get aligned to block boundaries on fseek() */
147 int _blksize
; /* stat.st_blksize (may be != _bf._size) */
148 int _offset
; /* current lseek offset */
150 struct _reent
*_data
;
154 * rand48 family support
156 * Copyright (c) 1993 Martin Birgmeier
157 * All rights reserved.
159 * You may redistribute unmodified or modified versions of this source
160 * code provided that the above copyright notice and this and the
161 * following conditions are retained.
163 * This software is provided ``as is'', and comes with no warranties
164 * of any kind. I shall in no event be liable for anything that happens
165 * to anyone/anything when using this software.
167 #define _RAND48_SEED_0 (0x330e)
168 #define _RAND48_SEED_1 (0xabcd)
169 #define _RAND48_SEED_2 (0x1234)
170 #define _RAND48_MULT_0 (0xe66d)
171 #define _RAND48_MULT_1 (0xdeec)
172 #define _RAND48_MULT_2 (0x0005)
173 #define _RAND48_ADD (0x000b)
175 unsigned short _seed
[3];
176 unsigned short _mult
[3];
183 * This structure contains *all* globals needed by the library.
184 * It's raison d'etre is to facilitate threads by making all library routines
185 * reentrant. IE: All state information is contained here.
190 /* local copy of errno */
193 /* FILE is a big struct and may change over time. To try to achieve binary
194 compatibility with future versions, put stdin,stdout,stderr here.
195 These are pointers into member __sf defined below. */
196 struct __sFILE
*_stdin
, *_stdout
, *_stderr
;
198 int _inc
; /* used by tmpnam */
201 int _current_category
; /* used by setlocale */
202 _CONST
char *_current_locale
;
204 int __sdidinit
; /* 1 means stdio has been init'd */
206 void _EXFUN((*__cleanup
),(struct _reent
*));
208 /* used by mprec routines */
209 struct _Bigint
*_result
;
211 struct _Bigint
*_p5s
;
212 struct _Bigint
**_freelist
;
214 /* used by some fp conversion routines */
215 int _cvtlen
; /* should be size_t */
222 unsigned int _unused_rand
;
224 char _asctime_buf
[26];
225 struct __tm _localtime_buf
;
227 __extension__
unsigned long long _rand_next
;
230 /* Two next two fields were once used by malloc. They are no longer
231 used. They are used to preserve the space used before so as to
232 allow addition of new reent fields and keep binary compatibility. */
236 unsigned char * _nextf
[_N_LISTS
];
237 unsigned int _nmalloc
[_N_LISTS
];
242 struct _atexit
*_atexit
; /* points to head of LIFO stack */
243 struct _atexit _atexit0
; /* one guaranteed table, required by ANSI */
246 void (**(_sig_func
))(int);
248 /* These are here last so that __sFILE can grow without changing the offsets
249 of the above members (on the off chance that future binary compatibility
250 would be broken otherwise). */
251 struct _glue __sglue
; /* root of glue chain */
252 struct __sFILE __sf
[3]; /* first three file descriptors */
257 #define _REENT_INIT(var) \
258 { 0, &var.__sf[0], &var.__sf[1], &var.__sf[2], 0, "", 0, "C", \
259 0, _NULL, _NULL, 0, _NULL, _NULL, 0, _NULL, { {0, _NULL, "", \
260 { 0,0,0,0,0,0,0,0}, 0, 1, \
261 {{_RAND48_SEED_0, _RAND48_SEED_1, _RAND48_SEED_2}, \
262 {_RAND48_MULT_0, _RAND48_MULT_1, _RAND48_MULT_2}, _RAND48_ADD}} } }
265 * All references to struct _reent are via this pointer.
266 * Internally, newlib routines that need to reference it should use _REENT.
269 #ifndef __ATTRIBUTE_IMPURE_PTR__
270 #define __ATTRIBUTE_IMPURE_PTR__
273 extern struct _reent
*_impure_ptr __ATTRIBUTE_IMPURE_PTR__
;
275 void _reclaim_reent
_PARAMS ((struct _reent
*));
277 /* #define _REENT_ONLY define this to get only reentrant routines */
280 #define _REENT _impure_ptr
286 #endif /* _SYS_REENT_H_ */