1
/* Copyright (C) 2004 Garrett A. Kajmowicz
3
This file is part of the uClibc++ Library.
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Lesser General Public
7
License as published by the Free Software Foundation; either
8
version 2.1 of the License, or (at your option) any later version.
10
This library is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Lesser General Public License for more details.
15
You should have received a copy of the GNU Lesser General Public
16
License along with this library; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
#if ! defined(__AVR__)
22
#define __UCLIBCXX_COMPILE_FSTREAM__ 1
28
#ifdef __UCLIBCXX_EXPAND_FSTREAM_CHAR__
30
#ifdef __UCLIBCXX_EXPAND_CONSTRUCTORS_DESTRUCTORS__
32
template _UCXXEXPORT filebuf::basic_filebuf();
33
template _UCXXEXPORT filebuf::~basic_filebuf();
35
#endif //__UCLIBCXX_EXPAND_CONSTRUCTORS_DESTRUCTORS__
37
template _UCXXEXPORT filebuf::int_type filebuf::pbackfail(filebuf::int_type c);
38
template _UCXXEXPORT filebuf * filebuf::open(const char* s, ios_base::openmode mode);
39
template _UCXXEXPORT filebuf * filebuf::close();
40
template _UCXXEXPORT filebuf::int_type filebuf::overflow(filebuf::int_type);
41
template _UCXXEXPORT filebuf::int_type filebuf::underflow ();
42
template _UCXXEXPORT streamsize filebuf::xsputn(const char* s, streamsize n);
44
template _UCXXEXPORT basic_streambuf<char, char_traits<char> >*
45
filebuf::setbuf(char * s, streamsize n);
48
#ifdef __UCLIBCXX_EXPAND_CONSTRUCTORS_DESTRUCTORS__
50
template _UCXXEXPORT basic_ofstream<char, char_traits<char> >::basic_ofstream();
51
template _UCXXEXPORT basic_ofstream<char, char_traits<char> >::basic_ofstream(const char* s, ios_base::openmode mode);
52
template _UCXXEXPORT basic_ofstream<char, char_traits<char> >::~basic_ofstream();
54
template _UCXXEXPORT basic_ifstream<char, char_traits<char> >::basic_ifstream();
55
template _UCXXEXPORT basic_ifstream<char, char_traits<char> >::basic_ifstream(const char* s, ios_base::openmode mode);
56
template _UCXXEXPORT basic_ifstream<char, char_traits<char> >::~basic_ifstream();
58
#endif //__UCLIBCXX_EXPAND_CONSTRUCTORS_DESTRUCTORS__
65
#ifdef __UCLIBCXX_HAS_WCHAR__
67
template <> _UCXXEXPORT basic_filebuf<wchar_t, char_traits<wchar_t> >::int_type
68
basic_filebuf<wchar_t, char_traits<wchar_t> >::overflow(int_type c)
70
typedef basic_streambuf<wchar_t, char_traits<wchar_t> > wstreambuf;
71
typedef char_traits<wchar_t> wtraits;
73
if(is_open() == false){
75
return wtraits::eof();
83
if( wstreambuf::pbase() != 0 ){
85
//Write all possible character from the existing array first
86
size_t chars_written = 0;
87
while(wstreambuf::pbase() && (wstreambuf::pbase() + chars_written !=wstreambuf::pptr()) ){
88
out_size = wcrtomb(out_array, wstreambuf::pbase()[chars_written], &ps);
89
if(out_size == (size_t)(-1) || fwrite(out_array, out_size, 1, fp) == 0){
95
if( wstreambuf::pbase() + chars_written == wstreambuf::pptr() ){
96
wstreambuf::pbump(-chars_written);
98
//Shuffle data back into order
99
size_t chars_left = wstreambuf::pptr() - wstreambuf::pbase() - chars_written;
100
for(size_t i = 0; i < chars_left; ++i){
101
wstreambuf::pbase()[i] = (wstreambuf::pptr() - chars_written)[i];
103
return wtraits::eof();
107
if( !wtraits::eq_int_type(c, wtraits::eof()) ){
108
out_size = wcrtomb(out_array, c, &ps);
109
if(out_size == (size_t)(-1) || fwrite(out_array, out_size, 1, fp) == 0){
110
return wtraits::eof();
115
return wtraits::not_eof(c);
119
template <> _UCXXEXPORT basic_filebuf<wchar_t, char_traits<wchar_t> >::int_type
120
basic_filebuf<wchar_t, char_traits<wchar_t> >::underflow()
122
/*Some variables used internally:
129
eback() returns mgbeg
130
gptr() returns mgnext
131
egptr() returns mgend
133
gbump(int n) mgnext+=n
136
typedef char_traits<wchar_t> traits;
137
typedef basic_streambuf<wchar_t, traits> wstreambuf;
140
if(wstreambuf::eback() == wstreambuf::gptr() && 0 != wstreambuf::eback()){ //Buffer is full
141
return traits::to_int_type(*wstreambuf::gptr());
152
fprintf(stderr, "WEOF returned by fgetwc\n");
153
return traits::eof();
156
c = traits::to_char_type(wi);
158
if(wstreambuf::eback() == 0){
159
return traits::to_int_type(c);
162
for(wchar_t * i = wstreambuf::gptr(); i < wstreambuf::egptr(); ++i){
166
*(wstreambuf::egptr()-1) = c;
168
wstreambuf::mgnext -= 1;
170
return traits::to_int_type(*wstreambuf::gptr());
173
#endif // __UCLIBCXX_HAS_WCHAR__
178
#endif // not ARDUINO