comparison packages/language/c/libc/current/src/stdio/common/streambuf.cxx @ 0:3111d98ba7b3 ecos-v1_1-release

Initial commit of eCos version 1.1
author jlarmour
date Tue, 11 May 1999 11:16:07 +0000
parents
children 443894e2e912
comparison
equal deleted inserted replaced
-1:000000000000 0:3111d98ba7b3
1 //===========================================================================
2 //
3 // streambuf.cxx
4 //
5 // C library stdio stream buffer functions
6 //
7 //===========================================================================
8 //####COPYRIGHTBEGIN####
9 //
10 // -------------------------------------------
11 // The contents of this file are subject to the Cygnus eCos Public License
12 // Version 1.0 (the "License"); you may not use this file except in
13 // compliance with the License. You may obtain a copy of the License at
14 // http://sourceware.cygnus.com/ecos
15 //
16 // Software distributed under the License is distributed on an "AS IS"
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
18 // License for the specific language governing rights and limitations under
19 // the License.
20 //
21 // The Original Code is eCos - Embedded Cygnus Operating System, released
22 // September 30, 1998.
23 //
24 // The Initial Developer of the Original Code is Cygnus. Portions created
25 // by Cygnus are Copyright (C) 1998 Cygnus Solutions. All Rights Reserved.
26 // -------------------------------------------
27 //
28 //####COPYRIGHTEND####
29 //===========================================================================
30 //#####DESCRIPTIONBEGIN####
31 //
32 // Author(s): jlarmour
33 // Contributors: jlarmour@cygnus.co.uk
34 // Date: 1998-02-13
35 // Purpose:
36 // Description:
37 // Usage:
38 //
39 //####DESCRIPTIONEND####
40 //
41 //===========================================================================
42
43 // CONFIGURATION
44
45 #include <pkgconf/libc.h> // Configuration header
46
47 // Include the C library? And do we want the stdio stuff? And buffered I/O?
48 #if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_STDIO) && \
49 defined(CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO)
50
51
52 // INCLUDES
53
54 #include <cyg/infra/cyg_type.h> // Common project-wide type definitions
55 #include <cyg/infra/cyg_ass.h> // Assertion support
56 #include <errno.h> // Cyg_ErrNo
57 #include "clibincl/stdlibsupp.hxx"// _malloc() and _free()
58 #include "clibincl/streambuf.hxx" // header for this file, just in case
59
60 // FUNCTIONS
61
62 Cyg_ErrNo
63 Cyg_StdioStreamBuffer::set_buffer( cyg_ucount32 size=BUFSIZE,
64 cyg_uint8 *new_buffer=NULL )
65 {
66
67 #ifdef CYGSEM_LIBC_STDIO_DYNAMIC_SETVBUF
68
69 // user-supplied buffer?
70 if (new_buffer != NULL) {
71 CYG_CHECK_DATA_PTR(new_buffer, "new_buffer not valid");
72 // first check if we were responsible for the old buffer
73 if (call_free) {
74 _free(buffer_bottom);
75 call_free = false;
76 }
77 buffer_bottom = new_buffer;
78 }
79 else if ( size != get_buffer_size() ) { // as long as its different from
80 // what we've got now
81 cyg_uint8 *malloced_buf;
82
83 malloced_buf = (cyg_uint8 * )_malloc( size );
84 if (malloced_buf == NULL)
85 return ENOMEM;
86
87 // should the old buffer be freed? This waits till after we know
88 // whether the malloc succeeded
89 if (call_free)
90 _free( buffer_bottom );
91
92 buffer_bottom = malloced_buf;
93
94 call_free=true;
95
96 } // else if
97
98
99 #else // ifdef CYGSEM_LIBC_STDIO_DYNAMIC_SETVBUF
100
101 // In this config we can't use a different buffer, or set a
102 // size greater than now. We can pretend to shrink it though
103
104 // Note on the next line we compare it with the size of buffer_bottom
105 // and not the current size, as that's what is the limiting factor
106 if ( (new_buffer != NULL) || (size > sizeof(buffer_bottom)) )
107 return EINVAL;
108
109 #endif // ifdef CYGSEM_LIBC_STDIO_DYNAMIC_SETVBUF
110
111 buffer_top = current_buffer_position = &buffer_bottom[0];
112 buffer_size = size;
113
114 return ENOERR;
115
116 } // set_buffer()
117
118
119 #endif // if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_STDIO) &&
120 // defined(CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO)
121
122
123 // EOF streambuf.cxx