29 #ifndef _STDIO_SYNC_FILEBUF_H
30 #define _STDIO_SYNC_FILEBUF_H 1
32 #pragma GCC system_header
39 #ifdef _GLIBCXX_USE_WCHAR_T
43 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
46 template<typename _CharT, typename _Traits = std::char_traits<_CharT> >
53 typedef typename traits_type::int_type
int_type;
54 typedef typename traits_type::pos_type
pos_type;
55 typedef typename traits_type::off_type
off_type;
59 std::__c_file*
const _M_file;
63 int_type _M_unget_buf;
68 : _M_file(__f), _M_unget_buf(traits_type::eof())
79 file() {
return this->_M_file; }
86 syncungetc(int_type __c);
89 syncputc(int_type __c);
94 int_type __c = this->syncgetc();
95 return this->syncungetc(__c);
102 _M_unget_buf = this->syncgetc();
110 const int_type __eof = traits_type::eof();
113 if (traits_type::eq_int_type(__c, __eof))
115 if (!traits_type::eq_int_type(_M_unget_buf, __eof))
116 __ret = this->syncungetc(_M_unget_buf);
121 __ret = this->syncungetc(__c);
124 _M_unget_buf = __eof;
135 if (traits_type::eq_int_type(__c, traits_type::eof()))
137 if (std::fflush(_M_file))
138 __ret = traits_type::eof();
140 __ret = traits_type::not_eof(__c);
143 __ret = this->syncputc(__c);
152 {
return std::fflush(_M_file); }
166 #ifdef _GLIBCXX_USE_LFS
167 if (!fseeko64(_M_file, __off, __whence))
170 if (!fseek(_M_file, __off, __whence))
178 std::ios_base::openmode __mode =
184 inline stdio_sync_filebuf<char>::int_type
185 stdio_sync_filebuf<char>::syncgetc()
186 {
return std::getc(_M_file); }
189 inline stdio_sync_filebuf<char>::int_type
190 stdio_sync_filebuf<char>::syncungetc(int_type __c)
191 {
return std::ungetc(__c, _M_file); }
194 inline stdio_sync_filebuf<char>::int_type
195 stdio_sync_filebuf<char>::syncputc(int_type __c)
196 {
return std::putc(__c, _M_file); }
204 _M_unget_buf = traits_type::to_int_type(__s[__ret - 1]);
206 _M_unget_buf = traits_type::eof();
213 {
return std::fwrite(__s, 1, __n, _M_file); }
215 #ifdef _GLIBCXX_USE_WCHAR_T
217 inline stdio_sync_filebuf<wchar_t>::int_type
218 stdio_sync_filebuf<wchar_t>::syncgetc()
219 {
return std::getwc(_M_file); }
222 inline stdio_sync_filebuf<wchar_t>::int_type
223 stdio_sync_filebuf<wchar_t>::syncungetc(int_type __c)
224 {
return std::ungetwc(__c, _M_file); }
227 inline stdio_sync_filebuf<wchar_t>::int_type
228 stdio_sync_filebuf<wchar_t>::syncputc(int_type __c)
229 {
return std::putwc(__c, _M_file); }
236 const int_type __eof = traits_type::eof();
239 int_type __c = this->syncgetc();
240 if (traits_type::eq_int_type(__c, __eof))
242 __s[__ret] = traits_type::to_char_type(__c);
247 _M_unget_buf = traits_type::to_int_type(__s[__ret - 1]);
249 _M_unget_buf = traits_type::eof();
255 stdio_sync_filebuf<wchar_t>::xsputn(
const wchar_t* __s,
259 const int_type __eof = traits_type::eof();
262 if (traits_type::eq_int_type(this->syncputc(*__s++), __eof))
270 #if _GLIBCXX_EXTERN_TEMPLATE
271 extern template class stdio_sync_filebuf<char>;
272 #ifdef _GLIBCXX_USE_WCHAR_T
273 extern template class stdio_sync_filebuf<wchar_t>;
277 _GLIBCXX_END_NAMESPACE
virtual int_type underflow()
Fetches more data from the controlled sequence.
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
fpos< mbstate_t > streampos
File position for char streams.
traits_type::pos_type pos_type
class stdio_sync_filebuf.
static const openmode out
Open for output. Default for ofstream and fstream.
Class representing stream positions.
virtual int sync()
Synchronizes the buffer arrays with the controlled sequences.
static const seekdir cur
Request a seek relative to the current position within the sequence.
static const seekdir beg
Request a seek relative to the beginning of the stream.
static const openmode in
Open for input. Default for ifstream and fstream.
std::__c_file *const file()
traits_type::off_type off_type
long long streamoff
Type used by fpos, char_traits, and char_traits.
virtual int_type overflow(int_type __c=traits_type::eof())
Consumes data from the buffer; writes to the controlled sequence.
virtual int_type pbackfail(int_type __c=traits_type::eof())
Tries to back up the input sequence.
traits_type::int_type int_type
virtual int_type uflow()
Fetches more data from the controlled sequence.