filename | test/include/sys/reent.h |
changeset | 185:6755a04c447f |
author | nkeynes |
date | Fri Feb 08 00:06:56 2008 +0000 (16 years ago) |
permissions | -rw-r--r-- |
last change | Fix LDS/STS to FPUL/FPSCR to check the FPU disabled bit. Fixes the linux 2.4.0-test8 kernel boot (this wasn't exactly very well documented in the original manual) |
view | annotate | diff | log | raw |
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. */
7 #ifndef _SYS_REENT_H_
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 #define _SYS_REENT_H_
13 #include <_ansi.h>
14 #include <time.h>
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
26 #ifndef __Long
27 #define __Long __int32_t
28 typedef __uint32_t __ULong;
29 #endif
31 struct _glue
32 {
33 struct _glue *_next;
34 int _niobs;
35 struct __sFILE *_iobs;
36 };
38 struct _Bigint
39 {
40 struct _Bigint *_next;
41 int _k, _maxwds, _sign, _wds;
42 __ULong _x[1];
43 };
45 /*
46 * atexit() support
47 */
49 #define _ATEXIT_SIZE 32 /* must be at least 32 to guarantee ANSI conformance */
51 struct _atexit {
52 struct _atexit *_next; /* next in list */
53 int _ind; /* next index in this table */
54 void (*_fns[_ATEXIT_SIZE])(void); /* the table itself */
55 };
57 /*
58 * Stdio buffers.
59 *
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.
62 */
64 struct __sbuf {
65 unsigned char *_base;
66 int _size;
67 };
69 /*
70 * We need fpos_t for the following, but it doesn't have a leading "_",
71 * so we use _fpos_t instead.
72 */
74 typedef long _fpos_t; /* XXX must match off_t in <sys/types.h> */
75 /* (and must be `long' for now) */
77 /*
78 * Stdio state variables.
79 *
80 * The following always hold:
81 *
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
86 *
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.)
91 *
92 * _lbfsize is used only to make the inline line-buffered output stream
93 * code as compact as possible.
94 *
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.
100 */
102 struct __sFILE {
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 */
111 /* operations */
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;
136 };
138 /*
139 * struct _reent
140 *
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.
144 */
146 struct _reent
147 {
148 /* local copy of errno */
149 int _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 */
157 char _emergency[25];
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;
168 int _result_k;
169 struct _Bigint *_p5s;
170 struct _Bigint **_freelist;
172 /* used by some fp conversion routines */
173 int _cvtlen; /* should be size_t */
174 char *_cvtbuf;
176 union
177 {
178 struct
179 {
180 unsigned int _rand_next;
181 char * _strtok_last;
182 char _asctime_buf[26];
183 struct tm _localtime_buf;
184 int _gamma_signgam;
185 } _reent;
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. */
189 struct
190 {
191 #define _N_LISTS 30
192 unsigned char * _nextf[_N_LISTS];
193 unsigned int _nmalloc[_N_LISTS];
194 } _unused;
195 } _new;
197 /* atexit stuff */
198 struct _atexit *_atexit; /* points to head of LIFO stack */
199 struct _atexit _atexit0; /* one guaranteed table, required by ANSI */
201 /* signal info */
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 */
209 };
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 } } }
216 /*
217 * All references to struct _reent are via this pointer.
218 * Internally, newlib routines that need to reference it should use _REENT.
219 */
221 #ifndef __ATTRIBUTE_IMPURE_PTR__
222 #define __ATTRIBUTE_IMPURE_PTR__
223 #endif
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 */
231 #ifndef _REENT_ONLY
232 #define _REENT _impure_ptr
233 #endif
235 #ifdef __cplusplus
236 }
237 #endif
238 #endif /* _SYS_REENT_H_ */
.