williamr@2: /* williamr@2: * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). williamr@2: * All rights reserved. williamr@2: * This component and the accompanying materials are made available williamr@4: * under the terms of "Eclipse Public License v1.0" williamr@2: * which accompanies this distribution, and is available williamr@4: * at the URL "http://www.eclipse.org/legal/epl-v10.html". williamr@2: * williamr@2: * Initial Contributors: williamr@2: * Nokia Corporation - initial contribution. williamr@2: * williamr@2: * Contributors: williamr@2: * williamr@2: * Description: williamr@2: * williamr@2: */ williamr@2: williamr@2: williamr@2: williamr@2: #ifndef _SYS_STDIO_T_H_ williamr@2: #define _SYS_STDIO_T_H_ williamr@2: #ifdef __cplusplus williamr@2: extern "C" { williamr@2: #endif williamr@2: williamr@2: #include <_ansi.h> williamr@2: williamr@2: /** williamr@2: Stdio buffers. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: struct __sbuf { williamr@2: unsigned char * _base; williamr@2: int _size; williamr@2: }; williamr@2: williamr@2: /** williamr@2: We need fpos_t for the following, but it doesn't have a leading "_", williamr@2: so we use _fpos_t instead. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: williamr@2: typedef long _fpos_t; /* XXX must match off_t in */ williamr@2: /* (and must be `long' for now) */ williamr@2: williamr@2: /** williamr@2: Stdio state variables. williamr@2: williamr@2: The following always hold: williamr@2: williamr@2: if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR), williamr@2: _lbfsize is -_bf._size, else _lbfsize is 0 williamr@2: if _flags&__SRD, _w is 0 williamr@2: if _flags&__SWR, _r is 0 williamr@2: williamr@2: This ensures that the getc and putc macros (or inline functions) never williamr@2: try to write or read from a file that is in `read' or `write' mode. williamr@2: (Moreover, they can, and do, automatically switch from read mode to williamr@2: write mode, and back, on "r+" and "w+" files.) williamr@2: williamr@2: _lbfsize is used only to make the inline line-buffered output stream williamr@2: code as compact as possible. williamr@2: williamr@2: _ub, _up, and _ur are used when ungetc() pushes back more characters williamr@2: than fit in the current _bf, or when ungetc() pushes back a character williamr@2: that does not match the previous one in _bf. When this happens, williamr@2: _ub._base becomes non-nil (i.e., a stream has ungetc() data iff williamr@2: _ub._base!=NULL) and _up and _ur save the current values of _p and _r. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: struct __sFILE { williamr@2: unsigned char *_p; /* current position in (some) buffer */ williamr@2: int _r; /* read space left for getc() */ williamr@2: int _w; /* write space left for putc() */ williamr@2: short _flags; /* flags, below; this FILE is free if 0 */ williamr@2: short _file; /* fileno, if Unix descriptor, else -1 */ williamr@2: struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */ williamr@2: int _lbfsize; /* 0 or -_bf._size, for inline putc */ williamr@2: williamr@2: /* operations */ williamr@2: void * _cookie; /* cookie passed to io functions */ williamr@2: williamr@2: int (*_read) (void * _cookie, char *_buf, int _n); williamr@2: int (*_write)(void * _cookie, const char *_buf, int _n); williamr@2: _fpos_t (*_seek) (void * _cookie, _fpos_t _offset, int _whence); williamr@2: int (*_close)(void * _cookie); williamr@2: williamr@2: /* separate buffer for long sequences of ungetc() */ williamr@2: struct __sbuf _ub; /* ungetc buffer */ williamr@2: unsigned char * _up; /* saved _p when _p is doing ungetc data */ williamr@2: int _ur; /* saved _r when _r is counting ungetc data */ williamr@2: williamr@2: /* tricks to meet minimum requirements even when malloc() fails */ williamr@2: unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */ williamr@2: unsigned char _nbuf[1]; /* guarantee a getc() buffer */ williamr@2: williamr@2: /* separate buffer for fgetline() when line crosses buffer boundary */ williamr@2: struct __sbuf _lb; /* buffer for fgetline() */ williamr@2: williamr@2: /* Unix stdio files get aligned to block boundaries on fseek() */ williamr@2: int _blksize; /* stat.st_blksize (may be != _bf._size) */ williamr@2: int _offset; /* current lseek offset */ williamr@2: williamr@2: struct _reent * _data; /* pointer back to re-entrancy context block */ williamr@2: }; williamr@2: williamr@2: williamr@2: #ifdef __cplusplus williamr@2: } williamr@2: #endif williamr@2: #endif /* _SYS_STDIO_T_H_ */