29#ifndef _STDIO_SYNC_FILEBUF_H
30#define _STDIO_SYNC_FILEBUF_H 1
32#pragma GCC system_header
39#ifdef _GLIBCXX_USE_WCHAR_T
43namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
45_GLIBCXX_BEGIN_NAMESPACE_VERSION
55 template<
typename _CharT,
typename _Traits = std::
char_traits<_CharT> >
60 typedef _CharT char_type;
61 typedef _Traits traits_type;
62 typedef typename traits_type::int_type int_type;
63 typedef typename traits_type::pos_type pos_type;
64 typedef typename traits_type::off_type off_type;
70 std::__c_file* _M_file;
74 int_type _M_unget_buf;
78 stdio_sync_filebuf(std::__c_file* __f)
79 : _M_file(__f), _M_unget_buf(traits_type::eof())
82#if __cplusplus >= 201103L
83 stdio_sync_filebuf(stdio_sync_filebuf&& __fb) noexcept
85 _M_file(__fb._M_file), _M_unget_buf(__fb._M_unget_buf)
87 __fb._M_file =
nullptr;
88 __fb._M_unget_buf = traits_type::eof();
92 operator=(stdio_sync_filebuf&& __fb)
noexcept
94 __streambuf_type::operator=(__fb);
95 _M_file = std::__exchange(__fb._M_file,
nullptr);
96 _M_unget_buf = std::__exchange(__fb._M_unget_buf, traits_type::eof());
101 swap(stdio_sync_filebuf& __fb)
103 __streambuf_type::swap(__fb);
105 std::swap(_M_unget_buf, __fb._M_unget_buf);
117 file() {
return this->_M_file; }
132 int_type __c = this->syncgetc();
133 return this->syncungetc(__c);
140 _M_unget_buf = this->syncgetc();
148 const int_type __eof = traits_type::eof();
151 if (traits_type::eq_int_type(__c, __eof))
153 if (!traits_type::eq_int_type(_M_unget_buf, __eof))
154 __ret = this->syncungetc(_M_unget_buf);
159 __ret = this->syncungetc(__c);
162 _M_unget_buf = __eof;
173 if (traits_type::eq_int_type(__c, traits_type::eof()))
175 if (std::fflush(_M_file))
176 __ret = traits_type::eof();
178 __ret = traits_type::not_eof(__c);
181 __ret = this->syncputc(__c);
190 {
return std::fflush(_M_file); }
204#ifdef _GLIBCXX_USE_LFS
205 if (!fseeko64(_M_file, __off, __whence))
208 if (!fseek(_M_file, __off, __whence))
222 inline stdio_sync_filebuf<char>::int_type
223 stdio_sync_filebuf<char>::syncgetc()
224 {
return std::getc(_M_file); }
227 inline stdio_sync_filebuf<char>::int_type
228 stdio_sync_filebuf<char>::syncungetc(
int_type __c)
229 {
return std::ungetc(__c, _M_file); }
232 inline stdio_sync_filebuf<char>::int_type
233 stdio_sync_filebuf<char>::syncputc(
int_type __c)
234 {
return std::putc(__c, _M_file); }
242 _M_unget_buf = traits_type::to_int_type(__s[__ret - 1]);
244 _M_unget_buf = traits_type::eof();
251 {
return std::fwrite(__s, 1, __n, _M_file); }
253#ifdef _GLIBCXX_USE_WCHAR_T
255 inline stdio_sync_filebuf<wchar_t>::int_type
256 stdio_sync_filebuf<wchar_t>::syncgetc()
257 {
return std::getwc(_M_file); }
260 inline stdio_sync_filebuf<wchar_t>::int_type
261 stdio_sync_filebuf<wchar_t>::syncungetc(
int_type __c)
262 {
return std::ungetwc(__c, _M_file); }
265 inline stdio_sync_filebuf<wchar_t>::int_type
266 stdio_sync_filebuf<wchar_t>::syncputc(
int_type __c)
267 {
return std::putwc(__c, _M_file); }
274 const int_type __eof = traits_type::eof();
278 if (traits_type::eq_int_type(__c, __eof))
280 __s[__ret] = traits_type::to_char_type(__c);
285 _M_unget_buf = traits_type::to_int_type(__s[__ret - 1]);
287 _M_unget_buf = traits_type::eof();
293 stdio_sync_filebuf<wchar_t>::xsputn(
const wchar_t* __s,
297 const int_type __eof = traits_type::eof();
300 if (traits_type::eq_int_type(this->syncputc(*__s++), __eof))
308#if _GLIBCXX_EXTERN_TEMPLATE
310#ifdef _GLIBCXX_USE_WCHAR_T
315_GLIBCXX_END_NAMESPACE_VERSION
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
void swap(any &__x, any &__y) noexcept
Exchange the states of two any objects.
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).
basic_streambuf< char_type, traits_type > __streambuf_type
This is a non-standard type.
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.