29 #ifndef _STDIO_SYNC_FILEBUF_H
30 #define _STDIO_SYNC_FILEBUF_H 1
32 #pragma GCC system_header
39 #ifdef _GLIBCXX_USE_WCHAR_T
43 namespace __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;
79 : _M_file(__f), _M_unget_buf(traits_type::eof())
82 #if __cplusplus >= 201103L
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();
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());
103 __streambuf_type::swap(__fb);
105 std::swap(_M_unget_buf, __fb._M_unget_buf);
117 file() {
return this->_M_file; }
124 syncungetc(int_type __c);
127 syncputc(int_type __c);
132 int_type __c = this->syncgetc();
133 return this->syncungetc(__c);
140 _M_unget_buf = this->syncgetc();
145 pbackfail(int_type __c = traits_type::eof())
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;
170 overflow(int_type __c = traits_type::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))
216 std::ios_base::openmode __mode =
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();
277 int_type __c = this->syncgetc();
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
309 extern template class stdio_sync_filebuf<char>;
310 #ifdef _GLIBCXX_USE_WCHAR_T
311 extern template class stdio_sync_filebuf<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).
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.
Class representing stream positions.
Provides a layer of compatibility for C.
virtual std::streampos seekpos(std::streampos __pos, std::ios_base::openmode __mode=std::ios_base::in|std::ios_base::out)
Alters the stream positions.
virtual int_type underflow()
Fetches more data from 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.