29 #ifndef _STDIO_SYNC_FILEBUF_H
30 #define _STDIO_SYNC_FILEBUF_H 1
32 #ifdef _GLIBCXX_SYSHDR
33 #pragma GCC system_header
43 #ifdef _GLIBCXX_USE_WCHAR_T
47 namespace __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;
83 : _M_file(__f), _M_unget_buf(traits_type::eof())
86 #if __cplusplus >= 201103L
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();
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());
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; }
128 syncungetc(int_type __c);
131 syncputc(int_type __c);
136 int_type __c = this->syncgetc();
137 return this->syncungetc(__c);
144 _M_unget_buf = this->syncgetc();
149 pbackfail(int_type __c = traits_type::eof())
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;
174 overflow(int_type __c = traits_type::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))
220 std::ios_base::openmode __mode =
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();
281 int_type __c = this->syncgetc();
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"
315 extern template class stdio_sync_filebuf<char>;
316 #ifdef _GLIBCXX_USE_WCHAR_T
317 extern template class stdio_sync_filebuf<wchar_t>;
319 #pragma GCC diagnostic pop
322 _GLIBCXX_END_NAMESPACE_VERSION