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. */
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;
49 #define _ATEXIT_SIZE 32 /* must be at least 32 to guarantee ANSI conformance */
52 struct _atexit *_next; /* next in list */
53 int _ind; /* next index in this table */
54 void (*_fns[_ATEXIT_SIZE])(void); /* the table itself */
60 * This and __sFILE are defined here because we need them for struct _reent,
61 * but we don't want stdio.h included when stdlib.h is.
70 * We need fpos_t for the following, but it doesn't have a leading "_",
71 * so we use _fpos_t instead.
74 typedef long _fpos_t; /* XXX must match off_t in <sys/types.h> */
75 /* (and must be `long' for now) */
78 * Stdio state variables.
80 * The following always hold:
82 * if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR),
83 * _lbfsize is -_bf._size, else _lbfsize is 0
84 * if _flags&__SRD, _w is 0
85 * if _flags&__SWR, _r is 0
87 * This ensures that the getc and putc macros (or inline functions) never
88 * try to write or read from a file that is in `read' or `write' mode.
89 * (Moreover, they can, and do, automatically switch from read mode to
90 * write mode, and back, on "r+" and "w+" files.)
92 * _lbfsize is used only to make the inline line-buffered output stream
93 * code as compact as possible.
95 * _ub, _up, and _ur are used when ungetc() pushes back more characters
96 * than fit in the current _bf, or when ungetc() pushes back a character
97 * that does not match the previous one in _bf. When this happens,
98 * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff
99 * _ub._base!=NULL) and _up and _ur save the current values of _p and _r.
103 unsigned char *_p; /* current position in (some) buffer */
104 int _r; /* read space left for getc() */
105 int _w; /* write space left for putc() */
106 short _flags; /* flags, below; this FILE is free if 0 */
107 short _file; /* fileno, if Unix descriptor, else -1 */
108 struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */
109 int _lbfsize; /* 0 or -_bf._size, for inline putc */
112 _PTR _cookie; /* cookie passed to io functions */
114 int _EXFUN((*_read),(_PTR _cookie, char *_buf, int _n));
115 int _EXFUN((*_write),(_PTR _cookie, const char *_buf, int _n));
116 _fpos_t _EXFUN((*_seek),(_PTR _cookie, _fpos_t _offset, int _whence));
117 int _EXFUN((*_close),(_PTR _cookie));
119 /* separate buffer for long sequences of ungetc() */
120 struct __sbuf _ub; /* ungetc buffer */
121 unsigned char *_up; /* saved _p when _p is doing ungetc data */
122 int _ur; /* saved _r when _r is counting ungetc data */
124 /* tricks to meet minimum requirements even when malloc() fails */
125 unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */
126 unsigned char _nbuf[1]; /* guarantee a getc() buffer */
128 /* separate buffer for fgetline() when line crosses buffer boundary */
129 struct __sbuf _lb; /* buffer for fgetline() */
131 /* Unix stdio files get aligned to block boundaries on fseek() */
132 int _blksize; /* stat.st_blksize (may be != _bf._size) */
133 int _offset; /* current lseek offset */
135 struct _reent *_data;
141 * This structure contains *all* globals needed by the library.
142 * It's raison d'etre is to facilitate threads by making all library routines
143 * reentrant. IE: All state information is contained here.
148 /* local copy of errno */
151 /* FILE is a big struct and may change over time. To try to achieve binary
152 compatibility with future versions, put stdin,stdout,stderr here.
153 These are pointers into member __sf defined below. */
154 struct __sFILE *_stdin, *_stdout, *_stderr;
156 int _inc; /* used by tmpnam */
159 int _current_category; /* used by setlocale */
160 _CONST char *_current_locale;
162 int __sdidinit; /* 1 means stdio has been init'd */
164 void _EXFUN((*__cleanup),(struct _reent *));
166 /* used by mprec routines */
167 struct _Bigint *_result;
169 struct _Bigint *_p5s;
170 struct _Bigint **_freelist;
172 /* used by some fp conversion routines */
173 int _cvtlen; /* should be size_t */
180 unsigned int _rand_next;
182 char _asctime_buf[26];
183 struct tm _localtime_buf;
186 /* Two next two fields were once used by malloc. They are no longer
187 used. They are used to preserve the space used before so as to
188 allow addition of new reent fields and keep binary compatibility. */
192 unsigned char * _nextf[_N_LISTS];
193 unsigned int _nmalloc[_N_LISTS];
198 struct _atexit *_atexit; /* points to head of LIFO stack */
199 struct _atexit _atexit0; /* one guaranteed table, required by ANSI */
202 void (**(_sig_func))(int);
204 /* These are here last so that __sFILE can grow without changing the offsets
205 of the above members (on the off chance that future binary compatibility
206 would be broken otherwise). */
207 struct _glue __sglue; /* root of glue chain */
208 struct __sFILE __sf[3]; /* first three file descriptors */
211 #define _REENT_INIT(var) \
212 { 0, &var.__sf[0], &var.__sf[1], &var.__sf[2], 0, "", 0, "C", \
213 0, NULL, NULL, 0, NULL, NULL, 0, NULL, { {1, NULL, "", \
214 { 0,0,0,0,0,0,0,0}, 0 } } }
217 * All references to struct _reent are via this pointer.
218 * Internally, newlib routines that need to reference it should use _REENT.
221 #ifndef __ATTRIBUTE_IMPURE_PTR__
222 #define __ATTRIBUTE_IMPURE_PTR__
225 extern struct _reent *_impure_ptr __ATTRIBUTE_IMPURE_PTR__;
227 void _reclaim_reent _PARAMS ((struct _reent *));
229 /* #define _REENT_ONLY define this to get only reentrant routines */
232 #define _REENT _impure_ptr
238 #endif /* _SYS_REENT_H_ */
.