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> >
62 typedef _CharT char_type;
63 typedef _Traits traits_type;
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;
76 int_type _M_unget_buf;
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);
134 int_type __c = this->syncgetc();
135 return this->syncungetc(__c);
142 _M_unget_buf = this->syncgetc();
147 pbackfail(int_type __c = traits_type::eof())
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;
172 overflow(int_type __c = traits_type::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