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