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