OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [language/] [c/] [libc/] [stdio/] [current/] [include/] [streambuf.inl] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
#ifndef CYGONCE_LIBC_STDIO_STREAMBUF_INL
2
#define CYGONCE_LIBC_STDIO_STREAMBUF_INL
3
//===========================================================================
4
//
5
//      streambuf.inl
6
//
7
//      Internal C library stdio stream buffer inline functions
8
//
9
//===========================================================================
10
// ####ECOSGPLCOPYRIGHTBEGIN####
11
// -------------------------------------------
12
// This file is part of eCos, the Embedded Configurable Operating System.
13
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
14
//
15
// eCos is free software; you can redistribute it and/or modify it under
16
// the terms of the GNU General Public License as published by the Free
17
// Software Foundation; either version 2 or (at your option) any later
18
// version.
19
//
20
// eCos is distributed in the hope that it will be useful, but WITHOUT
21
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
23
// for more details.
24
//
25
// You should have received a copy of the GNU General Public License
26
// along with eCos; if not, write to the Free Software Foundation, Inc.,
27
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
28
//
29
// As a special exception, if other files instantiate templates or use
30
// macros or inline functions from this file, or you compile this file
31
// and link it with other works to produce a work based on this file,
32
// this file does not by itself cause the resulting work to be covered by
33
// the GNU General Public License. However the source code for this file
34
// must still be made available in accordance with section (3) of the GNU
35
// General Public License v2.
36
//
37
// This exception does not invalidate any other reasons why a work based
38
// on this file might be covered by the GNU General Public License.
39
// -------------------------------------------
40
// ####ECOSGPLCOPYRIGHTEND####
41
//===========================================================================
42
//#####DESCRIPTIONBEGIN####
43
//
44
// Author(s):    jlarmour
45
// Contributors:
46
// Date:         2000-04-19
47
// Purpose:
48
// Description:
49
// Usage:       Do not include this file directly, instead
50
//              #include 
51
//
52
//####DESCRIPTIONEND####
53
//
54
//===========================================================================
55
 
56
// CONFIGURATION
57
 
58
#include    // Configuration header
59
 
60
// Include buffered I/O?
61
#if defined(CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO)
62
 
63
 
64
// INCLUDES
65
 
66
#include           // Common project-wide type definitions
67
#include            // Assertion support
68
#include                        // Cyg_ErrNo
69
#include                        // fpos_t and iobuf defines
70
#include                       // free()
71
#include   // header for this file, just in case
72
#include                       // INT_MAX
73
 
74
// FUNCTIONS
75
 
76
inline
77
Cyg_StdioStreamBuffer::Cyg_StdioStreamBuffer( cyg_ucount32 size,
78
                                              cyg_uint8 *new_buffer ) :
79
#if defined(CYGSEM_LIBC_STDIO_SETVBUF_MALLOC)
80
    call_free(false),
81
    buffer_bottom( NULL ),
82
    buffer_size(0),
83
#else
84
    buffer_bottom( static_buffer ),
85
    buffer_size(sizeof(static_buffer)),
86
#endif
87
    buffer_top(NULL),
88
    current_buffer_position(NULL)
89
{
90
    // NB Many of the above members in the initialisation list may seem
91
    // unnecessary, but it is to ensure a defined state if e.g. the malloc
92
    // in set_buffer() should fail
93
 
94
    (void)set_buffer(size, new_buffer);
95
} // Cyg_StdioStreamBuffer constructor
96
 
97
 
98
inline
99
Cyg_StdioStreamBuffer::~Cyg_StdioStreamBuffer()
100
{
101
#ifdef CYGSEM_LIBC_STDIO_SETVBUF_MALLOC
102
    if ((buffer_bottom != NULL) && call_free)
103
        free( buffer_bottom );
104
#endif
105
} // Cyg_StdioStreamBuffer destructor
106
 
107
 
108
inline cyg_ucount32
109
Cyg_StdioStreamBuffer::get_buffer_space_used( void )
110
{
111
    return (buffer_top - current_buffer_position);
112
} // get_buffer_space_used()
113
 
114
 
115
inline cyg_count32
116
Cyg_StdioStreamBuffer::get_buffer_size( void )
117
{
118
#ifdef CYGSEM_LIBC_STDIO_DYNAMIC_SETVBUF
119
    if (buffer_bottom==NULL)
120
        return -1;
121
#endif
122
    return buffer_size;
123
} // get_buffer_size()
124
 
125
 
126
inline cyg_ucount32
127
Cyg_StdioStreamBuffer::get_buffer_addr_to_read( cyg_uint8 **buffer )
128
{
129
    *buffer = current_buffer_position;
130
 
131
    return (buffer_top - current_buffer_position);
132
} // get_buffer_addr_to_read()
133
 
134
inline void
135
Cyg_StdioStreamBuffer::set_bytes_read( cyg_ucount32 bytes )
136
{
137
    cyg_uint8 *buffer_max = &buffer_bottom[ get_buffer_size() ];
138
 
139
    current_buffer_position += bytes;
140
 
141
    // INT_MAX is used by some callers to mean infinite.
142
    CYG_ASSERT( (current_buffer_position <= buffer_top)
143
                || (get_buffer_size() == INT_MAX),
144
                "read too many bytes from buffer" );
145
 
146
    if (current_buffer_position == buffer_max)
147
        current_buffer_position = buffer_top = &buffer_bottom[0];
148
 
149
} // set_bytes_read()
150
 
151
 
152
inline cyg_ucount32
153
Cyg_StdioStreamBuffer::get_buffer_addr_to_write( cyg_uint8 **buffer )
154
{
155
    cyg_uint8 *buffer_max = &buffer_bottom[ get_buffer_size() ];
156
 
157
    *buffer = buffer_top;
158
 
159
    return (buffer_max - buffer_top);
160
} // get_buffer_addr_to_write()
161
 
162
 
163
inline void
164
Cyg_StdioStreamBuffer::set_bytes_written( cyg_ucount32 bytes )
165
{
166
    buffer_top += bytes;
167
 
168
    // INT_MAX is used by some callers to mean infinite.
169
    CYG_ASSERT( (buffer_top <= &buffer_bottom[ get_buffer_size() ])
170
                || (get_buffer_size() == INT_MAX),
171
                "wrote too many bytes into buffer" );
172
} // set_bytes_written()
173
 
174
 
175
inline void
176
Cyg_StdioStreamBuffer::drain_buffer( void )
177
{
178
    buffer_top = current_buffer_position = &buffer_bottom[0];
179
} // drain_buffer()
180
 
181
#endif // if defined(CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO)
182
 
183
#endif // CYGONCE_LIBC_STDIO_STREAMBUF_INL multiple inclusion protection
184
 
185
// EOF streambuf.inl

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.