1 |
1005 |
ivang |
/* 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
|
9 |
|
|
extern "C" {
|
10 |
|
|
#endif
|
11 |
|
|
#define _SYS_REENT_H_
|
12 |
|
|
|
13 |
|
|
#include <_ansi.h>
|
14 |
|
|
#include <sys/_types.h>
|
15 |
|
|
|
16 |
|
|
#ifndef __Long
|
17 |
|
|
#if __LONG_MAX__ == 2147483647L
|
18 |
|
|
#define __Long long
|
19 |
|
|
typedef unsigned __Long __ULong;
|
20 |
|
|
#elif __INT_MAX__ == 2147483647
|
21 |
|
|
#define __Long int
|
22 |
|
|
typedef unsigned __Long __ULong;
|
23 |
|
|
#endif
|
24 |
|
|
#endif
|
25 |
|
|
|
26 |
|
|
#ifndef __Long
|
27 |
|
|
#define __Long __int32_t
|
28 |
|
|
typedef __uint32_t __ULong;
|
29 |
|
|
#endif
|
30 |
|
|
|
31 |
|
|
struct _glue
|
32 |
|
|
{
|
33 |
|
|
struct _glue *_next;
|
34 |
|
|
int _niobs;
|
35 |
|
|
struct __sFILE *_iobs;
|
36 |
|
|
};
|
37 |
|
|
|
38 |
|
|
struct _Bigint
|
39 |
|
|
{
|
40 |
|
|
struct _Bigint *_next;
|
41 |
|
|
int _k, _maxwds, _sign, _wds;
|
42 |
|
|
__ULong _x[1];
|
43 |
|
|
};
|
44 |
|
|
|
45 |
|
|
/* needed by reentrant structure */
|
46 |
|
|
struct __tm
|
47 |
|
|
{
|
48 |
|
|
int __tm_sec;
|
49 |
|
|
int __tm_min;
|
50 |
|
|
int __tm_hour;
|
51 |
|
|
int __tm_mday;
|
52 |
|
|
int __tm_mon;
|
53 |
|
|
int __tm_year;
|
54 |
|
|
int __tm_wday;
|
55 |
|
|
int __tm_yday;
|
56 |
|
|
int __tm_isdst;
|
57 |
|
|
};
|
58 |
|
|
|
59 |
|
|
/*
|
60 |
|
|
* atexit() support
|
61 |
|
|
*/
|
62 |
|
|
|
63 |
|
|
#define _ATEXIT_SIZE 32 /* must be at least 32 to guarantee ANSI conformance */
|
64 |
|
|
|
65 |
|
|
struct _atexit {
|
66 |
|
|
struct _atexit *_next; /* next in list */
|
67 |
|
|
int _ind; /* next index in this table */
|
68 |
|
|
void (*_fns[_ATEXIT_SIZE])(void); /* the table itself */
|
69 |
|
|
};
|
70 |
|
|
|
71 |
|
|
/*
|
72 |
|
|
* Stdio buffers.
|
73 |
|
|
*
|
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.
|
76 |
|
|
*/
|
77 |
|
|
|
78 |
|
|
struct __sbuf {
|
79 |
|
|
unsigned char *_base;
|
80 |
|
|
int _size;
|
81 |
|
|
};
|
82 |
|
|
|
83 |
|
|
/*
|
84 |
|
|
* We need fpos_t for the following, but it doesn't have a leading "_",
|
85 |
|
|
* so we use _fpos_t instead.
|
86 |
|
|
*/
|
87 |
|
|
|
88 |
|
|
typedef long _fpos_t; /* XXX must match off_t in <sys/types.h> */
|
89 |
|
|
/* (and must be `long' for now) */
|
90 |
|
|
|
91 |
|
|
/*
|
92 |
|
|
* Stdio state variables.
|
93 |
|
|
*
|
94 |
|
|
* The following always hold:
|
95 |
|
|
*
|
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
|
100 |
|
|
*
|
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.)
|
105 |
|
|
*
|
106 |
|
|
* _lbfsize is used only to make the inline line-buffered output stream
|
107 |
|
|
* code as compact as possible.
|
108 |
|
|
*
|
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.
|
114 |
|
|
*/
|
115 |
|
|
|
116 |
|
|
struct __sFILE {
|
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 */
|
124 |
|
|
|
125 |
|
|
/* operations */
|
126 |
|
|
_PTR _cookie; /* cookie passed to io functions */
|
127 |
|
|
|
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,
|
130 |
|
|
int _n));
|
131 |
|
|
_fpos_t _EXFUN((*_seek),(_PTR _cookie, _fpos_t _offset, int _whence));
|
132 |
|
|
int _EXFUN((*_close),(_PTR _cookie));
|
133 |
|
|
|
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 */
|
138 |
|
|
|
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 */
|
142 |
|
|
|
143 |
|
|
/* separate buffer for fgetline() when line crosses buffer boundary */
|
144 |
|
|
struct __sbuf _lb; /* buffer for fgetline() */
|
145 |
|
|
|
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 */
|
149 |
|
|
|
150 |
|
|
struct _reent *_data;
|
151 |
|
|
};
|
152 |
|
|
|
153 |
|
|
/*
|
154 |
|
|
* rand48 family support
|
155 |
|
|
*
|
156 |
|
|
* Copyright (c) 1993 Martin Birgmeier
|
157 |
|
|
* All rights reserved.
|
158 |
|
|
*
|
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.
|
162 |
|
|
*
|
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.
|
166 |
|
|
*/
|
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)
|
174 |
|
|
struct _rand48 {
|
175 |
|
|
unsigned short _seed[3];
|
176 |
|
|
unsigned short _mult[3];
|
177 |
|
|
unsigned short _add;
|
178 |
|
|
};
|
179 |
|
|
|
180 |
|
|
/*
|
181 |
|
|
* struct _reent
|
182 |
|
|
*
|
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.
|
186 |
|
|
*/
|
187 |
|
|
|
188 |
|
|
struct _reent
|
189 |
|
|
{
|
190 |
|
|
/* local copy of errno */
|
191 |
|
|
int _errno;
|
192 |
|
|
|
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;
|
197 |
|
|
|
198 |
|
|
int _inc; /* used by tmpnam */
|
199 |
|
|
char _emergency[25];
|
200 |
|
|
|
201 |
|
|
int _current_category; /* used by setlocale */
|
202 |
|
|
_CONST char *_current_locale;
|
203 |
|
|
|
204 |
|
|
int __sdidinit; /* 1 means stdio has been init'd */
|
205 |
|
|
|
206 |
|
|
void _EXFUN((*__cleanup),(struct _reent *));
|
207 |
|
|
|
208 |
|
|
/* used by mprec routines */
|
209 |
|
|
struct _Bigint *_result;
|
210 |
|
|
int _result_k;
|
211 |
|
|
struct _Bigint *_p5s;
|
212 |
|
|
struct _Bigint **_freelist;
|
213 |
|
|
|
214 |
|
|
/* used by some fp conversion routines */
|
215 |
|
|
int _cvtlen; /* should be size_t */
|
216 |
|
|
char *_cvtbuf;
|
217 |
|
|
|
218 |
|
|
union
|
219 |
|
|
{
|
220 |
|
|
struct
|
221 |
|
|
{
|
222 |
|
|
unsigned int _unused_rand;
|
223 |
|
|
char * _strtok_last;
|
224 |
|
|
char _asctime_buf[26];
|
225 |
|
|
struct __tm _localtime_buf;
|
226 |
|
|
int _gamma_signgam;
|
227 |
|
|
__extension__ unsigned long long _rand_next;
|
228 |
|
|
struct _rand48 _r48;
|
229 |
|
|
} _reent;
|
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. */
|
233 |
|
|
struct
|
234 |
|
|
{
|
235 |
|
|
#define _N_LISTS 30
|
236 |
|
|
unsigned char * _nextf[_N_LISTS];
|
237 |
|
|
unsigned int _nmalloc[_N_LISTS];
|
238 |
|
|
} _unused;
|
239 |
|
|
} _new;
|
240 |
|
|
|
241 |
|
|
/* atexit stuff */
|
242 |
|
|
struct _atexit *_atexit; /* points to head of LIFO stack */
|
243 |
|
|
struct _atexit _atexit0; /* one guaranteed table, required by ANSI */
|
244 |
|
|
|
245 |
|
|
/* signal info */
|
246 |
|
|
void (**(_sig_func))(int);
|
247 |
|
|
|
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 */
|
253 |
|
|
};
|
254 |
|
|
|
255 |
|
|
#define _NULL 0
|
256 |
|
|
|
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}} } }
|
263 |
|
|
|
264 |
|
|
/*
|
265 |
|
|
* All references to struct _reent are via this pointer.
|
266 |
|
|
* Internally, newlib routines that need to reference it should use _REENT.
|
267 |
|
|
*/
|
268 |
|
|
|
269 |
|
|
#ifndef __ATTRIBUTE_IMPURE_PTR__
|
270 |
|
|
#define __ATTRIBUTE_IMPURE_PTR__
|
271 |
|
|
#endif
|
272 |
|
|
|
273 |
|
|
extern struct _reent *_impure_ptr __ATTRIBUTE_IMPURE_PTR__;
|
274 |
|
|
|
275 |
|
|
void _reclaim_reent _PARAMS ((struct _reent *));
|
276 |
|
|
|
277 |
|
|
/* #define _REENT_ONLY define this to get only reentrant routines */
|
278 |
|
|
|
279 |
|
|
#ifndef _REENT_ONLY
|
280 |
|
|
#define _REENT _impure_ptr
|
281 |
|
|
#endif
|
282 |
|
|
|
283 |
|
|
#ifdef __cplusplus
|
284 |
|
|
}
|
285 |
|
|
#endif
|
286 |
|
|
#endif /* _SYS_REENT_H_ */
|