5755478 [rkeene@sledge /home/rkeene/devel/cygwin-stuff/cyg-root/usr/include/sys]$ cat -n reent.h
  1 /* 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 <time.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 /*
 46  * atexit() support
 47  */
 48 
 49 #define _ATEXIT_SIZE 32 /* must be at least 32 to guarantee ANSI conformance */
 50 
 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 };
 56 
 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  */
 63 
 64 struct __sbuf {
 65     unsigned char *_base;
 66     int _size;
 67 };
 68 
 69 /*
 70  * We need fpos_t for the following, but it doesn't have a leading "_",
 71  * so we use _fpos_t instead.
 72  */
 73 
 74 typedef long _fpos_t;       /* XXX must match off_t in <sys/types.h> */
 75                 /* (and must be `long' for now) */
 76 
 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  */
101 
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 */
110 
111   /* operations */
112   _PTR  _cookie;    /* cookie passed to io functions */
113 
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));
118 
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 */
123 
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 */
127 
128   /* separate buffer for fgetline() when line crosses buffer boundary */
129   struct __sbuf _lb;    /* buffer for fgetline() */
130 
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 */
134 
135   struct _reent *_data;
136 };
137 
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  */
145 
146 struct _reent
147 {
148   /* local copy of errno */
149   int _errno;
150 
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;
155 
156   int  _inc;            /* used by tmpnam */
157   char _emergency[25];
158  
159   int _current_category;    /* used by setlocale */
160   _CONST char *_current_locale;
161 
162   int __sdidinit;       /* 1 means stdio has been init'd */
163 
164   void _EXFUN((*__cleanup),(struct _reent *));
165 
166   /* used by mprec routines */
167   struct _Bigint *_result;
168   int _result_k;
169   struct _Bigint *_p5s;
170   struct _Bigint **_freelist;
171 
172   /* used by some fp conversion routines */
173   int _cvtlen;          /* should be size_t */
174   char *_cvtbuf;
175 
176   union
177     {
178       struct
179         {
180           unsigned int _unused_rand;
181           char * _strtok_last;
182           char _asctime_buf[26];
183           struct tm _localtime_buf;
184           int _gamma_signgam;
185           __extension__ unsigned long long _rand_next;
186 
187         } _reent;
188   /* Two next two fields were once used by malloc.  They are no longer
189      used. They are used to preserve the space used before so as to
190      allow addition of new reent fields and keep binary compatibility.   */ 
191       struct
192         {
193 #define _N_LISTS 30
194           unsigned char * _nextf[_N_LISTS];
195           unsigned int _nmalloc[_N_LISTS];
196         } _unused;
197     } _new;
198 
199   /* atexit stuff */
200   struct _atexit *_atexit;  /* points to head of LIFO stack */
201   struct _atexit _atexit0;  /* one guaranteed table, required by ANSI */
202 
203   /* signal info */
204   void (**(_sig_func))(int);
205 
206   /* These are here last so that __sFILE can grow without changing the offsets
207      of the above members (on the off chance that future binary compatibility
208      would be broken otherwise).  */
209   struct _glue __sglue;         /* root of glue chain */
210   struct __sFILE __sf[3];       /* first three file descriptors */
211 };
212 
213 #define _REENT_INIT(var) \
214   { 0, &var.__sf[0], &var.__sf[1], &var.__sf[2], 0, "", 0, "C", \
215     0, NULL, NULL, 0, NULL, NULL, 0, NULL, { {0, NULL, "", \
216     { 0,0,0,0,0,0,0,0}, 0, 1} } }
217 
218 /*
219  * All references to struct _reent are via this pointer.
220  * Internally, newlib routines that need to reference it should use _REENT.
221  */
222 
223 #ifndef __ATTRIBUTE_IMPURE_PTR__
224 #define __ATTRIBUTE_IMPURE_PTR__
225 #endif
226 
227 extern struct _reent *_impure_ptr __ATTRIBUTE_IMPURE_PTR__;
228 
229 void _reclaim_reent _PARAMS ((struct _reent *));
230 
231 /* #define _REENT_ONLY define this to get only reentrant routines */
232 
233 #ifndef _REENT_ONLY
234 #define _REENT _impure_ptr
235 #endif
236 
237 #ifdef __cplusplus
238 }
239 #endif
240 #endif /* _SYS_REENT_H_ */
5755479 [rkeene@sledge /home/rkeene/devel/cygwin-stuff/cyg-root/usr/include/sys]$

Click here to go back to the directory listing.
Click here to download this file.
last modified: 2001-01-31 15:09:06