29#ifndef _STDIO_SYNC_FILEBUF_H
30#define _STDIO_SYNC_FILEBUF_H 1
33#pragma GCC system_header
43#ifdef _GLIBCXX_USE_WCHAR_T
47namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
49_GLIBCXX_BEGIN_NAMESPACE_VERSION
59 template<
typename _CharT,
typename _Traits = std::
char_traits<_CharT> >
64 typedef _CharT char_type;
65 typedef _Traits traits_type;
66 typedef typename traits_type::int_type int_type;
67 typedef typename traits_type::pos_type pos_type;
68 typedef typename traits_type::off_type off_type;
74 std::__c_file* _M_file;
78 int_type _M_unget_buf;
82 stdio_sync_filebuf(std::__c_file* __f)
83 : _M_file(__f), _M_unget_buf(traits_type::eof())
86#if __cplusplus >= 201103L
87 stdio_sync_filebuf(stdio_sync_filebuf&& __fb) noexcept
89 _M_file(__fb._M_file), _M_unget_buf(__fb._M_unget_buf)
91 __fb._M_file =
nullptr;
92 __fb._M_unget_buf = traits_type::eof();
96 operator=(stdio_sync_filebuf&& __fb)
noexcept
98 __streambuf_type::operator=(__fb);
99 _M_file = std::__exchange(__fb._M_file,
nullptr);
100 _M_unget_buf = std::__exchange(__fb._M_unget_buf, traits_type::eof());
105 swap(stdio_sync_filebuf& __fb)
107 __streambuf_type::swap(__fb);
108 std::swap(_M_file, __fb._M_file);
109 std::swap(_M_unget_buf, __fb._M_unget_buf);
121 file() {
return this->_M_file; }
136 int_type __c = this->syncgetc();
137 return this->syncungetc(__c);
144 _M_unget_buf = this->syncgetc();
152 const int_type __eof = traits_type::eof();
155 if (traits_type::eq_int_type(__c, __eof))
157 if (!traits_type::eq_int_type(_M_unget_buf, __eof))
158 __ret = this->syncungetc(_M_unget_buf);
163 __ret = this->syncungetc(__c);
166 _M_unget_buf = __eof;
177 if (traits_type::eq_int_type(__c, traits_type::eof()))
179 if (std::fflush(_M_file))
180 __ret = traits_type::eof();
182 __ret = traits_type::not_eof(__c);
185 __ret = this->syncputc(__c);
194 {
return std::fflush(_M_file); }
208#ifdef _GLIBCXX_USE_LFS
209 if (!fseeko64(_M_file, __off, __whence))
212 if (!fseek(_M_file, __off, __whence))
226 inline stdio_sync_filebuf<char>::int_type
227 stdio_sync_filebuf<char>::syncgetc()
228 {
return std::getc(_M_file); }
231 inline stdio_sync_filebuf<char>::int_type
232 stdio_sync_filebuf<char>::syncungetc(
int_type __c)
233 {
return std::ungetc(__c, _M_file); }
236 inline stdio_sync_filebuf<char>::int_type
237 stdio_sync_filebuf<char>::syncputc(
int_type __c)
238 {
return std::putc(__c, _M_file); }
246 _M_unget_buf = traits_type::to_int_type(__s[__ret - 1]);
248 _M_unget_buf = traits_type::eof();
255 {
return std::fwrite(__s, 1, __n, _M_file); }
257#ifdef _GLIBCXX_USE_WCHAR_T
259 inline stdio_sync_filebuf<wchar_t>::int_type
260 stdio_sync_filebuf<wchar_t>::syncgetc()
261 {
return std::getwc(_M_file); }
264 inline stdio_sync_filebuf<wchar_t>::int_type
265 stdio_sync_filebuf<wchar_t>::syncungetc(
int_type __c)
266 {
return std::ungetwc(__c, _M_file); }
269 inline stdio_sync_filebuf<wchar_t>::int_type
270 stdio_sync_filebuf<wchar_t>::syncputc(
int_type __c)
271 {
return std::putwc(__c, _M_file); }
278 const int_type __eof = traits_type::eof();
282 if (traits_type::eq_int_type(__c, __eof))
284 __s[__ret] = traits_type::to_char_type(__c);
289 _M_unget_buf = traits_type::to_int_type(__s[__ret - 1]);
291 _M_unget_buf = traits_type::eof();
297 stdio_sync_filebuf<wchar_t>::xsputn(
const wchar_t* __s,
301 const int_type __eof = traits_type::eof();
304 if (traits_type::eq_int_type(this->syncputc(*__s++), __eof))
312#if _GLIBCXX_EXTERN_TEMPLATE
313#pragma GCC diagnostic push
314#pragma GCC diagnostic ignored "-Wc++11-extensions"
316#ifdef _GLIBCXX_USE_WCHAR_T
319#pragma GCC diagnostic pop
322_GLIBCXX_END_NAMESPACE_VERSION
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
long long streamoff
Type used by fpos, char_traits<char>, and char_traits<wchar_t>.
fpos< mbstate_t > streampos
File position for char streams.
GNU extensions for public use.
The actual work of input and output (interface).
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.
static const openmode out
Open for output. Default for ofstream and fstream.
_Ios_Openmode openmode
This is a bitmask type.
_Ios_Seekdir seekdir
This is an enumerated type.
Provides a layer of compatibility for C.
virtual int_type pbackfail(int_type __c=traits_type::eof())
Tries to back up the input sequence.
virtual int_type underflow()
Fetches more data from the controlled sequence.
virtual int_type overflow(int_type __c=traits_type::eof())
Consumes data from the buffer; writes to the controlled sequence.
virtual int sync()
Synchronizes the buffer arrays with the controlled sequences.
virtual int_type uflow()
Fetches more data from the controlled sequence.