1*38fd1498Szrj // istream classes -*- C++ -*- 2*38fd1498Szrj 3*38fd1498Szrj // Copyright (C) 1997-2018 Free Software Foundation, Inc. 4*38fd1498Szrj // 5*38fd1498Szrj // This file is part of the GNU ISO C++ Library. This library is free 6*38fd1498Szrj // software; you can redistribute it and/or modify it under the 7*38fd1498Szrj // terms of the GNU General Public License as published by the 8*38fd1498Szrj // Free Software Foundation; either version 3, or (at your option) 9*38fd1498Szrj // any later version. 10*38fd1498Szrj 11*38fd1498Szrj // This library is distributed in the hope that it will be useful, 12*38fd1498Szrj // but WITHOUT ANY WARRANTY; without even the implied warranty of 13*38fd1498Szrj // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14*38fd1498Szrj // GNU General Public License for more details. 15*38fd1498Szrj 16*38fd1498Szrj // Under Section 7 of GPL version 3, you are granted additional 17*38fd1498Szrj // permissions described in the GCC Runtime Library Exception, version 18*38fd1498Szrj // 3.1, as published by the Free Software Foundation. 19*38fd1498Szrj 20*38fd1498Szrj // You should have received a copy of the GNU General Public License and 21*38fd1498Szrj // a copy of the GCC Runtime Library Exception along with this program; 22*38fd1498Szrj // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 23*38fd1498Szrj // <http://www.gnu.org/licenses/>. 24*38fd1498Szrj 25*38fd1498Szrj /** @file bits/istream.tcc 26*38fd1498Szrj * This is an internal header file, included by other library headers. 27*38fd1498Szrj * Do not attempt to use it directly. @headername{istream} 28*38fd1498Szrj */ 29*38fd1498Szrj 30*38fd1498Szrj // 31*38fd1498Szrj // ISO C++ 14882: 27.6.1 Input streams 32*38fd1498Szrj // 33*38fd1498Szrj 34*38fd1498Szrj #ifndef _ISTREAM_TCC 35*38fd1498Szrj #define _ISTREAM_TCC 1 36*38fd1498Szrj 37*38fd1498Szrj #pragma GCC system_header 38*38fd1498Szrj 39*38fd1498Szrj #include <bits/cxxabi_forced.h> 40*38fd1498Szrj 41*38fd1498Szrj namespace std _GLIBCXX_VISIBILITY(default) 42*38fd1498Szrj { 43*38fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_VERSION 44*38fd1498Szrj 45*38fd1498Szrj template<typename _CharT, typename _Traits> 46*38fd1498Szrj basic_istream<_CharT, _Traits>::sentry:: sentry(basic_istream<_CharT,_Traits> & __in,bool __noskip)47*38fd1498Szrj sentry(basic_istream<_CharT, _Traits>& __in, bool __noskip) : _M_ok(false) 48*38fd1498Szrj { 49*38fd1498Szrj ios_base::iostate __err = ios_base::goodbit; 50*38fd1498Szrj if (__in.good()) 51*38fd1498Szrj __try 52*38fd1498Szrj { 53*38fd1498Szrj if (__in.tie()) 54*38fd1498Szrj __in.tie()->flush(); 55*38fd1498Szrj if (!__noskip && bool(__in.flags() & ios_base::skipws)) 56*38fd1498Szrj { 57*38fd1498Szrj const __int_type __eof = traits_type::eof(); 58*38fd1498Szrj __streambuf_type* __sb = __in.rdbuf(); 59*38fd1498Szrj __int_type __c = __sb->sgetc(); 60*38fd1498Szrj 61*38fd1498Szrj const __ctype_type& __ct = __check_facet(__in._M_ctype); 62*38fd1498Szrj while (!traits_type::eq_int_type(__c, __eof) 63*38fd1498Szrj && __ct.is(ctype_base::space, 64*38fd1498Szrj traits_type::to_char_type(__c))) 65*38fd1498Szrj __c = __sb->snextc(); 66*38fd1498Szrj 67*38fd1498Szrj // _GLIBCXX_RESOLVE_LIB_DEFECTS 68*38fd1498Szrj // 195. Should basic_istream::sentry's constructor ever 69*38fd1498Szrj // set eofbit? 70*38fd1498Szrj if (traits_type::eq_int_type(__c, __eof)) 71*38fd1498Szrj __err |= ios_base::eofbit; 72*38fd1498Szrj } 73*38fd1498Szrj } 74*38fd1498Szrj __catch(__cxxabiv1::__forced_unwind&) 75*38fd1498Szrj { 76*38fd1498Szrj __in._M_setstate(ios_base::badbit); 77*38fd1498Szrj __throw_exception_again; 78*38fd1498Szrj } 79*38fd1498Szrj __catch(...) 80*38fd1498Szrj { __in._M_setstate(ios_base::badbit); } 81*38fd1498Szrj 82*38fd1498Szrj if (__in.good() && __err == ios_base::goodbit) 83*38fd1498Szrj _M_ok = true; 84*38fd1498Szrj else 85*38fd1498Szrj { 86*38fd1498Szrj __err |= ios_base::failbit; 87*38fd1498Szrj __in.setstate(__err); 88*38fd1498Szrj } 89*38fd1498Szrj } 90*38fd1498Szrj 91*38fd1498Szrj template<typename _CharT, typename _Traits> 92*38fd1498Szrj template<typename _ValueT> 93*38fd1498Szrj basic_istream<_CharT, _Traits>& 94*38fd1498Szrj basic_istream<_CharT, _Traits>:: _M_extract(_ValueT & __v)95*38fd1498Szrj _M_extract(_ValueT& __v) 96*38fd1498Szrj { 97*38fd1498Szrj sentry __cerb(*this, false); 98*38fd1498Szrj if (__cerb) 99*38fd1498Szrj { 100*38fd1498Szrj ios_base::iostate __err = ios_base::goodbit; 101*38fd1498Szrj __try 102*38fd1498Szrj { 103*38fd1498Szrj const __num_get_type& __ng = __check_facet(this->_M_num_get); 104*38fd1498Szrj __ng.get(*this, 0, *this, __err, __v); 105*38fd1498Szrj } 106*38fd1498Szrj __catch(__cxxabiv1::__forced_unwind&) 107*38fd1498Szrj { 108*38fd1498Szrj this->_M_setstate(ios_base::badbit); 109*38fd1498Szrj __throw_exception_again; 110*38fd1498Szrj } 111*38fd1498Szrj __catch(...) 112*38fd1498Szrj { this->_M_setstate(ios_base::badbit); } 113*38fd1498Szrj if (__err) 114*38fd1498Szrj this->setstate(__err); 115*38fd1498Szrj } 116*38fd1498Szrj return *this; 117*38fd1498Szrj } 118*38fd1498Szrj 119*38fd1498Szrj template<typename _CharT, typename _Traits> 120*38fd1498Szrj basic_istream<_CharT, _Traits>& 121*38fd1498Szrj basic_istream<_CharT, _Traits>:: operator >>(short & __n)122*38fd1498Szrj operator>>(short& __n) 123*38fd1498Szrj { 124*38fd1498Szrj // _GLIBCXX_RESOLVE_LIB_DEFECTS 125*38fd1498Szrj // 118. basic_istream uses nonexistent num_get member functions. 126*38fd1498Szrj sentry __cerb(*this, false); 127*38fd1498Szrj if (__cerb) 128*38fd1498Szrj { 129*38fd1498Szrj ios_base::iostate __err = ios_base::goodbit; 130*38fd1498Szrj __try 131*38fd1498Szrj { 132*38fd1498Szrj long __l; 133*38fd1498Szrj const __num_get_type& __ng = __check_facet(this->_M_num_get); 134*38fd1498Szrj __ng.get(*this, 0, *this, __err, __l); 135*38fd1498Szrj 136*38fd1498Szrj // _GLIBCXX_RESOLVE_LIB_DEFECTS 137*38fd1498Szrj // 696. istream::operator>>(int&) broken. 138*38fd1498Szrj if (__l < __gnu_cxx::__numeric_traits<short>::__min) 139*38fd1498Szrj { 140*38fd1498Szrj __err |= ios_base::failbit; 141*38fd1498Szrj __n = __gnu_cxx::__numeric_traits<short>::__min; 142*38fd1498Szrj } 143*38fd1498Szrj else if (__l > __gnu_cxx::__numeric_traits<short>::__max) 144*38fd1498Szrj { 145*38fd1498Szrj __err |= ios_base::failbit; 146*38fd1498Szrj __n = __gnu_cxx::__numeric_traits<short>::__max; 147*38fd1498Szrj } 148*38fd1498Szrj else 149*38fd1498Szrj __n = short(__l); 150*38fd1498Szrj } 151*38fd1498Szrj __catch(__cxxabiv1::__forced_unwind&) 152*38fd1498Szrj { 153*38fd1498Szrj this->_M_setstate(ios_base::badbit); 154*38fd1498Szrj __throw_exception_again; 155*38fd1498Szrj } 156*38fd1498Szrj __catch(...) 157*38fd1498Szrj { this->_M_setstate(ios_base::badbit); } 158*38fd1498Szrj if (__err) 159*38fd1498Szrj this->setstate(__err); 160*38fd1498Szrj } 161*38fd1498Szrj return *this; 162*38fd1498Szrj } 163*38fd1498Szrj 164*38fd1498Szrj template<typename _CharT, typename _Traits> 165*38fd1498Szrj basic_istream<_CharT, _Traits>& 166*38fd1498Szrj basic_istream<_CharT, _Traits>:: operator >>(int & __n)167*38fd1498Szrj operator>>(int& __n) 168*38fd1498Szrj { 169*38fd1498Szrj // _GLIBCXX_RESOLVE_LIB_DEFECTS 170*38fd1498Szrj // 118. basic_istream uses nonexistent num_get member functions. 171*38fd1498Szrj sentry __cerb(*this, false); 172*38fd1498Szrj if (__cerb) 173*38fd1498Szrj { 174*38fd1498Szrj ios_base::iostate __err = ios_base::goodbit; 175*38fd1498Szrj __try 176*38fd1498Szrj { 177*38fd1498Szrj long __l; 178*38fd1498Szrj const __num_get_type& __ng = __check_facet(this->_M_num_get); 179*38fd1498Szrj __ng.get(*this, 0, *this, __err, __l); 180*38fd1498Szrj 181*38fd1498Szrj // _GLIBCXX_RESOLVE_LIB_DEFECTS 182*38fd1498Szrj // 696. istream::operator>>(int&) broken. 183*38fd1498Szrj if (__l < __gnu_cxx::__numeric_traits<int>::__min) 184*38fd1498Szrj { 185*38fd1498Szrj __err |= ios_base::failbit; 186*38fd1498Szrj __n = __gnu_cxx::__numeric_traits<int>::__min; 187*38fd1498Szrj } 188*38fd1498Szrj else if (__l > __gnu_cxx::__numeric_traits<int>::__max) 189*38fd1498Szrj { 190*38fd1498Szrj __err |= ios_base::failbit; 191*38fd1498Szrj __n = __gnu_cxx::__numeric_traits<int>::__max; 192*38fd1498Szrj } 193*38fd1498Szrj else 194*38fd1498Szrj __n = int(__l); 195*38fd1498Szrj } 196*38fd1498Szrj __catch(__cxxabiv1::__forced_unwind&) 197*38fd1498Szrj { 198*38fd1498Szrj this->_M_setstate(ios_base::badbit); 199*38fd1498Szrj __throw_exception_again; 200*38fd1498Szrj } 201*38fd1498Szrj __catch(...) 202*38fd1498Szrj { this->_M_setstate(ios_base::badbit); } 203*38fd1498Szrj if (__err) 204*38fd1498Szrj this->setstate(__err); 205*38fd1498Szrj } 206*38fd1498Szrj return *this; 207*38fd1498Szrj } 208*38fd1498Szrj 209*38fd1498Szrj template<typename _CharT, typename _Traits> 210*38fd1498Szrj basic_istream<_CharT, _Traits>& 211*38fd1498Szrj basic_istream<_CharT, _Traits>:: operator >>(__streambuf_type * __sbout)212*38fd1498Szrj operator>>(__streambuf_type* __sbout) 213*38fd1498Szrj { 214*38fd1498Szrj ios_base::iostate __err = ios_base::goodbit; 215*38fd1498Szrj sentry __cerb(*this, false); 216*38fd1498Szrj if (__cerb && __sbout) 217*38fd1498Szrj { 218*38fd1498Szrj __try 219*38fd1498Szrj { 220*38fd1498Szrj bool __ineof; 221*38fd1498Szrj if (!__copy_streambufs_eof(this->rdbuf(), __sbout, __ineof)) 222*38fd1498Szrj __err |= ios_base::failbit; 223*38fd1498Szrj if (__ineof) 224*38fd1498Szrj __err |= ios_base::eofbit; 225*38fd1498Szrj } 226*38fd1498Szrj __catch(__cxxabiv1::__forced_unwind&) 227*38fd1498Szrj { 228*38fd1498Szrj this->_M_setstate(ios_base::failbit); 229*38fd1498Szrj __throw_exception_again; 230*38fd1498Szrj } 231*38fd1498Szrj __catch(...) 232*38fd1498Szrj { this->_M_setstate(ios_base::failbit); } 233*38fd1498Szrj } 234*38fd1498Szrj else if (!__sbout) 235*38fd1498Szrj __err |= ios_base::failbit; 236*38fd1498Szrj if (__err) 237*38fd1498Szrj this->setstate(__err); 238*38fd1498Szrj return *this; 239*38fd1498Szrj } 240*38fd1498Szrj 241*38fd1498Szrj template<typename _CharT, typename _Traits> 242*38fd1498Szrj typename basic_istream<_CharT, _Traits>::int_type 243*38fd1498Szrj basic_istream<_CharT, _Traits>:: get(void)244*38fd1498Szrj get(void) 245*38fd1498Szrj { 246*38fd1498Szrj const int_type __eof = traits_type::eof(); 247*38fd1498Szrj int_type __c = __eof; 248*38fd1498Szrj _M_gcount = 0; 249*38fd1498Szrj ios_base::iostate __err = ios_base::goodbit; 250*38fd1498Szrj sentry __cerb(*this, true); 251*38fd1498Szrj if (__cerb) 252*38fd1498Szrj { 253*38fd1498Szrj __try 254*38fd1498Szrj { 255*38fd1498Szrj __c = this->rdbuf()->sbumpc(); 256*38fd1498Szrj // 27.6.1.1 paragraph 3 257*38fd1498Szrj if (!traits_type::eq_int_type(__c, __eof)) 258*38fd1498Szrj _M_gcount = 1; 259*38fd1498Szrj else 260*38fd1498Szrj __err |= ios_base::eofbit; 261*38fd1498Szrj } 262*38fd1498Szrj __catch(__cxxabiv1::__forced_unwind&) 263*38fd1498Szrj { 264*38fd1498Szrj this->_M_setstate(ios_base::badbit); 265*38fd1498Szrj __throw_exception_again; 266*38fd1498Szrj } 267*38fd1498Szrj __catch(...) 268*38fd1498Szrj { this->_M_setstate(ios_base::badbit); } 269*38fd1498Szrj } 270*38fd1498Szrj if (!_M_gcount) 271*38fd1498Szrj __err |= ios_base::failbit; 272*38fd1498Szrj if (__err) 273*38fd1498Szrj this->setstate(__err); 274*38fd1498Szrj return __c; 275*38fd1498Szrj } 276*38fd1498Szrj 277*38fd1498Szrj template<typename _CharT, typename _Traits> 278*38fd1498Szrj basic_istream<_CharT, _Traits>& 279*38fd1498Szrj basic_istream<_CharT, _Traits>:: get(char_type & __c)280*38fd1498Szrj get(char_type& __c) 281*38fd1498Szrj { 282*38fd1498Szrj _M_gcount = 0; 283*38fd1498Szrj ios_base::iostate __err = ios_base::goodbit; 284*38fd1498Szrj sentry __cerb(*this, true); 285*38fd1498Szrj if (__cerb) 286*38fd1498Szrj { 287*38fd1498Szrj __try 288*38fd1498Szrj { 289*38fd1498Szrj const int_type __cb = this->rdbuf()->sbumpc(); 290*38fd1498Szrj // 27.6.1.1 paragraph 3 291*38fd1498Szrj if (!traits_type::eq_int_type(__cb, traits_type::eof())) 292*38fd1498Szrj { 293*38fd1498Szrj _M_gcount = 1; 294*38fd1498Szrj __c = traits_type::to_char_type(__cb); 295*38fd1498Szrj } 296*38fd1498Szrj else 297*38fd1498Szrj __err |= ios_base::eofbit; 298*38fd1498Szrj } 299*38fd1498Szrj __catch(__cxxabiv1::__forced_unwind&) 300*38fd1498Szrj { 301*38fd1498Szrj this->_M_setstate(ios_base::badbit); 302*38fd1498Szrj __throw_exception_again; 303*38fd1498Szrj } 304*38fd1498Szrj __catch(...) 305*38fd1498Szrj { this->_M_setstate(ios_base::badbit); } 306*38fd1498Szrj } 307*38fd1498Szrj if (!_M_gcount) 308*38fd1498Szrj __err |= ios_base::failbit; 309*38fd1498Szrj if (__err) 310*38fd1498Szrj this->setstate(__err); 311*38fd1498Szrj return *this; 312*38fd1498Szrj } 313*38fd1498Szrj 314*38fd1498Szrj template<typename _CharT, typename _Traits> 315*38fd1498Szrj basic_istream<_CharT, _Traits>& 316*38fd1498Szrj basic_istream<_CharT, _Traits>:: get(char_type * __s,streamsize __n,char_type __delim)317*38fd1498Szrj get(char_type* __s, streamsize __n, char_type __delim) 318*38fd1498Szrj { 319*38fd1498Szrj _M_gcount = 0; 320*38fd1498Szrj ios_base::iostate __err = ios_base::goodbit; 321*38fd1498Szrj sentry __cerb(*this, true); 322*38fd1498Szrj if (__cerb) 323*38fd1498Szrj { 324*38fd1498Szrj __try 325*38fd1498Szrj { 326*38fd1498Szrj const int_type __idelim = traits_type::to_int_type(__delim); 327*38fd1498Szrj const int_type __eof = traits_type::eof(); 328*38fd1498Szrj __streambuf_type* __sb = this->rdbuf(); 329*38fd1498Szrj int_type __c = __sb->sgetc(); 330*38fd1498Szrj 331*38fd1498Szrj while (_M_gcount + 1 < __n 332*38fd1498Szrj && !traits_type::eq_int_type(__c, __eof) 333*38fd1498Szrj && !traits_type::eq_int_type(__c, __idelim)) 334*38fd1498Szrj { 335*38fd1498Szrj *__s++ = traits_type::to_char_type(__c); 336*38fd1498Szrj ++_M_gcount; 337*38fd1498Szrj __c = __sb->snextc(); 338*38fd1498Szrj } 339*38fd1498Szrj if (traits_type::eq_int_type(__c, __eof)) 340*38fd1498Szrj __err |= ios_base::eofbit; 341*38fd1498Szrj } 342*38fd1498Szrj __catch(__cxxabiv1::__forced_unwind&) 343*38fd1498Szrj { 344*38fd1498Szrj this->_M_setstate(ios_base::badbit); 345*38fd1498Szrj __throw_exception_again; 346*38fd1498Szrj } 347*38fd1498Szrj __catch(...) 348*38fd1498Szrj { this->_M_setstate(ios_base::badbit); } 349*38fd1498Szrj } 350*38fd1498Szrj // _GLIBCXX_RESOLVE_LIB_DEFECTS 351*38fd1498Szrj // 243. get and getline when sentry reports failure. 352*38fd1498Szrj if (__n > 0) 353*38fd1498Szrj *__s = char_type(); 354*38fd1498Szrj if (!_M_gcount) 355*38fd1498Szrj __err |= ios_base::failbit; 356*38fd1498Szrj if (__err) 357*38fd1498Szrj this->setstate(__err); 358*38fd1498Szrj return *this; 359*38fd1498Szrj } 360*38fd1498Szrj 361*38fd1498Szrj template<typename _CharT, typename _Traits> 362*38fd1498Szrj basic_istream<_CharT, _Traits>& 363*38fd1498Szrj basic_istream<_CharT, _Traits>:: get(__streambuf_type & __sb,char_type __delim)364*38fd1498Szrj get(__streambuf_type& __sb, char_type __delim) 365*38fd1498Szrj { 366*38fd1498Szrj _M_gcount = 0; 367*38fd1498Szrj ios_base::iostate __err = ios_base::goodbit; 368*38fd1498Szrj sentry __cerb(*this, true); 369*38fd1498Szrj if (__cerb) 370*38fd1498Szrj { 371*38fd1498Szrj __try 372*38fd1498Szrj { 373*38fd1498Szrj const int_type __idelim = traits_type::to_int_type(__delim); 374*38fd1498Szrj const int_type __eof = traits_type::eof(); 375*38fd1498Szrj __streambuf_type* __this_sb = this->rdbuf(); 376*38fd1498Szrj int_type __c = __this_sb->sgetc(); 377*38fd1498Szrj char_type __c2 = traits_type::to_char_type(__c); 378*38fd1498Szrj 379*38fd1498Szrj while (!traits_type::eq_int_type(__c, __eof) 380*38fd1498Szrj && !traits_type::eq_int_type(__c, __idelim) 381*38fd1498Szrj && !traits_type::eq_int_type(__sb.sputc(__c2), __eof)) 382*38fd1498Szrj { 383*38fd1498Szrj ++_M_gcount; 384*38fd1498Szrj __c = __this_sb->snextc(); 385*38fd1498Szrj __c2 = traits_type::to_char_type(__c); 386*38fd1498Szrj } 387*38fd1498Szrj if (traits_type::eq_int_type(__c, __eof)) 388*38fd1498Szrj __err |= ios_base::eofbit; 389*38fd1498Szrj } 390*38fd1498Szrj __catch(__cxxabiv1::__forced_unwind&) 391*38fd1498Szrj { 392*38fd1498Szrj this->_M_setstate(ios_base::badbit); 393*38fd1498Szrj __throw_exception_again; 394*38fd1498Szrj } 395*38fd1498Szrj __catch(...) 396*38fd1498Szrj { this->_M_setstate(ios_base::badbit); } 397*38fd1498Szrj } 398*38fd1498Szrj if (!_M_gcount) 399*38fd1498Szrj __err |= ios_base::failbit; 400*38fd1498Szrj if (__err) 401*38fd1498Szrj this->setstate(__err); 402*38fd1498Szrj return *this; 403*38fd1498Szrj } 404*38fd1498Szrj 405*38fd1498Szrj template<typename _CharT, typename _Traits> 406*38fd1498Szrj basic_istream<_CharT, _Traits>& 407*38fd1498Szrj basic_istream<_CharT, _Traits>:: getline(char_type * __s,streamsize __n,char_type __delim)408*38fd1498Szrj getline(char_type* __s, streamsize __n, char_type __delim) 409*38fd1498Szrj { 410*38fd1498Szrj _M_gcount = 0; 411*38fd1498Szrj ios_base::iostate __err = ios_base::goodbit; 412*38fd1498Szrj sentry __cerb(*this, true); 413*38fd1498Szrj if (__cerb) 414*38fd1498Szrj { 415*38fd1498Szrj __try 416*38fd1498Szrj { 417*38fd1498Szrj const int_type __idelim = traits_type::to_int_type(__delim); 418*38fd1498Szrj const int_type __eof = traits_type::eof(); 419*38fd1498Szrj __streambuf_type* __sb = this->rdbuf(); 420*38fd1498Szrj int_type __c = __sb->sgetc(); 421*38fd1498Szrj 422*38fd1498Szrj while (_M_gcount + 1 < __n 423*38fd1498Szrj && !traits_type::eq_int_type(__c, __eof) 424*38fd1498Szrj && !traits_type::eq_int_type(__c, __idelim)) 425*38fd1498Szrj { 426*38fd1498Szrj *__s++ = traits_type::to_char_type(__c); 427*38fd1498Szrj __c = __sb->snextc(); 428*38fd1498Szrj ++_M_gcount; 429*38fd1498Szrj } 430*38fd1498Szrj if (traits_type::eq_int_type(__c, __eof)) 431*38fd1498Szrj __err |= ios_base::eofbit; 432*38fd1498Szrj else 433*38fd1498Szrj { 434*38fd1498Szrj if (traits_type::eq_int_type(__c, __idelim)) 435*38fd1498Szrj { 436*38fd1498Szrj __sb->sbumpc(); 437*38fd1498Szrj ++_M_gcount; 438*38fd1498Szrj } 439*38fd1498Szrj else 440*38fd1498Szrj __err |= ios_base::failbit; 441*38fd1498Szrj } 442*38fd1498Szrj } 443*38fd1498Szrj __catch(__cxxabiv1::__forced_unwind&) 444*38fd1498Szrj { 445*38fd1498Szrj this->_M_setstate(ios_base::badbit); 446*38fd1498Szrj __throw_exception_again; 447*38fd1498Szrj } 448*38fd1498Szrj __catch(...) 449*38fd1498Szrj { this->_M_setstate(ios_base::badbit); } 450*38fd1498Szrj } 451*38fd1498Szrj // _GLIBCXX_RESOLVE_LIB_DEFECTS 452*38fd1498Szrj // 243. get and getline when sentry reports failure. 453*38fd1498Szrj if (__n > 0) 454*38fd1498Szrj *__s = char_type(); 455*38fd1498Szrj if (!_M_gcount) 456*38fd1498Szrj __err |= ios_base::failbit; 457*38fd1498Szrj if (__err) 458*38fd1498Szrj this->setstate(__err); 459*38fd1498Szrj return *this; 460*38fd1498Szrj } 461*38fd1498Szrj 462*38fd1498Szrj // We provide three overloads, since the first two are much simpler 463*38fd1498Szrj // than the general case. Also, the latter two can thus adopt the 464*38fd1498Szrj // same "batchy" strategy used by getline above. 465*38fd1498Szrj template<typename _CharT, typename _Traits> 466*38fd1498Szrj basic_istream<_CharT, _Traits>& 467*38fd1498Szrj basic_istream<_CharT, _Traits>:: ignore(void)468*38fd1498Szrj ignore(void) 469*38fd1498Szrj { 470*38fd1498Szrj _M_gcount = 0; 471*38fd1498Szrj sentry __cerb(*this, true); 472*38fd1498Szrj if (__cerb) 473*38fd1498Szrj { 474*38fd1498Szrj ios_base::iostate __err = ios_base::goodbit; 475*38fd1498Szrj __try 476*38fd1498Szrj { 477*38fd1498Szrj const int_type __eof = traits_type::eof(); 478*38fd1498Szrj __streambuf_type* __sb = this->rdbuf(); 479*38fd1498Szrj 480*38fd1498Szrj if (traits_type::eq_int_type(__sb->sbumpc(), __eof)) 481*38fd1498Szrj __err |= ios_base::eofbit; 482*38fd1498Szrj else 483*38fd1498Szrj _M_gcount = 1; 484*38fd1498Szrj } 485*38fd1498Szrj __catch(__cxxabiv1::__forced_unwind&) 486*38fd1498Szrj { 487*38fd1498Szrj this->_M_setstate(ios_base::badbit); 488*38fd1498Szrj __throw_exception_again; 489*38fd1498Szrj } 490*38fd1498Szrj __catch(...) 491*38fd1498Szrj { this->_M_setstate(ios_base::badbit); } 492*38fd1498Szrj if (__err) 493*38fd1498Szrj this->setstate(__err); 494*38fd1498Szrj } 495*38fd1498Szrj return *this; 496*38fd1498Szrj } 497*38fd1498Szrj 498*38fd1498Szrj template<typename _CharT, typename _Traits> 499*38fd1498Szrj basic_istream<_CharT, _Traits>& 500*38fd1498Szrj basic_istream<_CharT, _Traits>:: ignore(streamsize __n)501*38fd1498Szrj ignore(streamsize __n) 502*38fd1498Szrj { 503*38fd1498Szrj _M_gcount = 0; 504*38fd1498Szrj sentry __cerb(*this, true); 505*38fd1498Szrj if (__cerb && __n > 0) 506*38fd1498Szrj { 507*38fd1498Szrj ios_base::iostate __err = ios_base::goodbit; 508*38fd1498Szrj __try 509*38fd1498Szrj { 510*38fd1498Szrj const int_type __eof = traits_type::eof(); 511*38fd1498Szrj __streambuf_type* __sb = this->rdbuf(); 512*38fd1498Szrj int_type __c = __sb->sgetc(); 513*38fd1498Szrj 514*38fd1498Szrj // N.B. On LFS-enabled platforms streamsize is still 32 bits 515*38fd1498Szrj // wide: if we want to implement the standard mandated behavior 516*38fd1498Szrj // for n == max() (see 27.6.1.3/24) we are at risk of signed 517*38fd1498Szrj // integer overflow: thus these contortions. Also note that, 518*38fd1498Szrj // by definition, when more than 2G chars are actually ignored, 519*38fd1498Szrj // _M_gcount (the return value of gcount, that is) cannot be 520*38fd1498Szrj // really correct, being unavoidably too small. 521*38fd1498Szrj bool __large_ignore = false; 522*38fd1498Szrj while (true) 523*38fd1498Szrj { 524*38fd1498Szrj while (_M_gcount < __n 525*38fd1498Szrj && !traits_type::eq_int_type(__c, __eof)) 526*38fd1498Szrj { 527*38fd1498Szrj ++_M_gcount; 528*38fd1498Szrj __c = __sb->snextc(); 529*38fd1498Szrj } 530*38fd1498Szrj if (__n == __gnu_cxx::__numeric_traits<streamsize>::__max 531*38fd1498Szrj && !traits_type::eq_int_type(__c, __eof)) 532*38fd1498Szrj { 533*38fd1498Szrj _M_gcount = 534*38fd1498Szrj __gnu_cxx::__numeric_traits<streamsize>::__min; 535*38fd1498Szrj __large_ignore = true; 536*38fd1498Szrj } 537*38fd1498Szrj else 538*38fd1498Szrj break; 539*38fd1498Szrj } 540*38fd1498Szrj 541*38fd1498Szrj if (__large_ignore) 542*38fd1498Szrj _M_gcount = __gnu_cxx::__numeric_traits<streamsize>::__max; 543*38fd1498Szrj 544*38fd1498Szrj if (traits_type::eq_int_type(__c, __eof)) 545*38fd1498Szrj __err |= ios_base::eofbit; 546*38fd1498Szrj } 547*38fd1498Szrj __catch(__cxxabiv1::__forced_unwind&) 548*38fd1498Szrj { 549*38fd1498Szrj this->_M_setstate(ios_base::badbit); 550*38fd1498Szrj __throw_exception_again; 551*38fd1498Szrj } 552*38fd1498Szrj __catch(...) 553*38fd1498Szrj { this->_M_setstate(ios_base::badbit); } 554*38fd1498Szrj if (__err) 555*38fd1498Szrj this->setstate(__err); 556*38fd1498Szrj } 557*38fd1498Szrj return *this; 558*38fd1498Szrj } 559*38fd1498Szrj 560*38fd1498Szrj template<typename _CharT, typename _Traits> 561*38fd1498Szrj basic_istream<_CharT, _Traits>& 562*38fd1498Szrj basic_istream<_CharT, _Traits>:: ignore(streamsize __n,int_type __delim)563*38fd1498Szrj ignore(streamsize __n, int_type __delim) 564*38fd1498Szrj { 565*38fd1498Szrj _M_gcount = 0; 566*38fd1498Szrj sentry __cerb(*this, true); 567*38fd1498Szrj if (__cerb && __n > 0) 568*38fd1498Szrj { 569*38fd1498Szrj ios_base::iostate __err = ios_base::goodbit; 570*38fd1498Szrj __try 571*38fd1498Szrj { 572*38fd1498Szrj const int_type __eof = traits_type::eof(); 573*38fd1498Szrj __streambuf_type* __sb = this->rdbuf(); 574*38fd1498Szrj int_type __c = __sb->sgetc(); 575*38fd1498Szrj 576*38fd1498Szrj // See comment above. 577*38fd1498Szrj bool __large_ignore = false; 578*38fd1498Szrj while (true) 579*38fd1498Szrj { 580*38fd1498Szrj while (_M_gcount < __n 581*38fd1498Szrj && !traits_type::eq_int_type(__c, __eof) 582*38fd1498Szrj && !traits_type::eq_int_type(__c, __delim)) 583*38fd1498Szrj { 584*38fd1498Szrj ++_M_gcount; 585*38fd1498Szrj __c = __sb->snextc(); 586*38fd1498Szrj } 587*38fd1498Szrj if (__n == __gnu_cxx::__numeric_traits<streamsize>::__max 588*38fd1498Szrj && !traits_type::eq_int_type(__c, __eof) 589*38fd1498Szrj && !traits_type::eq_int_type(__c, __delim)) 590*38fd1498Szrj { 591*38fd1498Szrj _M_gcount = 592*38fd1498Szrj __gnu_cxx::__numeric_traits<streamsize>::__min; 593*38fd1498Szrj __large_ignore = true; 594*38fd1498Szrj } 595*38fd1498Szrj else 596*38fd1498Szrj break; 597*38fd1498Szrj } 598*38fd1498Szrj 599*38fd1498Szrj if (__large_ignore) 600*38fd1498Szrj _M_gcount = __gnu_cxx::__numeric_traits<streamsize>::__max; 601*38fd1498Szrj 602*38fd1498Szrj if (traits_type::eq_int_type(__c, __eof)) 603*38fd1498Szrj __err |= ios_base::eofbit; 604*38fd1498Szrj else if (traits_type::eq_int_type(__c, __delim)) 605*38fd1498Szrj { 606*38fd1498Szrj if (_M_gcount 607*38fd1498Szrj < __gnu_cxx::__numeric_traits<streamsize>::__max) 608*38fd1498Szrj ++_M_gcount; 609*38fd1498Szrj __sb->sbumpc(); 610*38fd1498Szrj } 611*38fd1498Szrj } 612*38fd1498Szrj __catch(__cxxabiv1::__forced_unwind&) 613*38fd1498Szrj { 614*38fd1498Szrj this->_M_setstate(ios_base::badbit); 615*38fd1498Szrj __throw_exception_again; 616*38fd1498Szrj } 617*38fd1498Szrj __catch(...) 618*38fd1498Szrj { this->_M_setstate(ios_base::badbit); } 619*38fd1498Szrj if (__err) 620*38fd1498Szrj this->setstate(__err); 621*38fd1498Szrj } 622*38fd1498Szrj return *this; 623*38fd1498Szrj } 624*38fd1498Szrj 625*38fd1498Szrj template<typename _CharT, typename _Traits> 626*38fd1498Szrj typename basic_istream<_CharT, _Traits>::int_type 627*38fd1498Szrj basic_istream<_CharT, _Traits>:: peek(void)628*38fd1498Szrj peek(void) 629*38fd1498Szrj { 630*38fd1498Szrj int_type __c = traits_type::eof(); 631*38fd1498Szrj _M_gcount = 0; 632*38fd1498Szrj sentry __cerb(*this, true); 633*38fd1498Szrj if (__cerb) 634*38fd1498Szrj { 635*38fd1498Szrj ios_base::iostate __err = ios_base::goodbit; 636*38fd1498Szrj __try 637*38fd1498Szrj { 638*38fd1498Szrj __c = this->rdbuf()->sgetc(); 639*38fd1498Szrj if (traits_type::eq_int_type(__c, traits_type::eof())) 640*38fd1498Szrj __err |= ios_base::eofbit; 641*38fd1498Szrj } 642*38fd1498Szrj __catch(__cxxabiv1::__forced_unwind&) 643*38fd1498Szrj { 644*38fd1498Szrj this->_M_setstate(ios_base::badbit); 645*38fd1498Szrj __throw_exception_again; 646*38fd1498Szrj } 647*38fd1498Szrj __catch(...) 648*38fd1498Szrj { this->_M_setstate(ios_base::badbit); } 649*38fd1498Szrj if (__err) 650*38fd1498Szrj this->setstate(__err); 651*38fd1498Szrj } 652*38fd1498Szrj return __c; 653*38fd1498Szrj } 654*38fd1498Szrj 655*38fd1498Szrj template<typename _CharT, typename _Traits> 656*38fd1498Szrj basic_istream<_CharT, _Traits>& 657*38fd1498Szrj basic_istream<_CharT, _Traits>:: read(char_type * __s,streamsize __n)658*38fd1498Szrj read(char_type* __s, streamsize __n) 659*38fd1498Szrj { 660*38fd1498Szrj _M_gcount = 0; 661*38fd1498Szrj sentry __cerb(*this, true); 662*38fd1498Szrj if (__cerb) 663*38fd1498Szrj { 664*38fd1498Szrj ios_base::iostate __err = ios_base::goodbit; 665*38fd1498Szrj __try 666*38fd1498Szrj { 667*38fd1498Szrj _M_gcount = this->rdbuf()->sgetn(__s, __n); 668*38fd1498Szrj if (_M_gcount != __n) 669*38fd1498Szrj __err |= (ios_base::eofbit | ios_base::failbit); 670*38fd1498Szrj } 671*38fd1498Szrj __catch(__cxxabiv1::__forced_unwind&) 672*38fd1498Szrj { 673*38fd1498Szrj this->_M_setstate(ios_base::badbit); 674*38fd1498Szrj __throw_exception_again; 675*38fd1498Szrj } 676*38fd1498Szrj __catch(...) 677*38fd1498Szrj { this->_M_setstate(ios_base::badbit); } 678*38fd1498Szrj if (__err) 679*38fd1498Szrj this->setstate(__err); 680*38fd1498Szrj } 681*38fd1498Szrj return *this; 682*38fd1498Szrj } 683*38fd1498Szrj 684*38fd1498Szrj template<typename _CharT, typename _Traits> 685*38fd1498Szrj streamsize 686*38fd1498Szrj basic_istream<_CharT, _Traits>:: readsome(char_type * __s,streamsize __n)687*38fd1498Szrj readsome(char_type* __s, streamsize __n) 688*38fd1498Szrj { 689*38fd1498Szrj _M_gcount = 0; 690*38fd1498Szrj sentry __cerb(*this, true); 691*38fd1498Szrj if (__cerb) 692*38fd1498Szrj { 693*38fd1498Szrj ios_base::iostate __err = ios_base::goodbit; 694*38fd1498Szrj __try 695*38fd1498Szrj { 696*38fd1498Szrj // Cannot compare int_type with streamsize generically. 697*38fd1498Szrj const streamsize __num = this->rdbuf()->in_avail(); 698*38fd1498Szrj if (__num > 0) 699*38fd1498Szrj _M_gcount = this->rdbuf()->sgetn(__s, std::min(__num, __n)); 700*38fd1498Szrj else if (__num == -1) 701*38fd1498Szrj __err |= ios_base::eofbit; 702*38fd1498Szrj } 703*38fd1498Szrj __catch(__cxxabiv1::__forced_unwind&) 704*38fd1498Szrj { 705*38fd1498Szrj this->_M_setstate(ios_base::badbit); 706*38fd1498Szrj __throw_exception_again; 707*38fd1498Szrj } 708*38fd1498Szrj __catch(...) 709*38fd1498Szrj { this->_M_setstate(ios_base::badbit); } 710*38fd1498Szrj if (__err) 711*38fd1498Szrj this->setstate(__err); 712*38fd1498Szrj } 713*38fd1498Szrj return _M_gcount; 714*38fd1498Szrj } 715*38fd1498Szrj 716*38fd1498Szrj template<typename _CharT, typename _Traits> 717*38fd1498Szrj basic_istream<_CharT, _Traits>& 718*38fd1498Szrj basic_istream<_CharT, _Traits>:: putback(char_type __c)719*38fd1498Szrj putback(char_type __c) 720*38fd1498Szrj { 721*38fd1498Szrj // _GLIBCXX_RESOLVE_LIB_DEFECTS 722*38fd1498Szrj // 60. What is a formatted input function? 723*38fd1498Szrj _M_gcount = 0; 724*38fd1498Szrj // Clear eofbit per N3168. 725*38fd1498Szrj this->clear(this->rdstate() & ~ios_base::eofbit); 726*38fd1498Szrj sentry __cerb(*this, true); 727*38fd1498Szrj if (__cerb) 728*38fd1498Szrj { 729*38fd1498Szrj ios_base::iostate __err = ios_base::goodbit; 730*38fd1498Szrj __try 731*38fd1498Szrj { 732*38fd1498Szrj const int_type __eof = traits_type::eof(); 733*38fd1498Szrj __streambuf_type* __sb = this->rdbuf(); 734*38fd1498Szrj if (!__sb 735*38fd1498Szrj || traits_type::eq_int_type(__sb->sputbackc(__c), __eof)) 736*38fd1498Szrj __err |= ios_base::badbit; 737*38fd1498Szrj } 738*38fd1498Szrj __catch(__cxxabiv1::__forced_unwind&) 739*38fd1498Szrj { 740*38fd1498Szrj this->_M_setstate(ios_base::badbit); 741*38fd1498Szrj __throw_exception_again; 742*38fd1498Szrj } 743*38fd1498Szrj __catch(...) 744*38fd1498Szrj { this->_M_setstate(ios_base::badbit); } 745*38fd1498Szrj if (__err) 746*38fd1498Szrj this->setstate(__err); 747*38fd1498Szrj } 748*38fd1498Szrj return *this; 749*38fd1498Szrj } 750*38fd1498Szrj 751*38fd1498Szrj template<typename _CharT, typename _Traits> 752*38fd1498Szrj basic_istream<_CharT, _Traits>& 753*38fd1498Szrj basic_istream<_CharT, _Traits>:: unget(void)754*38fd1498Szrj unget(void) 755*38fd1498Szrj { 756*38fd1498Szrj // _GLIBCXX_RESOLVE_LIB_DEFECTS 757*38fd1498Szrj // 60. What is a formatted input function? 758*38fd1498Szrj _M_gcount = 0; 759*38fd1498Szrj // Clear eofbit per N3168. 760*38fd1498Szrj this->clear(this->rdstate() & ~ios_base::eofbit); 761*38fd1498Szrj sentry __cerb(*this, true); 762*38fd1498Szrj if (__cerb) 763*38fd1498Szrj { 764*38fd1498Szrj ios_base::iostate __err = ios_base::goodbit; 765*38fd1498Szrj __try 766*38fd1498Szrj { 767*38fd1498Szrj const int_type __eof = traits_type::eof(); 768*38fd1498Szrj __streambuf_type* __sb = this->rdbuf(); 769*38fd1498Szrj if (!__sb 770*38fd1498Szrj || traits_type::eq_int_type(__sb->sungetc(), __eof)) 771*38fd1498Szrj __err |= ios_base::badbit; 772*38fd1498Szrj } 773*38fd1498Szrj __catch(__cxxabiv1::__forced_unwind&) 774*38fd1498Szrj { 775*38fd1498Szrj this->_M_setstate(ios_base::badbit); 776*38fd1498Szrj __throw_exception_again; 777*38fd1498Szrj } 778*38fd1498Szrj __catch(...) 779*38fd1498Szrj { this->_M_setstate(ios_base::badbit); } 780*38fd1498Szrj if (__err) 781*38fd1498Szrj this->setstate(__err); 782*38fd1498Szrj } 783*38fd1498Szrj return *this; 784*38fd1498Szrj } 785*38fd1498Szrj 786*38fd1498Szrj template<typename _CharT, typename _Traits> 787*38fd1498Szrj int 788*38fd1498Szrj basic_istream<_CharT, _Traits>:: sync(void)789*38fd1498Szrj sync(void) 790*38fd1498Szrj { 791*38fd1498Szrj // _GLIBCXX_RESOLVE_LIB_DEFECTS 792*38fd1498Szrj // DR60. Do not change _M_gcount. 793*38fd1498Szrj int __ret = -1; 794*38fd1498Szrj sentry __cerb(*this, true); 795*38fd1498Szrj if (__cerb) 796*38fd1498Szrj { 797*38fd1498Szrj ios_base::iostate __err = ios_base::goodbit; 798*38fd1498Szrj __try 799*38fd1498Szrj { 800*38fd1498Szrj __streambuf_type* __sb = this->rdbuf(); 801*38fd1498Szrj if (__sb) 802*38fd1498Szrj { 803*38fd1498Szrj if (__sb->pubsync() == -1) 804*38fd1498Szrj __err |= ios_base::badbit; 805*38fd1498Szrj else 806*38fd1498Szrj __ret = 0; 807*38fd1498Szrj } 808*38fd1498Szrj } 809*38fd1498Szrj __catch(__cxxabiv1::__forced_unwind&) 810*38fd1498Szrj { 811*38fd1498Szrj this->_M_setstate(ios_base::badbit); 812*38fd1498Szrj __throw_exception_again; 813*38fd1498Szrj } 814*38fd1498Szrj __catch(...) 815*38fd1498Szrj { this->_M_setstate(ios_base::badbit); } 816*38fd1498Szrj if (__err) 817*38fd1498Szrj this->setstate(__err); 818*38fd1498Szrj } 819*38fd1498Szrj return __ret; 820*38fd1498Szrj } 821*38fd1498Szrj 822*38fd1498Szrj template<typename _CharT, typename _Traits> 823*38fd1498Szrj typename basic_istream<_CharT, _Traits>::pos_type 824*38fd1498Szrj basic_istream<_CharT, _Traits>:: tellg(void)825*38fd1498Szrj tellg(void) 826*38fd1498Szrj { 827*38fd1498Szrj // _GLIBCXX_RESOLVE_LIB_DEFECTS 828*38fd1498Szrj // DR60. Do not change _M_gcount. 829*38fd1498Szrj pos_type __ret = pos_type(-1); 830*38fd1498Szrj sentry __cerb(*this, true); 831*38fd1498Szrj if (__cerb) 832*38fd1498Szrj { 833*38fd1498Szrj __try 834*38fd1498Szrj { 835*38fd1498Szrj if (!this->fail()) 836*38fd1498Szrj __ret = this->rdbuf()->pubseekoff(0, ios_base::cur, 837*38fd1498Szrj ios_base::in); 838*38fd1498Szrj } 839*38fd1498Szrj __catch(__cxxabiv1::__forced_unwind&) 840*38fd1498Szrj { 841*38fd1498Szrj this->_M_setstate(ios_base::badbit); 842*38fd1498Szrj __throw_exception_again; 843*38fd1498Szrj } 844*38fd1498Szrj __catch(...) 845*38fd1498Szrj { this->_M_setstate(ios_base::badbit); } 846*38fd1498Szrj } 847*38fd1498Szrj return __ret; 848*38fd1498Szrj } 849*38fd1498Szrj 850*38fd1498Szrj template<typename _CharT, typename _Traits> 851*38fd1498Szrj basic_istream<_CharT, _Traits>& 852*38fd1498Szrj basic_istream<_CharT, _Traits>:: seekg(pos_type __pos)853*38fd1498Szrj seekg(pos_type __pos) 854*38fd1498Szrj { 855*38fd1498Szrj // _GLIBCXX_RESOLVE_LIB_DEFECTS 856*38fd1498Szrj // DR60. Do not change _M_gcount. 857*38fd1498Szrj // Clear eofbit per N3168. 858*38fd1498Szrj this->clear(this->rdstate() & ~ios_base::eofbit); 859*38fd1498Szrj sentry __cerb(*this, true); 860*38fd1498Szrj if (__cerb) 861*38fd1498Szrj { 862*38fd1498Szrj ios_base::iostate __err = ios_base::goodbit; 863*38fd1498Szrj __try 864*38fd1498Szrj { 865*38fd1498Szrj if (!this->fail()) 866*38fd1498Szrj { 867*38fd1498Szrj // 136. seekp, seekg setting wrong streams? 868*38fd1498Szrj const pos_type __p = this->rdbuf()->pubseekpos(__pos, 869*38fd1498Szrj ios_base::in); 870*38fd1498Szrj 871*38fd1498Szrj // 129. Need error indication from seekp() and seekg() 872*38fd1498Szrj if (__p == pos_type(off_type(-1))) 873*38fd1498Szrj __err |= ios_base::failbit; 874*38fd1498Szrj } 875*38fd1498Szrj } 876*38fd1498Szrj __catch(__cxxabiv1::__forced_unwind&) 877*38fd1498Szrj { 878*38fd1498Szrj this->_M_setstate(ios_base::badbit); 879*38fd1498Szrj __throw_exception_again; 880*38fd1498Szrj } 881*38fd1498Szrj __catch(...) 882*38fd1498Szrj { this->_M_setstate(ios_base::badbit); } 883*38fd1498Szrj if (__err) 884*38fd1498Szrj this->setstate(__err); 885*38fd1498Szrj } 886*38fd1498Szrj return *this; 887*38fd1498Szrj } 888*38fd1498Szrj 889*38fd1498Szrj template<typename _CharT, typename _Traits> 890*38fd1498Szrj basic_istream<_CharT, _Traits>& 891*38fd1498Szrj basic_istream<_CharT, _Traits>:: seekg(off_type __off,ios_base::seekdir __dir)892*38fd1498Szrj seekg(off_type __off, ios_base::seekdir __dir) 893*38fd1498Szrj { 894*38fd1498Szrj // _GLIBCXX_RESOLVE_LIB_DEFECTS 895*38fd1498Szrj // DR60. Do not change _M_gcount. 896*38fd1498Szrj // Clear eofbit per N3168. 897*38fd1498Szrj this->clear(this->rdstate() & ~ios_base::eofbit); 898*38fd1498Szrj sentry __cerb(*this, true); 899*38fd1498Szrj if (__cerb) 900*38fd1498Szrj { 901*38fd1498Szrj ios_base::iostate __err = ios_base::goodbit; 902*38fd1498Szrj __try 903*38fd1498Szrj { 904*38fd1498Szrj if (!this->fail()) 905*38fd1498Szrj { 906*38fd1498Szrj // 136. seekp, seekg setting wrong streams? 907*38fd1498Szrj const pos_type __p = this->rdbuf()->pubseekoff(__off, __dir, 908*38fd1498Szrj ios_base::in); 909*38fd1498Szrj 910*38fd1498Szrj // 129. Need error indication from seekp() and seekg() 911*38fd1498Szrj if (__p == pos_type(off_type(-1))) 912*38fd1498Szrj __err |= ios_base::failbit; 913*38fd1498Szrj } 914*38fd1498Szrj } 915*38fd1498Szrj __catch(__cxxabiv1::__forced_unwind&) 916*38fd1498Szrj { 917*38fd1498Szrj this->_M_setstate(ios_base::badbit); 918*38fd1498Szrj __throw_exception_again; 919*38fd1498Szrj } 920*38fd1498Szrj __catch(...) 921*38fd1498Szrj { this->_M_setstate(ios_base::badbit); } 922*38fd1498Szrj if (__err) 923*38fd1498Szrj this->setstate(__err); 924*38fd1498Szrj } 925*38fd1498Szrj return *this; 926*38fd1498Szrj } 927*38fd1498Szrj 928*38fd1498Szrj // 27.6.1.2.3 Character extraction templates 929*38fd1498Szrj template<typename _CharT, typename _Traits> 930*38fd1498Szrj basic_istream<_CharT, _Traits>& operator >>(basic_istream<_CharT,_Traits> & __in,_CharT & __c)931*38fd1498Szrj operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c) 932*38fd1498Szrj { 933*38fd1498Szrj typedef basic_istream<_CharT, _Traits> __istream_type; 934*38fd1498Szrj typedef typename __istream_type::int_type __int_type; 935*38fd1498Szrj 936*38fd1498Szrj typename __istream_type::sentry __cerb(__in, false); 937*38fd1498Szrj if (__cerb) 938*38fd1498Szrj { 939*38fd1498Szrj ios_base::iostate __err = ios_base::goodbit; 940*38fd1498Szrj __try 941*38fd1498Szrj { 942*38fd1498Szrj const __int_type __cb = __in.rdbuf()->sbumpc(); 943*38fd1498Szrj if (!_Traits::eq_int_type(__cb, _Traits::eof())) 944*38fd1498Szrj __c = _Traits::to_char_type(__cb); 945*38fd1498Szrj else 946*38fd1498Szrj __err |= (ios_base::eofbit | ios_base::failbit); 947*38fd1498Szrj } 948*38fd1498Szrj __catch(__cxxabiv1::__forced_unwind&) 949*38fd1498Szrj { 950*38fd1498Szrj __in._M_setstate(ios_base::badbit); 951*38fd1498Szrj __throw_exception_again; 952*38fd1498Szrj } 953*38fd1498Szrj __catch(...) 954*38fd1498Szrj { __in._M_setstate(ios_base::badbit); } 955*38fd1498Szrj if (__err) 956*38fd1498Szrj __in.setstate(__err); 957*38fd1498Szrj } 958*38fd1498Szrj return __in; 959*38fd1498Szrj } 960*38fd1498Szrj 961*38fd1498Szrj template<typename _CharT, typename _Traits> 962*38fd1498Szrj basic_istream<_CharT, _Traits>& operator >>(basic_istream<_CharT,_Traits> & __in,_CharT * __s)963*38fd1498Szrj operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s) 964*38fd1498Szrj { 965*38fd1498Szrj typedef basic_istream<_CharT, _Traits> __istream_type; 966*38fd1498Szrj typedef basic_streambuf<_CharT, _Traits> __streambuf_type; 967*38fd1498Szrj typedef typename _Traits::int_type int_type; 968*38fd1498Szrj typedef _CharT char_type; 969*38fd1498Szrj typedef ctype<_CharT> __ctype_type; 970*38fd1498Szrj 971*38fd1498Szrj streamsize __extracted = 0; 972*38fd1498Szrj ios_base::iostate __err = ios_base::goodbit; 973*38fd1498Szrj typename __istream_type::sentry __cerb(__in, false); 974*38fd1498Szrj if (__cerb) 975*38fd1498Szrj { 976*38fd1498Szrj __try 977*38fd1498Szrj { 978*38fd1498Szrj // Figure out how many characters to extract. 979*38fd1498Szrj streamsize __num = __in.width(); 980*38fd1498Szrj if (__num <= 0) 981*38fd1498Szrj __num = __gnu_cxx::__numeric_traits<streamsize>::__max; 982*38fd1498Szrj 983*38fd1498Szrj const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc()); 984*38fd1498Szrj 985*38fd1498Szrj const int_type __eof = _Traits::eof(); 986*38fd1498Szrj __streambuf_type* __sb = __in.rdbuf(); 987*38fd1498Szrj int_type __c = __sb->sgetc(); 988*38fd1498Szrj 989*38fd1498Szrj while (__extracted < __num - 1 990*38fd1498Szrj && !_Traits::eq_int_type(__c, __eof) 991*38fd1498Szrj && !__ct.is(ctype_base::space, 992*38fd1498Szrj _Traits::to_char_type(__c))) 993*38fd1498Szrj { 994*38fd1498Szrj *__s++ = _Traits::to_char_type(__c); 995*38fd1498Szrj ++__extracted; 996*38fd1498Szrj __c = __sb->snextc(); 997*38fd1498Szrj } 998*38fd1498Szrj if (_Traits::eq_int_type(__c, __eof)) 999*38fd1498Szrj __err |= ios_base::eofbit; 1000*38fd1498Szrj 1001*38fd1498Szrj // _GLIBCXX_RESOLVE_LIB_DEFECTS 1002*38fd1498Szrj // 68. Extractors for char* should store null at end 1003*38fd1498Szrj *__s = char_type(); 1004*38fd1498Szrj __in.width(0); 1005*38fd1498Szrj } 1006*38fd1498Szrj __catch(__cxxabiv1::__forced_unwind&) 1007*38fd1498Szrj { 1008*38fd1498Szrj __in._M_setstate(ios_base::badbit); 1009*38fd1498Szrj __throw_exception_again; 1010*38fd1498Szrj } 1011*38fd1498Szrj __catch(...) 1012*38fd1498Szrj { __in._M_setstate(ios_base::badbit); } 1013*38fd1498Szrj } 1014*38fd1498Szrj if (!__extracted) 1015*38fd1498Szrj __err |= ios_base::failbit; 1016*38fd1498Szrj if (__err) 1017*38fd1498Szrj __in.setstate(__err); 1018*38fd1498Szrj return __in; 1019*38fd1498Szrj } 1020*38fd1498Szrj 1021*38fd1498Szrj // 27.6.1.4 Standard basic_istream manipulators 1022*38fd1498Szrj template<typename _CharT, typename _Traits> 1023*38fd1498Szrj basic_istream<_CharT, _Traits>& ws(basic_istream<_CharT,_Traits> & __in)1024*38fd1498Szrj ws(basic_istream<_CharT, _Traits>& __in) 1025*38fd1498Szrj { 1026*38fd1498Szrj typedef basic_istream<_CharT, _Traits> __istream_type; 1027*38fd1498Szrj typedef basic_streambuf<_CharT, _Traits> __streambuf_type; 1028*38fd1498Szrj typedef typename __istream_type::int_type __int_type; 1029*38fd1498Szrj typedef ctype<_CharT> __ctype_type; 1030*38fd1498Szrj 1031*38fd1498Szrj const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc()); 1032*38fd1498Szrj const __int_type __eof = _Traits::eof(); 1033*38fd1498Szrj __streambuf_type* __sb = __in.rdbuf(); 1034*38fd1498Szrj __int_type __c = __sb->sgetc(); 1035*38fd1498Szrj 1036*38fd1498Szrj while (!_Traits::eq_int_type(__c, __eof) 1037*38fd1498Szrj && __ct.is(ctype_base::space, _Traits::to_char_type(__c))) 1038*38fd1498Szrj __c = __sb->snextc(); 1039*38fd1498Szrj 1040*38fd1498Szrj if (_Traits::eq_int_type(__c, __eof)) 1041*38fd1498Szrj __in.setstate(ios_base::eofbit); 1042*38fd1498Szrj return __in; 1043*38fd1498Szrj } 1044*38fd1498Szrj 1045*38fd1498Szrj // Inhibit implicit instantiations for required instantiations, 1046*38fd1498Szrj // which are defined via explicit instantiations elsewhere. 1047*38fd1498Szrj #if _GLIBCXX_EXTERN_TEMPLATE 1048*38fd1498Szrj extern template class basic_istream<char>; 1049*38fd1498Szrj extern template istream& ws(istream&); 1050*38fd1498Szrj extern template istream& operator>>(istream&, char&); 1051*38fd1498Szrj extern template istream& operator>>(istream&, char*); 1052*38fd1498Szrj extern template istream& operator>>(istream&, unsigned char&); 1053*38fd1498Szrj extern template istream& operator>>(istream&, signed char&); 1054*38fd1498Szrj extern template istream& operator>>(istream&, unsigned char*); 1055*38fd1498Szrj extern template istream& operator>>(istream&, signed char*); 1056*38fd1498Szrj 1057*38fd1498Szrj extern template istream& istream::_M_extract(unsigned short&); 1058*38fd1498Szrj extern template istream& istream::_M_extract(unsigned int&); 1059*38fd1498Szrj extern template istream& istream::_M_extract(long&); 1060*38fd1498Szrj extern template istream& istream::_M_extract(unsigned long&); 1061*38fd1498Szrj extern template istream& istream::_M_extract(bool&); 1062*38fd1498Szrj #ifdef _GLIBCXX_USE_LONG_LONG 1063*38fd1498Szrj extern template istream& istream::_M_extract(long long&); 1064*38fd1498Szrj extern template istream& istream::_M_extract(unsigned long long&); 1065*38fd1498Szrj #endif 1066*38fd1498Szrj extern template istream& istream::_M_extract(float&); 1067*38fd1498Szrj extern template istream& istream::_M_extract(double&); 1068*38fd1498Szrj extern template istream& istream::_M_extract(long double&); 1069*38fd1498Szrj extern template istream& istream::_M_extract(void*&); 1070*38fd1498Szrj 1071*38fd1498Szrj extern template class basic_iostream<char>; 1072*38fd1498Szrj 1073*38fd1498Szrj #ifdef _GLIBCXX_USE_WCHAR_T 1074*38fd1498Szrj extern template class basic_istream<wchar_t>; 1075*38fd1498Szrj extern template wistream& ws(wistream&); 1076*38fd1498Szrj extern template wistream& operator>>(wistream&, wchar_t&); 1077*38fd1498Szrj extern template wistream& operator>>(wistream&, wchar_t*); 1078*38fd1498Szrj 1079*38fd1498Szrj extern template wistream& wistream::_M_extract(unsigned short&); 1080*38fd1498Szrj extern template wistream& wistream::_M_extract(unsigned int&); 1081*38fd1498Szrj extern template wistream& wistream::_M_extract(long&); 1082*38fd1498Szrj extern template wistream& wistream::_M_extract(unsigned long&); 1083*38fd1498Szrj extern template wistream& wistream::_M_extract(bool&); 1084*38fd1498Szrj #ifdef _GLIBCXX_USE_LONG_LONG 1085*38fd1498Szrj extern template wistream& wistream::_M_extract(long long&); 1086*38fd1498Szrj extern template wistream& wistream::_M_extract(unsigned long long&); 1087*38fd1498Szrj #endif 1088*38fd1498Szrj extern template wistream& wistream::_M_extract(float&); 1089*38fd1498Szrj extern template wistream& wistream::_M_extract(double&); 1090*38fd1498Szrj extern template wistream& wistream::_M_extract(long double&); 1091*38fd1498Szrj extern template wistream& wistream::_M_extract(void*&); 1092*38fd1498Szrj 1093*38fd1498Szrj extern template class basic_iostream<wchar_t>; 1094*38fd1498Szrj #endif 1095*38fd1498Szrj #endif 1096*38fd1498Szrj 1097*38fd1498Szrj _GLIBCXX_END_NAMESPACE_VERSION 1098*38fd1498Szrj } // namespace std 1099*38fd1498Szrj 1100*38fd1498Szrj #endif 1101