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