#include <fstream>
namespace std
{
template<>
basic_filebuf<char>::int_type
basic_filebuf<char>::_M_underflow_common(bool __bump)
{
int_type __ret = traits_type::eof();
bool __testin = _M_mode & ios_base::in;
bool __testout = _M_mode & ios_base::out;
if (__testin)
{
if (_M_pback_init)
{
_M_pback_destroy();
if (_M_in_cur < _M_in_end)
{
__ret = traits_type::to_int_type(*_M_in_cur);
if (__bump)
_M_in_cur_move(1);
return __ret;
}
}
bool __testget = _M_in_cur && _M_in_beg < _M_in_cur;
bool __testinit = _M_is_indeterminate();
if (__testget)
{
if (__testout)
_M_really_overflow();
else if (_M_in_cur != _M_filepos)
_M_file.seekoff(_M_in_cur - _M_filepos,
ios_base::cur, ios_base::in);
}
if (__testinit || __testget)
{
streamsize __elen = 0;
streamsize __ilen = 0;
__elen = _M_file.xsgetn(reinterpret_cast<char*>(_M_in_beg),
_M_buf_size);
__ilen = __elen;
if (0 < __ilen)
{
_M_set_determinate(__ilen);
if (__testout)
_M_out_cur = _M_in_cur;
__ret = traits_type::to_int_type(*_M_in_cur);
if (__bump)
_M_in_cur_move(1);
else if (_M_buf_size == 1)
{
_M_file.sys_ungetc(traits_type::to_int_type(*_M_in_cur));
_M_set_indeterminate();
}
}
}
}
_M_last_overflowed = false;
return __ret;
}
#ifdef _GLIBCPP_USE_WCHAR_T
template<>
basic_filebuf<wchar_t>::int_type
basic_filebuf<wchar_t>::_M_underflow_common(bool __bump)
{
int_type __ret = traits_type::eof();
bool __testin = _M_mode & ios_base::in;
bool __testout = _M_mode & ios_base::out;
if (__testin)
{
if (_M_pback_init)
{
_M_pback_destroy();
if (_M_in_cur < _M_in_end)
{
__ret = traits_type::to_int_type(*_M_in_cur);
if (__bump)
_M_in_cur_move(1);
return __ret;
}
}
bool __testget = _M_in_cur && _M_in_beg < _M_in_cur;
bool __testinit = _M_is_indeterminate();
if (__testget)
{
if (__testout)
_M_really_overflow();
else if (_M_in_cur != _M_filepos)
_M_file.seekoff(_M_in_cur - _M_filepos,
ios_base::cur, ios_base::in);
}
if (__testinit || __testget)
{
const locale __loc = this->getloc();
const __codecvt_type& __cvt = use_facet<__codecvt_type>(__loc);
streamsize __elen = 0;
streamsize __ilen = 0;
if (__cvt.always_noconv())
{
__elen = _M_file.xsgetn(reinterpret_cast<char*>(_M_in_beg),
_M_buf_size);
__ilen = __elen;
}
else
{
char* __buf = static_cast<char*>(__builtin_alloca(_M_buf_size));
__elen = _M_file.xsgetn(__buf, _M_buf_size);
const char* __eend;
char_type* __iend;
__res_type __r = __cvt.in(_M_state_cur, __buf,
__buf + __elen, __eend, _M_in_beg,
_M_in_beg + _M_buf_size, __iend);
if (__r == codecvt_base::ok)
__ilen = __iend - _M_in_beg;
else
{
__ilen = 0;
_M_file.seekoff(-__elen, ios_base::cur, ios_base::in);
}
}
if (0 < __ilen)
{
_M_set_determinate(__ilen);
if (__testout)
_M_out_cur = _M_in_cur;
__ret = traits_type::to_int_type(*_M_in_cur);
if (__bump)
_M_in_cur_move(1);
else if (_M_buf_size == 1)
{
_M_file.sys_ungetc(traits_type::to_int_type(*_M_in_cur));
_M_set_indeterminate();
}
}
}
}
_M_last_overflowed = false;
return __ret;
}
#endif
}