williamr@2
|
1 |
/*
|
williamr@2
|
2 |
* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
|
williamr@2
|
3 |
* All rights reserved.
|
williamr@2
|
4 |
* This component and the accompanying materials are made available
|
williamr@4
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
williamr@2
|
6 |
* which accompanies this distribution, and is available
|
williamr@4
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
williamr@2
|
8 |
*
|
williamr@2
|
9 |
* Initial Contributors:
|
williamr@2
|
10 |
* Nokia Corporation - initial contribution.
|
williamr@2
|
11 |
*
|
williamr@2
|
12 |
* Contributors:
|
williamr@2
|
13 |
*
|
williamr@2
|
14 |
* Description:
|
williamr@2
|
15 |
*
|
williamr@2
|
16 |
*/
|
williamr@2
|
17 |
|
williamr@2
|
18 |
|
williamr@2
|
19 |
|
williamr@2
|
20 |
#ifndef _SYS_STDIO_T_H_
|
williamr@2
|
21 |
#define _SYS_STDIO_T_H_
|
williamr@2
|
22 |
#ifdef __cplusplus
|
williamr@2
|
23 |
extern "C" {
|
williamr@2
|
24 |
#endif
|
williamr@2
|
25 |
|
williamr@2
|
26 |
#include <_ansi.h>
|
williamr@2
|
27 |
|
williamr@2
|
28 |
/**
|
williamr@2
|
29 |
Stdio buffers.
|
williamr@2
|
30 |
@publishedAll
|
williamr@2
|
31 |
@released
|
williamr@2
|
32 |
*/
|
williamr@2
|
33 |
struct __sbuf {
|
williamr@2
|
34 |
unsigned char * _base;
|
williamr@2
|
35 |
int _size;
|
williamr@2
|
36 |
};
|
williamr@2
|
37 |
|
williamr@2
|
38 |
/**
|
williamr@2
|
39 |
We need fpos_t for the following, but it doesn't have a leading "_",
|
williamr@2
|
40 |
so we use _fpos_t instead.
|
williamr@2
|
41 |
@publishedAll
|
williamr@2
|
42 |
@released
|
williamr@2
|
43 |
*/
|
williamr@2
|
44 |
|
williamr@2
|
45 |
typedef long _fpos_t; /* XXX must match off_t in <sys/types.h> */
|
williamr@2
|
46 |
/* (and must be `long' for now) */
|
williamr@2
|
47 |
|
williamr@2
|
48 |
/**
|
williamr@2
|
49 |
Stdio state variables.
|
williamr@2
|
50 |
|
williamr@2
|
51 |
The following always hold:
|
williamr@2
|
52 |
|
williamr@2
|
53 |
if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR),
|
williamr@2
|
54 |
_lbfsize is -_bf._size, else _lbfsize is 0
|
williamr@2
|
55 |
if _flags&__SRD, _w is 0
|
williamr@2
|
56 |
if _flags&__SWR, _r is 0
|
williamr@2
|
57 |
|
williamr@2
|
58 |
This ensures that the getc and putc macros (or inline functions) never
|
williamr@2
|
59 |
try to write or read from a file that is in `read' or `write' mode.
|
williamr@2
|
60 |
(Moreover, they can, and do, automatically switch from read mode to
|
williamr@2
|
61 |
write mode, and back, on "r+" and "w+" files.)
|
williamr@2
|
62 |
|
williamr@2
|
63 |
_lbfsize is used only to make the inline line-buffered output stream
|
williamr@2
|
64 |
code as compact as possible.
|
williamr@2
|
65 |
|
williamr@2
|
66 |
_ub, _up, and _ur are used when ungetc() pushes back more characters
|
williamr@2
|
67 |
than fit in the current _bf, or when ungetc() pushes back a character
|
williamr@2
|
68 |
that does not match the previous one in _bf. When this happens,
|
williamr@2
|
69 |
_ub._base becomes non-nil (i.e., a stream has ungetc() data iff
|
williamr@2
|
70 |
_ub._base!=NULL) and _up and _ur save the current values of _p and _r.
|
williamr@2
|
71 |
@publishedAll
|
williamr@2
|
72 |
@released
|
williamr@2
|
73 |
*/
|
williamr@2
|
74 |
struct __sFILE {
|
williamr@2
|
75 |
unsigned char *_p; /* current position in (some) buffer */
|
williamr@2
|
76 |
int _r; /* read space left for getc() */
|
williamr@2
|
77 |
int _w; /* write space left for putc() */
|
williamr@2
|
78 |
short _flags; /* flags, below; this FILE is free if 0 */
|
williamr@2
|
79 |
short _file; /* fileno, if Unix descriptor, else -1 */
|
williamr@2
|
80 |
struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */
|
williamr@2
|
81 |
int _lbfsize; /* 0 or -_bf._size, for inline putc */
|
williamr@2
|
82 |
|
williamr@2
|
83 |
/* operations */
|
williamr@2
|
84 |
void * _cookie; /* cookie passed to io functions */
|
williamr@2
|
85 |
|
williamr@2
|
86 |
int (*_read) (void * _cookie, char *_buf, int _n);
|
williamr@2
|
87 |
int (*_write)(void * _cookie, const char *_buf, int _n);
|
williamr@2
|
88 |
_fpos_t (*_seek) (void * _cookie, _fpos_t _offset, int _whence);
|
williamr@2
|
89 |
int (*_close)(void * _cookie);
|
williamr@2
|
90 |
|
williamr@2
|
91 |
/* separate buffer for long sequences of ungetc() */
|
williamr@2
|
92 |
struct __sbuf _ub; /* ungetc buffer */
|
williamr@2
|
93 |
unsigned char * _up; /* saved _p when _p is doing ungetc data */
|
williamr@2
|
94 |
int _ur; /* saved _r when _r is counting ungetc data */
|
williamr@2
|
95 |
|
williamr@2
|
96 |
/* tricks to meet minimum requirements even when malloc() fails */
|
williamr@2
|
97 |
unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */
|
williamr@2
|
98 |
unsigned char _nbuf[1]; /* guarantee a getc() buffer */
|
williamr@2
|
99 |
|
williamr@2
|
100 |
/* separate buffer for fgetline() when line crosses buffer boundary */
|
williamr@2
|
101 |
struct __sbuf _lb; /* buffer for fgetline() */
|
williamr@2
|
102 |
|
williamr@2
|
103 |
/* Unix stdio files get aligned to block boundaries on fseek() */
|
williamr@2
|
104 |
int _blksize; /* stat.st_blksize (may be != _bf._size) */
|
williamr@2
|
105 |
int _offset; /* current lseek offset */
|
williamr@2
|
106 |
|
williamr@2
|
107 |
struct _reent * _data; /* pointer back to re-entrancy context block */
|
williamr@2
|
108 |
};
|
williamr@2
|
109 |
|
williamr@2
|
110 |
|
williamr@2
|
111 |
#ifdef __cplusplus
|
williamr@2
|
112 |
}
|
williamr@2
|
113 |
#endif
|
williamr@2
|
114 |
#endif /* _SYS_STDIO_T_H_ */
|