Mercurial > flash_v2
comparison packages/language/c/libc/stdio/current/include/streambuf.inl @ 115:6ed91473a1cd ecos-sw-2000-08-21
Merge from eCos master repository on 2000-08-21-22:40:54-BST
| author | jlarmour |
|---|---|
| date | Fri, 25 Aug 2000 17:32:38 +0000 |
| parents | |
| children | 0ae0bc38e387 |
comparison
equal
deleted
inserted
replaced
| 114:5ad2b71d525e | 115:6ed91473a1cd |
|---|---|
| 1 #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 //####COPYRIGHTBEGIN#### | |
| 11 // | |
| 12 // ------------------------------------------- | |
| 13 // The contents of this file are subject to the Red Hat eCos Public License | |
| 14 // Version 1.1 (the "License"); you may not use this file except in | |
| 15 // compliance with the License. You may obtain a copy of the License at | |
| 16 // http://www.redhat.com/ | |
| 17 // | |
| 18 // Software distributed under the License is distributed on an "AS IS" | |
| 19 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the | |
| 20 // License for the specific language governing rights and limitations under | |
| 21 // the License. | |
| 22 // | |
| 23 // The Original Code is eCos - Embedded Configurable Operating System, | |
| 24 // released September 30, 1998. | |
| 25 // | |
| 26 // The Initial Developer of the Original Code is Red Hat. | |
| 27 // Portions created by Red Hat are | |
| 28 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc. | |
| 29 // All Rights Reserved. | |
| 30 // ------------------------------------------- | |
| 31 // | |
| 32 //####COPYRIGHTEND#### | |
| 33 //=========================================================================== | |
| 34 //#####DESCRIPTIONBEGIN#### | |
| 35 // | |
| 36 // Author(s): jlarmour | |
| 37 // Contributors: | |
| 38 // Date: 2000-04-19 | |
| 39 // Purpose: | |
| 40 // Description: | |
| 41 // Usage: Do not include this file directly, instead | |
| 42 // #include <cyg/libc/stdio/streambuf.hxx> | |
| 43 // | |
| 44 //####DESCRIPTIONEND#### | |
| 45 // | |
| 46 //=========================================================================== | |
| 47 | |
| 48 // CONFIGURATION | |
| 49 | |
| 50 #include <pkgconf/libc_stdio.h> // Configuration header | |
| 51 | |
| 52 // Include buffered I/O? | |
| 53 #if defined(CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO) | |
| 54 | |
| 55 | |
| 56 // INCLUDES | |
| 57 | |
| 58 #include <cyg/infra/cyg_type.h> // Common project-wide type definitions | |
| 59 #include <cyg/infra/cyg_ass.h> // Assertion support | |
| 60 #include <errno.h> // Cyg_ErrNo | |
| 61 #include <stdio.h> // fpos_t and iobuf defines | |
| 62 #include <stdlib.h> // free() | |
| 63 #include <cyg/libc/stdio/streambuf.hxx> // header for this file, just in case | |
| 64 | |
| 65 // FUNCTIONS | |
| 66 | |
| 67 inline | |
| 68 Cyg_StdioStreamBuffer::Cyg_StdioStreamBuffer( cyg_ucount32 size=BUFSIZ, | |
| 69 cyg_uint8 *new_buffer=NULL ) : | |
| 70 #if defined(CYGSEM_LIBC_STDIO_SETVBUF_MALLOC) | |
| 71 call_free(false), | |
| 72 buffer_bottom( NULL ), | |
| 73 buffer_size(0), | |
| 74 #else | |
| 75 buffer_bottom( static_buffer ), | |
| 76 buffer_size(sizeof(static_buffer)), | |
| 77 #endif | |
| 78 buffer_top(NULL), | |
| 79 current_buffer_position(NULL) | |
| 80 { | |
| 81 // NB Many of the above members in the initialisation list may seem | |
| 82 // unnecessary, but it is to ensure a defined state if e.g. the malloc | |
| 83 // in set_buffer() should fail | |
| 84 | |
| 85 (void)set_buffer(size, new_buffer); | |
| 86 } // Cyg_StdioStreamBuffer constructor | |
| 87 | |
| 88 | |
| 89 inline | |
| 90 Cyg_StdioStreamBuffer::~Cyg_StdioStreamBuffer() | |
| 91 { | |
| 92 #ifdef CYGSEM_LIBC_STDIO_DYNAMIC_SETVBUF | |
| 93 if ((buffer_bottom != NULL) && call_free) | |
| 94 free( buffer_bottom ); | |
| 95 #endif | |
| 96 } // Cyg_StdioStreamBuffer destructor | |
| 97 | |
| 98 | |
| 99 inline cyg_ucount32 | |
| 100 Cyg_StdioStreamBuffer::get_buffer_space_used( void ) | |
| 101 { | |
| 102 return (buffer_top - current_buffer_position); | |
| 103 } // get_buffer_space_used() | |
| 104 | |
| 105 | |
| 106 inline cyg_count32 | |
| 107 Cyg_StdioStreamBuffer::get_buffer_size( void ) | |
| 108 { | |
| 109 #ifdef CYGSEM_LIBC_STDIO_DYNAMIC_SETVBUF | |
| 110 if (buffer_bottom==NULL) | |
| 111 return -1; | |
| 112 #endif | |
| 113 return buffer_size; | |
| 114 } // get_buffer_size() | |
| 115 | |
| 116 | |
| 117 inline cyg_ucount32 | |
| 118 Cyg_StdioStreamBuffer::get_buffer_addr_to_read( cyg_uint8 **buffer ) | |
| 119 { | |
| 120 *buffer = current_buffer_position; | |
| 121 | |
| 122 return (buffer_top - current_buffer_position); | |
| 123 } // get_buffer_addr_to_read() | |
| 124 | |
| 125 inline void | |
| 126 Cyg_StdioStreamBuffer::set_bytes_read( cyg_ucount32 bytes ) | |
| 127 { | |
| 128 cyg_uint8 *buffer_max = &buffer_bottom[ get_buffer_size() ]; | |
| 129 | |
| 130 current_buffer_position += bytes; | |
| 131 | |
| 132 CYG_ASSERT( (current_buffer_position <= buffer_top), | |
| 133 "read too many bytes from buffer" ); | |
| 134 | |
| 135 if (current_buffer_position == buffer_max) | |
| 136 current_buffer_position = buffer_top = &buffer_bottom[0]; | |
| 137 | |
| 138 } // set_bytes_read() | |
| 139 | |
| 140 | |
| 141 inline cyg_ucount32 | |
| 142 Cyg_StdioStreamBuffer::get_buffer_addr_to_write( cyg_uint8 **buffer ) | |
| 143 { | |
| 144 cyg_uint8 *buffer_max = &buffer_bottom[ get_buffer_size() ]; | |
| 145 | |
| 146 *buffer = buffer_top; | |
| 147 | |
| 148 return (buffer_max - buffer_top); | |
| 149 } // get_buffer_addr_to_write() | |
| 150 | |
| 151 | |
| 152 inline void | |
| 153 Cyg_StdioStreamBuffer::set_bytes_written( cyg_ucount32 bytes ) | |
| 154 { | |
| 155 buffer_top += bytes; | |
| 156 | |
| 157 CYG_ASSERT( (buffer_top <= &buffer_bottom[ get_buffer_size() ]), | |
| 158 "wrote too many bytes into buffer" ); | |
| 159 } // set_bytes_written() | |
| 160 | |
| 161 | |
| 162 inline void | |
| 163 Cyg_StdioStreamBuffer::drain_buffer( void ) | |
| 164 { | |
| 165 buffer_top = current_buffer_position = &buffer_bottom[0]; | |
| 166 } // drain_buffer() | |
| 167 | |
| 168 #endif // if defined(CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO) | |
| 169 | |
| 170 #endif CYGONCE_LIBC_STDIO_STREAMBUF_INL multiple inclusion protection | |
| 171 | |
| 172 // EOF streambuf.inl |
