29 #ifndef _STDIO_SYNC_FILEBUF_H 30 #define _STDIO_SYNC_FILEBUF_H 1 32 #pragma GCC system_header 40 #ifdef _GLIBCXX_USE_WCHAR_T 44 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
46 _GLIBCXX_BEGIN_NAMESPACE_VERSION
56 template<
typename _CharT,
typename _Traits = std::
char_traits<_CharT> >
63 typedef typename traits_type::int_type
int_type;
64 typedef typename traits_type::pos_type
pos_type;
65 typedef typename traits_type::off_type
off_type;
71 std::__c_file* _M_file;
80 : _M_file(__f), _M_unget_buf(traits_type::eof())
83 #if __cplusplus >= 201103L 86 _M_file(__fb._M_file), _M_unget_buf(__fb._M_unget_buf)
88 __fb._M_file =
nullptr;
89 __fb._M_unget_buf = traits_type::eof();
95 __streambuf_type::operator=(__fb);
96 _M_file = std::__exchange(__fb._M_file,
nullptr);
97 _M_unget_buf = std::__exchange(__fb._M_unget_buf, traits_type::eof());
104 __streambuf_type::swap(__fb);
105 std::swap(_M_file, __fb._M_file);
106 std::swap(_M_unget_buf, __fb._M_unget_buf);
118 file() {
return this->_M_file; }
125 syncungetc(int_type __c);
128 syncputc(int_type __c);
134 return this->syncungetc(__c);
141 _M_unget_buf = this->syncgetc();
146 pbackfail(int_type __c = traits_type::eof())
149 const int_type __eof = traits_type::eof();
152 if (traits_type::eq_int_type(__c, __eof))
154 if (!traits_type::eq_int_type(_M_unget_buf, __eof))
155 __ret = this->syncungetc(_M_unget_buf);
160 __ret = this->syncungetc(__c);
163 _M_unget_buf = __eof;
171 overflow(int_type __c = traits_type::eof())
174 if (traits_type::eq_int_type(__c, traits_type::eof()))
176 if (std::fflush(_M_file))
177 __ret = traits_type::eof();
179 __ret = traits_type::not_eof(__c);
182 __ret = this->syncputc(__c);
191 {
return std::fflush(_M_file); }
205 #ifdef _GLIBCXX_USE_LFS 206 if (!fseeko64(_M_file, __off, __whence))
209 if (!fseek(_M_file, __off, __whence))
217 std::ios_base::openmode __mode =
223 inline stdio_sync_filebuf<char>::int_type
224 stdio_sync_filebuf<char>::syncgetc()
225 {
return std::getc(_M_file); }
228 inline stdio_sync_filebuf<char>::int_type
229 stdio_sync_filebuf<char>::syncungetc(int_type __c)
230 {
return std::ungetc(__c, _M_file); }
233 inline stdio_sync_filebuf<char>::int_type
234 stdio_sync_filebuf<char>::syncputc(int_type __c)
235 {
return std::putc(__c, _M_file); }
243 _M_unget_buf = traits_type::to_int_type(__s[__ret - 1]);
245 _M_unget_buf = traits_type::eof();
252 {
return std::fwrite(__s, 1, __n, _M_file); }
254 #ifdef _GLIBCXX_USE_WCHAR_T 256 inline stdio_sync_filebuf<wchar_t>::int_type
257 stdio_sync_filebuf<wchar_t>::syncgetc()
258 {
return std::getwc(_M_file); }
261 inline stdio_sync_filebuf<wchar_t>::int_type
262 stdio_sync_filebuf<wchar_t>::syncungetc(int_type __c)
263 {
return std::ungetwc(__c, _M_file); }
266 inline stdio_sync_filebuf<wchar_t>::int_type
267 stdio_sync_filebuf<wchar_t>::syncputc(int_type __c)
268 {
return std::putwc(__c, _M_file); }
275 const int_type __eof = traits_type::eof();
278 int_type __c = this->syncgetc();
279 if (traits_type::eq_int_type(__c, __eof))
281 __s[__ret] = traits_type::to_char_type(__c);
286 _M_unget_buf = traits_type::to_int_type(__s[__ret - 1]);
288 _M_unget_buf = traits_type::eof();
294 stdio_sync_filebuf<wchar_t>::xsputn(
const wchar_t* __s,
298 const int_type __eof = traits_type::eof();
301 if (traits_type::eq_int_type(this->syncputc(*__s++), __eof))
309 #if _GLIBCXX_EXTERN_TEMPLATE 310 extern template class stdio_sync_filebuf<char>;
311 #ifdef _GLIBCXX_USE_WCHAR_T 312 extern template class stdio_sync_filebuf<wchar_t>;
316 _GLIBCXX_END_NAMESPACE_VERSION
The actual work of input and output (interface).
Class representing stream positions.
static const seekdir beg
Request a seek relative to the beginning of the stream.
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
traits_type::off_type off_type
static const seekdir cur
Request a seek relative to the current position within the sequence.
long long streamoff
Type used by fpos, char_traits<char>, and char_traits<wchar_t>.
static const openmode in
Open for input. Default for ifstream and fstream.
traits_type::int_type int_type
virtual int_type uflow()
Fetches more data from the controlled sequence.
fpos< mbstate_t > streampos
File position for char streams.
Provides a layer of compatibility for C.This GNU extension provides extensions for working with stand...
virtual int_type underflow()
Fetches more data from the controlled sequence.
GNU extensions for public use.
static const openmode out
Open for output. Default for ofstream and fstream.
traits_type::pos_type pos_type
virtual int sync()
Synchronizes the buffer arrays with the controlled sequences.