Update msys build environment for multibyte conversion functions
[msysgit.git] / include / sys / reent.h
bloba221385780b6093e6e43e3f6e7f370b1e3993dbe
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 <sys/_types.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
33 struct _glue *_next;
34 int _niobs;
35 struct __sFILE *_iobs;
38 struct _Bigint
40 struct _Bigint *_next;
41 int _k, _maxwds, _sign, _wds;
42 __ULong _x[1];
45 /* needed by reentrant structure */
46 struct __tm
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;
60 * atexit() support
63 #define _ATEXIT_SIZE 32 /* must be at least 32 to guarantee ANSI conformance */
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 */
72 * Stdio buffers.
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.
78 struct __sbuf {
79 unsigned char *_base;
80 int _size;
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.
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 */
125 /* operations */
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,
130 int _n));
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;
153 typedef struct __sFILE __FILE;
156 * rand48 family support
158 * Copyright (c) 1993 Martin Birgmeier
159 * All rights reserved.
161 * You may redistribute unmodified or modified versions of this source
162 * code provided that the above copyright notice and this and the
163 * following conditions are retained.
165 * This software is provided ``as is'', and comes with no warranties
166 * of any kind. I shall in no event be liable for anything that happens
167 * to anyone/anything when using this software.
169 #define _RAND48_SEED_0 (0x330e)
170 #define _RAND48_SEED_1 (0xabcd)
171 #define _RAND48_SEED_2 (0x1234)
172 #define _RAND48_MULT_0 (0xe66d)
173 #define _RAND48_MULT_1 (0xdeec)
174 #define _RAND48_MULT_2 (0x0005)
175 #define _RAND48_ADD (0x000b)
176 struct _rand48 {
177 unsigned short _seed[3];
178 unsigned short _mult[3];
179 unsigned short _add;
183 * struct _reent
185 * This structure contains *all* globals needed by the library.
186 * It's raison d'etre is to facilitate threads by making all library routines
187 * reentrant. IE: All state information is contained here.
190 struct _reent
192 /* local copy of errno */
193 int _errno;
195 /* FILE is a big struct and may change over time. To try to achieve binary
196 compatibility with future versions, put stdin,stdout,stderr here.
197 These are pointers into member __sf defined below. */
198 struct __sFILE *_stdin, *_stdout, *_stderr;
200 int _inc; /* used by tmpnam */
201 char _emergency[25];
203 int _current_category; /* used by setlocale */
204 _CONST char *_current_locale;
206 int __sdidinit; /* 1 means stdio has been init'd */
208 void _EXFUN((*__cleanup),(struct _reent *));
210 /* used by mprec routines */
211 struct _Bigint *_result;
212 int _result_k;
213 struct _Bigint *_p5s;
214 struct _Bigint **_freelist;
216 /* used by some fp conversion routines */
217 int _cvtlen; /* should be size_t */
218 char *_cvtbuf;
220 union
222 struct
224 unsigned int _unused_rand;
225 char * _strtok_last;
226 char _asctime_buf[26];
227 struct __tm _localtime_buf;
228 int _gamma_signgam;
229 __extension__ unsigned long long _rand_next;
230 struct _rand48 _r48;
231 _mbstate_t _mblen_state;
232 _mbstate_t _mbtowc_state;
233 _mbstate_t _wctomb_state;
234 _mbstate_t _mbrlen_state;
235 _mbstate_t _mbrtowc_state;
236 _mbstate_t _mbsrtowcs_state;
237 _mbstate_t _wcrtomb_state;
238 _mbstate_t _wcsrtombs_state;
239 } _reent;
240 /* Two next two fields were once used by malloc. They are no longer
241 used. They are used to preserve the space used before so as to
242 allow addition of new reent fields and keep binary compatibility. */
243 struct
245 #define _N_LISTS 30
246 unsigned char * _nextf[_N_LISTS];
247 unsigned int _nmalloc[_N_LISTS];
248 } _unused;
249 } _new;
251 /* atexit stuff */
252 struct _atexit *_atexit; /* points to head of LIFO stack */
253 struct _atexit _atexit0; /* one guaranteed table, required by ANSI */
255 /* signal info */
256 void (**(_sig_func))(int);
258 /* These are here last so that __sFILE can grow without changing the offsets
259 of the above members (on the off chance that future binary compatibility
260 would be broken otherwise). */
261 struct _glue __sglue; /* root of glue chain */
262 struct __sFILE __sf[3]; /* first three file descriptors */
265 #define _NULL 0
267 #define _REENT_INIT(var) \
268 { 0, &var.__sf[0], &var.__sf[1], &var.__sf[2], 0, "", 0, "C", \
269 0, _NULL, _NULL, 0, _NULL, _NULL, 0, _NULL, { {0, _NULL, "", \
270 { 0,0,0,0,0,0,0,0}, 0, 1, \
271 {{_RAND48_SEED_0, _RAND48_SEED_1, _RAND48_SEED_2}, \
272 {_RAND48_MULT_0, _RAND48_MULT_1, _RAND48_MULT_2}, _RAND48_ADD}, \
273 {0,{0}}, {0,{0}}, {0,{0}}, {0,{0}}, {0,{0}}, {0,{0}}, {0,{0}}, {0,{0}} \
274 } } }
276 #define _REENT_MBLEN_STATE(ptr) ((ptr)->_new._reent._mblen_state)
277 #define _REENT_MBTOWC_STATE(ptr)((ptr)->_new._reent._mbtowc_state)
278 #define _REENT_WCTOMB_STATE(ptr)((ptr)->_new._reent._wctomb_state)
279 #define _REENT_MBRLEN_STATE(ptr)((ptr)->_new._reent._mbrlen_state)
280 #define _REENT_MBRTOWC_STATE(ptr)((ptr)->_new._reent._mbrtowc_state)
281 #define _REENT_MBSRTOWCS_STATE(ptr)((ptr)->_new._reent._mbsrtowcs_state)
282 #define _REENT_WCRTOMB_STATE(ptr)((ptr)->_new._reent._wcrtomb_state)
283 #define _REENT_WCSRTOMBS_STATE(ptr)((ptr)->_new._reent._wcsrtombs_state)
284 #define _REENT_CHECK_MISC(ptr) /* nothing */
287 * All references to struct _reent are via this pointer.
288 * Internally, newlib routines that need to reference it should use _REENT.
291 #ifndef __ATTRIBUTE_IMPURE_PTR__
292 #define __ATTRIBUTE_IMPURE_PTR__
293 #endif
295 extern struct _reent *_impure_ptr __ATTRIBUTE_IMPURE_PTR__;
297 void _reclaim_reent _PARAMS ((struct _reent *));
299 /* #define _REENT_ONLY define this to get only reentrant routines */
301 #ifndef _REENT_ONLY
302 #define _REENT _impure_ptr
303 #endif
305 #ifdef __cplusplus
307 #endif
308 #endif /* _SYS_REENT_H_ */