Search
lxdream.org :: lxdream/test/include/sys/reent.h :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename test/include/sys/reent.h
changeset 185:6755a04c447f
author nkeynes
date Sun Oct 07 06:27:12 2007 +0000 (16 years ago)
permissions -rw-r--r--
last change Fix compilation warnings
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/test/include/sys/reent.h Sun Oct 07 06:27:12 2007 +0000
1.3 @@ -0,0 +1,238 @@
1.4 +/* This header file provides the reentrancy. */
1.5 +
1.6 +/* WARNING: All identifiers here must begin with an underscore. This file is
1.7 + included by stdio.h and others and we therefore must only use identifiers
1.8 + in the namespace allotted to us. */
1.9 +
1.10 +#ifndef _SYS_REENT_H_
1.11 +#ifdef __cplusplus
1.12 +extern "C" {
1.13 +#endif
1.14 +#define _SYS_REENT_H_
1.15 +
1.16 +#include <_ansi.h>
1.17 +#include <time.h>
1.18 +
1.19 +#ifndef __Long
1.20 +#if __LONG_MAX__ == 2147483647L
1.21 +#define __Long long
1.22 +typedef unsigned __Long __ULong;
1.23 +#elif __INT_MAX__ == 2147483647
1.24 +#define __Long int
1.25 +typedef unsigned __Long __ULong;
1.26 +#endif
1.27 +#endif
1.28 +
1.29 +#ifndef __Long
1.30 +#define __Long __int32_t
1.31 +typedef __uint32_t __ULong;
1.32 +#endif
1.33 +
1.34 +struct _glue
1.35 +{
1.36 + struct _glue *_next;
1.37 + int _niobs;
1.38 + struct __sFILE *_iobs;
1.39 +};
1.40 +
1.41 +struct _Bigint
1.42 +{
1.43 + struct _Bigint *_next;
1.44 + int _k, _maxwds, _sign, _wds;
1.45 + __ULong _x[1];
1.46 +};
1.47 +
1.48 +/*
1.49 + * atexit() support
1.50 + */
1.51 +
1.52 +#define _ATEXIT_SIZE 32 /* must be at least 32 to guarantee ANSI conformance */
1.53 +
1.54 +struct _atexit {
1.55 + struct _atexit *_next; /* next in list */
1.56 + int _ind; /* next index in this table */
1.57 + void (*_fns[_ATEXIT_SIZE])(void); /* the table itself */
1.58 +};
1.59 +
1.60 +/*
1.61 + * Stdio buffers.
1.62 + *
1.63 + * This and __sFILE are defined here because we need them for struct _reent,
1.64 + * but we don't want stdio.h included when stdlib.h is.
1.65 + */
1.66 +
1.67 +struct __sbuf {
1.68 + unsigned char *_base;
1.69 + int _size;
1.70 +};
1.71 +
1.72 +/*
1.73 + * We need fpos_t for the following, but it doesn't have a leading "_",
1.74 + * so we use _fpos_t instead.
1.75 + */
1.76 +
1.77 +typedef long _fpos_t; /* XXX must match off_t in <sys/types.h> */
1.78 + /* (and must be `long' for now) */
1.79 +
1.80 +/*
1.81 + * Stdio state variables.
1.82 + *
1.83 + * The following always hold:
1.84 + *
1.85 + * if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR),
1.86 + * _lbfsize is -_bf._size, else _lbfsize is 0
1.87 + * if _flags&__SRD, _w is 0
1.88 + * if _flags&__SWR, _r is 0
1.89 + *
1.90 + * This ensures that the getc and putc macros (or inline functions) never
1.91 + * try to write or read from a file that is in `read' or `write' mode.
1.92 + * (Moreover, they can, and do, automatically switch from read mode to
1.93 + * write mode, and back, on "r+" and "w+" files.)
1.94 + *
1.95 + * _lbfsize is used only to make the inline line-buffered output stream
1.96 + * code as compact as possible.
1.97 + *
1.98 + * _ub, _up, and _ur are used when ungetc() pushes back more characters
1.99 + * than fit in the current _bf, or when ungetc() pushes back a character
1.100 + * that does not match the previous one in _bf. When this happens,
1.101 + * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff
1.102 + * _ub._base!=NULL) and _up and _ur save the current values of _p and _r.
1.103 + */
1.104 +
1.105 +struct __sFILE {
1.106 + unsigned char *_p; /* current position in (some) buffer */
1.107 + int _r; /* read space left for getc() */
1.108 + int _w; /* write space left for putc() */
1.109 + short _flags; /* flags, below; this FILE is free if 0 */
1.110 + short _file; /* fileno, if Unix descriptor, else -1 */
1.111 + struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */
1.112 + int _lbfsize; /* 0 or -_bf._size, for inline putc */
1.113 +
1.114 + /* operations */
1.115 + _PTR _cookie; /* cookie passed to io functions */
1.116 +
1.117 + int _EXFUN((*_read),(_PTR _cookie, char *_buf, int _n));
1.118 + int _EXFUN((*_write),(_PTR _cookie, const char *_buf, int _n));
1.119 + _fpos_t _EXFUN((*_seek),(_PTR _cookie, _fpos_t _offset, int _whence));
1.120 + int _EXFUN((*_close),(_PTR _cookie));
1.121 +
1.122 + /* separate buffer for long sequences of ungetc() */
1.123 + struct __sbuf _ub; /* ungetc buffer */
1.124 + unsigned char *_up; /* saved _p when _p is doing ungetc data */
1.125 + int _ur; /* saved _r when _r is counting ungetc data */
1.126 +
1.127 + /* tricks to meet minimum requirements even when malloc() fails */
1.128 + unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */
1.129 + unsigned char _nbuf[1]; /* guarantee a getc() buffer */
1.130 +
1.131 + /* separate buffer for fgetline() when line crosses buffer boundary */
1.132 + struct __sbuf _lb; /* buffer for fgetline() */
1.133 +
1.134 + /* Unix stdio files get aligned to block boundaries on fseek() */
1.135 + int _blksize; /* stat.st_blksize (may be != _bf._size) */
1.136 + int _offset; /* current lseek offset */
1.137 +
1.138 + struct _reent *_data;
1.139 +};
1.140 +
1.141 +/*
1.142 + * struct _reent
1.143 + *
1.144 + * This structure contains *all* globals needed by the library.
1.145 + * It's raison d'etre is to facilitate threads by making all library routines
1.146 + * reentrant. IE: All state information is contained here.
1.147 + */
1.148 +
1.149 +struct _reent
1.150 +{
1.151 + /* local copy of errno */
1.152 + int _errno;
1.153 +
1.154 + /* FILE is a big struct and may change over time. To try to achieve binary
1.155 + compatibility with future versions, put stdin,stdout,stderr here.
1.156 + These are pointers into member __sf defined below. */
1.157 + struct __sFILE *_stdin, *_stdout, *_stderr;
1.158 +
1.159 + int _inc; /* used by tmpnam */
1.160 + char _emergency[25];
1.161 +
1.162 + int _current_category; /* used by setlocale */
1.163 + _CONST char *_current_locale;
1.164 +
1.165 + int __sdidinit; /* 1 means stdio has been init'd */
1.166 +
1.167 + void _EXFUN((*__cleanup),(struct _reent *));
1.168 +
1.169 + /* used by mprec routines */
1.170 + struct _Bigint *_result;
1.171 + int _result_k;
1.172 + struct _Bigint *_p5s;
1.173 + struct _Bigint **_freelist;
1.174 +
1.175 + /* used by some fp conversion routines */
1.176 + int _cvtlen; /* should be size_t */
1.177 + char *_cvtbuf;
1.178 +
1.179 + union
1.180 + {
1.181 + struct
1.182 + {
1.183 + unsigned int _rand_next;
1.184 + char * _strtok_last;
1.185 + char _asctime_buf[26];
1.186 + struct tm _localtime_buf;
1.187 + int _gamma_signgam;
1.188 + } _reent;
1.189 + /* Two next two fields were once used by malloc. They are no longer
1.190 + used. They are used to preserve the space used before so as to
1.191 + allow addition of new reent fields and keep binary compatibility. */
1.192 + struct
1.193 + {
1.194 +#define _N_LISTS 30
1.195 + unsigned char * _nextf[_N_LISTS];
1.196 + unsigned int _nmalloc[_N_LISTS];
1.197 + } _unused;
1.198 + } _new;
1.199 +
1.200 + /* atexit stuff */
1.201 + struct _atexit *_atexit; /* points to head of LIFO stack */
1.202 + struct _atexit _atexit0; /* one guaranteed table, required by ANSI */
1.203 +
1.204 + /* signal info */
1.205 + void (**(_sig_func))(int);
1.206 +
1.207 + /* These are here last so that __sFILE can grow without changing the offsets
1.208 + of the above members (on the off chance that future binary compatibility
1.209 + would be broken otherwise). */
1.210 + struct _glue __sglue; /* root of glue chain */
1.211 + struct __sFILE __sf[3]; /* first three file descriptors */
1.212 +};
1.213 +
1.214 +#define _REENT_INIT(var) \
1.215 + { 0, &var.__sf[0], &var.__sf[1], &var.__sf[2], 0, "", 0, "C", \
1.216 + 0, NULL, NULL, 0, NULL, NULL, 0, NULL, { {1, NULL, "", \
1.217 + { 0,0,0,0,0,0,0,0}, 0 } } }
1.218 +
1.219 +/*
1.220 + * All references to struct _reent are via this pointer.
1.221 + * Internally, newlib routines that need to reference it should use _REENT.
1.222 + */
1.223 +
1.224 +#ifndef __ATTRIBUTE_IMPURE_PTR__
1.225 +#define __ATTRIBUTE_IMPURE_PTR__
1.226 +#endif
1.227 +
1.228 +extern struct _reent *_impure_ptr __ATTRIBUTE_IMPURE_PTR__;
1.229 +
1.230 +void _reclaim_reent _PARAMS ((struct _reent *));
1.231 +
1.232 +/* #define _REENT_ONLY define this to get only reentrant routines */
1.233 +
1.234 +#ifndef _REENT_ONLY
1.235 +#define _REENT _impure_ptr
1.236 +#endif
1.237 +
1.238 +#ifdef __cplusplus
1.239 +}
1.240 +#endif
1.241 +#endif /* _SYS_REENT_H_ */
.