29 #ifndef _STDIO_SYNC_FILEBUF_H 30 #define _STDIO_SYNC_FILEBUF_H 1 32 #pragma GCC system_header 41 #ifdef _GLIBCXX_USE_WCHAR_T 45 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
47 _GLIBCXX_BEGIN_NAMESPACE_VERSION
57 template<
typename _CharT,
typename _Traits = std::
char_traits<_CharT> >
64 typedef typename traits_type::int_type
int_type;
65 typedef typename traits_type::pos_type
pos_type;
66 typedef typename traits_type::off_type
off_type;
72 std::__c_file* _M_file;
81 : _M_file(__f), _M_unget_buf(traits_type::eof())
84 #if __cplusplus >= 201103L 87 _M_file(__fb._M_file), _M_unget_buf(__fb._M_unget_buf)
89 __fb._M_file =
nullptr;
90 __fb._M_unget_buf = traits_type::eof();
96 __streambuf_type::operator=(__fb);
97 _M_file = std::__exchange(__fb._M_file,
nullptr);
98 _M_unget_buf = std::__exchange(__fb._M_unget_buf, traits_type::eof());
105 __streambuf_type::swap(__fb);
106 std::swap(_M_file, __fb._M_file);
107 std::swap(_M_unget_buf, __fb._M_unget_buf);
119 file() {
return this->_M_file; }
126 syncungetc(int_type __c);
129 syncputc(int_type __c);
135 return this->syncungetc(__c);
142 _M_unget_buf = this->syncgetc();
150 const int_type __eof = traits_type::eof();
153 if (traits_type::eq_int_type(__c, __eof))
155 if (!traits_type::eq_int_type(_M_unget_buf, __eof))
156 __ret = this->syncungetc(_M_unget_buf);
161 __ret = this->syncungetc(__c);
164 _M_unget_buf = __eof;
175 if (traits_type::eq_int_type(__c, traits_type::eof()))
177 if (std::fflush(_M_file))
178 __ret = traits_type::eof();
180 __ret = traits_type::not_eof(__c);
183 __ret = this->syncputc(__c);
192 {
return std::fflush(_M_file); }
206 #ifdef _GLIBCXX_USE_LFS 207 if (!fseeko64(_M_file, __off, __whence))
210 if (!fseek(_M_file, __off, __whence))
218 std::ios_base::openmode __mode =
224 inline stdio_sync_filebuf<char>::int_type
225 stdio_sync_filebuf<char>::syncgetc()
226 {
return std::getc(_M_file); }
229 inline stdio_sync_filebuf<char>::int_type
230 stdio_sync_filebuf<char>::syncungetc(int_type __c)
231 {
return std::ungetc(__c, _M_file); }
234 inline stdio_sync_filebuf<char>::int_type
235 stdio_sync_filebuf<char>::syncputc(int_type __c)
236 {
return std::putc(__c, _M_file); }
244 _M_unget_buf = traits_type::to_int_type(__s[__ret - 1]);
246 _M_unget_buf = traits_type::eof();
253 {
return std::fwrite(__s, 1, __n, _M_file); }
255 #ifdef _GLIBCXX_USE_WCHAR_T 257 inline stdio_sync_filebuf<wchar_t>::int_type
258 stdio_sync_filebuf<wchar_t>::syncgetc()
259 {
return std::getwc(_M_file); }
262 inline stdio_sync_filebuf<wchar_t>::int_type
263 stdio_sync_filebuf<wchar_t>::syncungetc(int_type __c)
264 {
return std::ungetwc(__c, _M_file); }
267 inline stdio_sync_filebuf<wchar_t>::int_type
268 stdio_sync_filebuf<wchar_t>::syncputc(int_type __c)
269 {
return std::putwc(__c, _M_file); }
276 const int_type __eof = traits_type::eof();
279 int_type __c = this->syncgetc();
280 if (traits_type::eq_int_type(__c, __eof))
282 __s[__ret] = traits_type::to_char_type(__c);
287 _M_unget_buf = traits_type::to_int_type(__s[__ret - 1]);
289 _M_unget_buf = traits_type::eof();
295 stdio_sync_filebuf<wchar_t>::xsputn(
const wchar_t* __s,
299 const int_type __eof = traits_type::eof();
302 if (traits_type::eq_int_type(this->syncputc(*__s++), __eof))
310 #if _GLIBCXX_EXTERN_TEMPLATE 311 extern template class stdio_sync_filebuf<char>;
312 #ifdef _GLIBCXX_USE_WCHAR_T 313 extern template class stdio_sync_filebuf<wchar_t>;
317 _GLIBCXX_END_NAMESPACE_VERSION
long long streamoff
Type used by fpos, char_traits<char>, and char_traits<wchar_t>.
Class representing stream positions.
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
static const openmode in
Open for input. Default for ifstream and fstream.
traits_type::int_type int_type
virtual int_type overflow(int_type __c=traits_type::eof())
Consumes data from the buffer; writes to the controlled sequence.
static const openmode out
Open for output. Default for ofstream and fstream.
The actual work of input and output (interface).
GNU extensions for public use.
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 sync()
Synchronizes the buffer arrays with the controlled sequences.
virtual int_type uflow()
Fetches more data from the controlled sequence.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
traits_type::pos_type pos_type
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.
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.
traits_type::off_type off_type