📄 reent.h
字号:
/* This header file provides the reentrancy. *//* WARNING: All identifiers here must begin with an underscore. This file is included by stdio.h and others and we therefore must only use identifiers in the namespace allotted to us. */#ifndef _SYS_REENT_H_#ifdef __cplusplusextern "C" {#endif#define _SYS_REENT_H_#include <_ansi.h>#include <sys/_types.h>#ifndef __Long#if __LONG_MAX__ == 2147483647L#define __Long longtypedef unsigned __Long __ULong;#elif __INT_MAX__ == 2147483647#define __Long inttypedef unsigned __Long __ULong;#endif#endif#if !defined( __Long)#include <sys/types.h>#endif#ifndef __Long#define __Long __int32_ttypedef __uint32_t __ULong;#endif/* * If _REENT_SMALL is defined, we make struct _reent as small as possible, * by having nearly everything possible allocated at first use. */struct _Bigint { struct _Bigint *_next; int _k, _maxwds, _sign, _wds; __ULong _x[1];};/* needed by reentrant structure */struct __tm{ int __tm_sec; int __tm_min; int __tm_hour; int __tm_mday; int __tm_mon; int __tm_year; int __tm_wday; int __tm_yday; int __tm_isdst;};/* * atexit() support. */#define _ATEXIT_SIZE 32 /* must be at least 32 to guarantee ANSI conformance */struct _on_exit_args { void * _fnargs[_ATEXIT_SIZE]; /* user fn args */ void * _dso_handle[_ATEXIT_SIZE]; /* Bitmask is set if user function takes arguments. */ __ULong _fntypes; /* type of exit routine - Must have at least _ATEXIT_SIZE bits */ /* Bitmask is set if function was registered via __cxa_atexit. */ __ULong _is_cxa;};#ifdef _REENT_SMALLstruct _atexit { struct _atexit *_next; /* next in list */ int _ind; /* next index in this table */ void (*_fns[_ATEXIT_SIZE])(void); /* the table itself */ struct _on_exit_args * _on_exit_args_ptr;};#elsestruct _atexit { struct _atexit *_next; /* next in list */ int _ind; /* next index in this table */ /* Some entries may already have been called, and will be NULL. */ void (*_fns[_ATEXIT_SIZE])(void); /* the table itself */ struct _on_exit_args _on_exit_args;};#endif/* * Stdio buffers. * * This and __FILE are defined here because we need them for struct _reent, * but we don't want stdio.h included when stdlib.h is. */struct __sbuf { unsigned char *_base; int _size;};/* * We need fpos_t for the following, but it doesn't have a leading "_", * so we use _fpos_t instead. */typedef long _fpos_t; /* XXX must match off_t in <sys/types.h> */ /* (and must be `long' for now) */#ifdef __LARGE64_FILEStypedef _off64_t _fpos64_t;#endif/* * Stdio state variables. * * The following always hold: * * if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR), * _lbfsize is -_bf._size, else _lbfsize is 0 * if _flags&__SRD, _w is 0 * if _flags&__SWR, _r is 0 * * This ensures that the getc and putc macros (or inline functions) never * try to write or read from a file that is in `read' or `write' mode. * (Moreover, they can, and do, automatically switch from read mode to * write mode, and back, on "r+" and "w+" files.) * * _lbfsize is used only to make the inline line-buffered output stream * code as compact as possible. * * _ub, _up, and _ur are used when ungetc() pushes back more characters * than fit in the current _bf, or when ungetc() pushes back a character * that does not match the previous one in _bf. When this happens, * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff * _ub._base!=NULL) and _up and _ur save the current values of _p and _r. */#ifdef _REENT_SMALL/* * struct __sFILE_fake is the start of a struct __sFILE, with only the * minimal fields allocated. In __sinit() we really allocate the 3 * standard streams, etc., and point away from this fake. */struct __sFILE_fake { unsigned char *_p; /* current position in (some) buffer */ int _r; /* read space left for getc() */ int _w; /* write space left for putc() */ short _flags; /* flags, below; this FILE is free if 0 */ short _file; /* fileno, if Unix descriptor, else -1 */ struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */ int _lbfsize; /* 0 or -_bf._size, for inline putc */ struct _reent *_data;};/* CHECK_INIT() comes from stdio/local.h; be sure to include that. */# define _REENT_SMALL_CHECK_INIT(fp) CHECK_INIT(fp)#else# define _REENT_SMALL_CHECK_INIT(fp) /* nothing */#endifstruct __sFILE { unsigned char *_p; /* current position in (some) buffer */ int _r; /* read space left for getc() */ int _w; /* write space left for putc() */ short _flags; /* flags, below; this FILE is free if 0 */ short _file; /* fileno, if Unix descriptor, else -1 */ struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */ int _lbfsize; /* 0 or -_bf._size, for inline putc */#ifdef _REENT_SMALL struct _reent *_data;#endif /* operations */ _PTR _cookie; /* cookie passed to io functions */ _READ_WRITE_RETURN_TYPE _EXFUN((*_read),(_PTR _cookie, char *_buf, int _n)); _READ_WRITE_RETURN_TYPE _EXFUN((*_write),(_PTR _cookie, const char *_buf, int _n)); _fpos_t _EXFUN((*_seek),(_PTR _cookie, _fpos_t _offset, int _whence)); int _EXFUN((*_close),(_PTR _cookie)); /* separate buffer for long sequences of ungetc() */ struct __sbuf _ub; /* ungetc buffer */ unsigned char *_up; /* saved _p when _p is doing ungetc data */ int _ur; /* saved _r when _r is counting ungetc data */ /* tricks to meet minimum requirements even when malloc() fails */ unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */ unsigned char _nbuf[1]; /* guarantee a getc() buffer */ /* separate buffer for fgetline() when line crosses buffer boundary */ struct __sbuf _lb; /* buffer for fgetline() */ /* Unix stdio files get aligned to block boundaries on fseek() */ int _blksize; /* stat.st_blksize (may be != _bf._size) */ int _offset; /* current lseek offset */#ifndef _REENT_SMALL struct _reent *_data; /* Here for binary compatibility? Remove? */#endif#ifndef __SINGLE_THREAD__ _flock_t _lock; /* for thread-safety locking */#endif};#ifdef __LARGE64_FILESstruct __sFILE64 { unsigned char *_p; /* current position in (some) buffer */ int _r; /* read space left for getc() */ int _w; /* write space left for putc() */ short _flags; /* flags, below; this FILE is free if 0 */ short _file; /* fileno, if Unix descriptor, else -1 */ struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */ int _lbfsize; /* 0 or -_bf._size, for inline putc */ struct _reent *_data; /* operations */ _PTR _cookie; /* cookie passed to io functions */ _READ_WRITE_RETURN_TYPE _EXFUN((*_read),(_PTR _cookie, char *_buf, int _n)); _READ_WRITE_RETURN_TYPE _EXFUN((*_write),(_PTR _cookie, const char *_buf, int _n)); _fpos_t _EXFUN((*_seek),(_PTR _cookie, _fpos_t _offset, int _whence)); int _EXFUN((*_close),(_PTR _cookie)); /* separate buffer for long sequences of ungetc() */ struct __sbuf _ub; /* ungetc buffer */ unsigned char *_up; /* saved _p when _p is doing ungetc data */ int _ur; /* saved _r when _r is counting ungetc data */ /* tricks to meet minimum requirements even when malloc() fails */ unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */ unsigned char _nbuf[1]; /* guarantee a getc() buffer */ /* separate buffer for fgetline() when line crosses buffer boundary */ struct __sbuf _lb; /* buffer for fgetline() */ /* Unix stdio files get aligned to block boundaries on fseek() */ int _blksize; /* stat.st_blksize (may be != _bf._size) */ int _flags2; /* for future use */ _off64_t _offset; /* current lseek offset */ _fpos64_t _EXFUN((*_seek64),(_PTR _cookie, _fpos64_t _offset, int _whence));#ifndef __SINGLE_THREAD__ _flock_t _lock; /* for thread-safety locking */#endif};typedef struct __sFILE64 __FILE;#elsetypedef struct __sFILE __FILE;#endif /* __LARGE64_FILES */struct _glue { struct _glue *_next; int _niobs; __FILE *_iobs;};/* * rand48 family support * * Copyright (c) 1993 Martin Birgmeier * All rights reserved. * * You may redistribute unmodified or modified versions of this source * code provided that the above copyright notice and this and the * following conditions are retained. * * This software is provided ``as is'', and comes with no warranties * of any kind. I shall in no event be liable for anything that happens * to anyone/anything when using this software. */#define _RAND48_SEED_0 (0x330e)#define _RAND48_SEED_1 (0xabcd)#define _RAND48_SEED_2 (0x1234)#define _RAND48_MULT_0 (0xe66d)#define _RAND48_MULT_1 (0xdeec)#define _RAND48_MULT_2 (0x0005)#define _RAND48_ADD (0x000b)struct _rand48 { unsigned short _seed[3]; unsigned short _mult[3]; unsigned short _add;#ifdef _REENT_SMALL /* Put this in here as well, for good luck. */ __extension__ unsigned long long _rand_next;#endif};/* How big the some arrays are. */#define _REENT_EMERGENCY_SIZE 25#define _REENT_ASCTIME_SIZE 26#define _REENT_SIGNAL_SIZE 24/* * struct _reent * * This structure contains *all* globals needed by the library. * It's raison d'etre is to facilitate threads by making all library routines * reentrant. IE: All state information is contained here. */#ifdef _REENT_SMALLstruct _mprec{ /* used by mprec routines */ struct _Bigint *_result; int _result_k; struct _Bigint *_p5s; struct _Bigint **_freelist;};struct _misc_reent{ /* miscellaneous reentrant data */ char *_strtok_last; _mbstate_t _mblen_state; _mbstate_t _wctomb_state; _mbstate_t _mbtowc_state; char _l64a_buf[8]; int _getdate_err; _mbstate_t _mbrlen_state; _mbstate_t _mbrtowc_state; _mbstate_t _mbsrtowcs_state; _mbstate_t _wcrtomb_state; _mbstate_t _wcsrtombs_state;};/* This version of _reent is layed our with "int"s in pairs, to help * ports with 16-bit int's but 32-bit pointers, align nicely. */struct _reent{ /* FILE is a big struct and may change over time. To try to achieve binary compatibility with future versions, put stdin,stdout,stderr here. These are pointers into member __sf defined below. */ __FILE *_stdin, *_stdout, *_stderr; /* XXX */ int _errno; /* local copy of errno */ int _inc; /* used by tmpnam */ char *_emergency; int __sdidinit; /* 1 means stdio has been init'd */ int _current_category; /* used by setlocale */ _CONST char *_current_locale; struct _mprec *_mp; void _EXFUN((*__cleanup),(struct _reent *)); int _gamma_signgam; /* used by some fp conversion routines */ int _cvtlen; /* should be size_t */ char *_cvtbuf; struct _rand48 *_r48; struct __tm *_localtime_buf; char *_asctime_buf; /* signal info */ void (**(_sig_func))(int); /* atexit stuff */ struct _atexit *_atexit; struct _atexit _atexit0; struct _glue __sglue; /* root of glue chain */ __FILE *__sf; /* file descriptors */ struct __sFILE_fake __sf_fake; /* fake initial stdin/out/err */ struct _misc_reent *_misc; /* strtok, multibyte states */ char *_signal_buf; /* strsignal */};#define _REENT_INIT(var) \ { (__FILE *)&var.__sf_fake, \ (__FILE *)&var.__sf_fake, \ (__FILE *)&var.__sf_fake, \ 0, \ 0, \ _NULL, \ 0, \ 0, \ "C", \ _NULL, \ _NULL, \ 0, \ 0, \ _NULL, \ _NULL, \ _NULL, \ _NULL, \ _NULL, \ _NULL, \ {_NULL, 0, {_NULL}, _NULL}, \ {_NULL, 0, _NULL}, \ _NULL, \ {_NULL, 0, 0, 0, 0, {_NULL, 0}, 0, _NULL}, \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -