2000-10-05 19:27:02 +08:00
|
|
|
// File based streams -*- C++ -*-
|
|
|
|
|
2003-01-17 04:30:50 +08:00
|
|
|
// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003
|
2002-01-26 09:55:09 +08:00
|
|
|
// Free Software Foundation, Inc.
|
2000-10-05 19:27:02 +08:00
|
|
|
//
|
|
|
|
// This file is part of the GNU ISO C++ Library. This library is free
|
|
|
|
// software; you can redistribute it and/or modify it under the
|
|
|
|
// terms of the GNU General Public License as published by the
|
|
|
|
// Free Software Foundation; either version 2, or (at your option)
|
|
|
|
// any later version.
|
|
|
|
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with this library; see the file COPYING. If not, write to the Free
|
|
|
|
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
|
|
|
// USA.
|
|
|
|
|
|
|
|
// As a special exception, you may use this file as part of a free software
|
|
|
|
// library without restriction. Specifically, if other files instantiate
|
|
|
|
// templates or use macros or inline functions from this file, or you compile
|
|
|
|
// this file and link it with other files to produce an executable, this
|
|
|
|
// file does not by itself cause the resulting executable to be covered by
|
|
|
|
// the GNU General Public License. This exception does not however
|
|
|
|
// invalidate any other reasons why the executable file might be covered by
|
|
|
|
// the GNU General Public License.
|
|
|
|
|
|
|
|
//
|
|
|
|
// ISO C++ 14882: 27.8 File-based streams
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef _CPP_BITS_FSTREAM_TCC
|
|
|
|
#define _CPP_BITS_FSTREAM_TCC 1
|
|
|
|
|
2002-02-17 03:33:43 +08:00
|
|
|
#pragma GCC system_header
|
|
|
|
|
2000-10-05 19:27:02 +08:00
|
|
|
namespace std
|
|
|
|
{
|
std_streambuf.h (_S_pback_size, [...]): Move to basic_filebuf.
2003-04-22 Paolo Carlini <pcarlini@unitus.it>
* include/std/std_streambuf.h (_S_pback_size, _M_pback,
_M_pback_cur_save, _M_pback_end_save, _M_pback_init,
_M_pback_create(), _M_pback_destroy()): Move to basic_filebuf.
(basic_streambuf::basic_streambuf()): Adjust.
* include/std/std_fstream.h (_S_pback_size, _M_pback,
_M_pback_cur_save, _M_pback_end_save, _M_pback_init,
_M_pback_create(), _M_pback_destroy()): Moved here
from basic_streambuf.
* include/bits/fstream.tcc (basic_filebuf::basic_filebuf()):
Adjust.
(basic_filebuf::_S_pback_size): Add declaration.
* include/bits/streambuf.tcc (basic_streambuf::_S_pback_size):
Remove declaration.
From-SVN: r65950
2003-04-23 01:32:25 +08:00
|
|
|
template<typename _CharT, typename _Traits>
|
|
|
|
const size_t
|
|
|
|
basic_filebuf<_CharT, _Traits>::_S_pback_size;
|
|
|
|
|
2000-10-05 19:27:02 +08:00
|
|
|
template<typename _CharT, typename _Traits>
|
|
|
|
void
|
|
|
|
basic_filebuf<_CharT, _Traits>::
|
2001-05-23 02:48:19 +08:00
|
|
|
_M_allocate_internal_buffer()
|
2000-10-05 19:27:02 +08:00
|
|
|
{
|
2003-04-13 03:21:35 +08:00
|
|
|
if (!this->_M_buf && this->_M_buf_size)
|
2001-01-16 15:55:26 +08:00
|
|
|
{
|
2003-04-01 02:24:13 +08:00
|
|
|
// Allocate internal buffer.
|
PR libstdc++/9404, PR libstdc++/9701 (partial)
2003-02-24 Paolo Carlini <pcarlini@unitus.it>
Nathan Myers <ncm@cantrip.org>
PR libstdc++/9404, PR libstdc++/9701 (partial)
(aka pptr == epptr implies overflow)
* include/bits/fstream.tcc (_M_allocate_internal_buffer):
Consistently, _M_out_end points to the end of the buffer just
created.
(overflow): Tweak to use _M_out_buf_size().
(_M_convert_to_external): The role of the old _M_out_end is
now played by _M_out_lim.
(_M_really_overflow): Likewise.
(seekoff): Likewise.
(setbuf): _M_out_end points to the end of the external buffer.
* include/bits/sstream.tcc (overflow): Rewrote, taking into
account the resolution of DR 169 (TC).
(seekoff): Use _M_string.capacity(); ios_base::end is now _M_out_lim.
(seekpos): Use _M_string.capacity(); tweak.
* include/bits/streambuf.tcc (sputc, xsputn): Remove comments.
* include/std/std_fstream.h (sync): The role of the old
_M_out_end is now played by _M_out_lim.
(_M_set_indeterminate): Use _M_set_determinate.
(_M_set_determinate): _M_out_end is now _M_out_lim.
(_M_is_indeterminate): Likewise.
* include/std/std_sstream.h (str()): _M_out_end is now _M_out_lim.
(_M_stringbuf_init): Don't set _M_buf_size, unused for sstreams,
which have the information readily available as _M_string.capacity();
for ate and app modes, pass the string size to _M_really_sync.
(_M_really_sync): Consistently set _M_out_end and _M_out_lim, to
point to the end of the buffer (i.e., epptr) and to the string end,
respectively.
* include/std/std_streambuf.h: tweak comments, add _M_out_lim,
which points to the right limit of the used put area.
(_M_out_cur_move): The role of the old _M_out_end is now played
by _M_out_lim.
(_M_out_buf_size): Simplify: now (when _M_out_cur) return simply
_M_out_end - _M_out_cur (i.e., pptr), _very_ close to the letter
of the standard.
(basic_streambuf()): Initialize _M_out_lim too.
* testsuite/27_io/filebuf_virtuals.cc (test10): Trivial tweak.
* testsuite/27_io/filebuf_virtuals.cc (test11): Add.
* testsuite/27_io/stringbuf_virtuals.cc (test09): Add.
Co-Authored-By: Nathan Myers <ncm@cantrip.org>
From-SVN: r63367
2003-02-25 02:22:58 +08:00
|
|
|
this->_M_buf = new char_type[this->_M_buf_size];
|
2002-05-01 03:04:43 +08:00
|
|
|
_M_buf_allocated = true;
|
2001-05-23 02:48:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Both close and setbuf need to deallocate internal buffers, if it exists.
|
|
|
|
template<typename _CharT, typename _Traits>
|
|
|
|
void
|
|
|
|
basic_filebuf<_CharT, _Traits>::
|
2003-04-26 08:23:18 +08:00
|
|
|
_M_destroy_internal_buffer() throw()
|
2001-05-23 02:48:19 +08:00
|
|
|
{
|
|
|
|
if (_M_buf_allocated)
|
|
|
|
{
|
2003-01-17 04:30:50 +08:00
|
|
|
delete [] this->_M_buf;
|
|
|
|
this->_M_buf = NULL;
|
2001-05-23 02:48:19 +08:00
|
|
|
_M_buf_allocated = false;
|
|
|
|
this->setg(NULL, NULL, NULL);
|
|
|
|
this->setp(NULL, NULL);
|
|
|
|
}
|
2000-10-05 19:27:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits>
|
|
|
|
basic_filebuf<_CharT, _Traits>::
|
2002-05-01 03:04:43 +08:00
|
|
|
basic_filebuf() : __streambuf_type(), _M_file(&_M_lock),
|
|
|
|
_M_state_cur(__state_type()), _M_state_beg(__state_type()),
|
2003-04-29 07:51:37 +08:00
|
|
|
_M_buf(NULL), _M_buf_size(BUFSIZ), _M_buf_allocated(false),
|
|
|
|
_M_last_overflowed(false), _M_pback_cur_save(0),
|
|
|
|
_M_pback_end_save(0), _M_pback_init(false)
|
2003-01-17 04:30:50 +08:00
|
|
|
{ this->_M_buf_unified = true; }
|
2000-10-05 19:27:02 +08:00
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits>
|
2001-07-20 08:09:31 +08:00
|
|
|
typename basic_filebuf<_CharT, _Traits>::__filebuf_type*
|
2000-10-05 19:27:02 +08:00
|
|
|
basic_filebuf<_CharT, _Traits>::
|
|
|
|
open(const char* __s, ios_base::openmode __mode)
|
|
|
|
{
|
|
|
|
__filebuf_type *__ret = NULL;
|
|
|
|
if (!this->is_open())
|
|
|
|
{
|
2002-04-16 08:45:36 +08:00
|
|
|
_M_file.open(__s, __mode);
|
2001-01-16 15:55:26 +08:00
|
|
|
if (this->is_open())
|
2000-10-05 19:27:02 +08:00
|
|
|
{
|
2001-05-23 02:48:19 +08:00
|
|
|
_M_allocate_internal_buffer();
|
2003-01-17 04:30:50 +08:00
|
|
|
this->_M_mode = __mode;
|
2002-11-12 07:18:05 +08:00
|
|
|
|
|
|
|
// Setup initial position of buffer.
|
2000-10-05 19:27:02 +08:00
|
|
|
_M_set_indeterminate();
|
2002-08-16 06:25:39 +08:00
|
|
|
|
2002-04-12 13:42:23 +08:00
|
|
|
if ((__mode & ios_base::ate)
|
2000-10-05 19:27:02 +08:00
|
|
|
&& this->seekoff(0, ios_base::end, __mode) < 0)
|
2003-04-30 03:46:07 +08:00
|
|
|
// 27.8.1.3,4
|
|
|
|
this->close();
|
|
|
|
else
|
|
|
|
__ret = this;
|
2000-10-05 19:27:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return __ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits>
|
2001-07-20 08:09:31 +08:00
|
|
|
typename basic_filebuf<_CharT, _Traits>::__filebuf_type*
|
2000-10-05 19:27:02 +08:00
|
|
|
basic_filebuf<_CharT, _Traits>::
|
2003-04-26 08:23:18 +08:00
|
|
|
close() throw()
|
2000-10-05 19:27:02 +08:00
|
|
|
{
|
2003-03-18 02:44:44 +08:00
|
|
|
__filebuf_type* __ret = NULL;
|
2000-10-05 19:27:02 +08:00
|
|
|
if (this->is_open())
|
|
|
|
{
|
2003-03-18 02:44:44 +08:00
|
|
|
bool __testfail = false;
|
2003-04-26 08:23:18 +08:00
|
|
|
try
|
|
|
|
{
|
|
|
|
const int_type __eof = traits_type::eof();
|
|
|
|
const bool __testput = this->_M_out_beg < this->_M_out_lim;
|
According to 5.9 para 2 (second bullet) for pointers p...
2003-04-18 Paolo Carlini <pcarlini@unitus.it>
According to 5.9 para 2 (second bullet) for pointers p, q
pointing to the same type, with p == 0 and q == 0, (p < q)
is false.
* include/bits/fstream.tcc (close, overflow, _M_really_overflow,
seekoff): Remove redundant NULL pointer checks from tests
involving _M_out_* and _M_in_*, const qualify bool variables.
(showmanyc, pbackfail, _M_convert_to_external, imbue): Const
qualify bool variables.
* include/bits/streambuf.tcc (sbumpc, sputbackc, sungetc, sputc):
Remove redundant NULL pointer checks from tests involving
_M_out_* and _M_in_*, const qualify bool variables.
* include/std/std_fstream.h (sync): Likewise.
(_M_is_indeterminate): Const qualify bool variables.
* include/std/std_streambuf.h (sgetc, uflow): Remove redundant
NULL pointer checks from tests involving _M_out_* and _M_in_*,
const qualify bool variables.
(_M_in_cur_move, _M_out_cur_move, uflow): Const qualify bool
variables.
From-SVN: r65783
2003-04-18 21:55:22 +08:00
|
|
|
|
2003-04-26 08:23:18 +08:00
|
|
|
if (__testput
|
2003-04-28 12:54:54 +08:00
|
|
|
&& traits_type::eq_int_type(_M_overflow(__eof), __eof))
|
2003-04-26 08:23:18 +08:00
|
|
|
__testfail = true;
|
2000-10-05 19:27:02 +08:00
|
|
|
|
|
|
|
#if 0
|
2003-04-26 08:23:18 +08:00
|
|
|
// XXX not done
|
|
|
|
if (_M_last_overflowed)
|
|
|
|
{
|
|
|
|
_M_output_unshift();
|
2003-04-28 12:54:54 +08:00
|
|
|
_M_overflow(__eof);
|
2003-04-26 08:23:18 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
catch(...)
|
2000-10-05 19:27:02 +08:00
|
|
|
{
|
2003-04-26 08:23:18 +08:00
|
|
|
__testfail = true;
|
2000-10-05 19:27:02 +08:00
|
|
|
}
|
2003-04-26 08:23:18 +08:00
|
|
|
|
2003-03-18 02:44:44 +08:00
|
|
|
// NB: Do this here so that re-opened filebufs will be cool...
|
|
|
|
this->_M_mode = ios_base::openmode(0);
|
2003-05-07 20:48:58 +08:00
|
|
|
this->_M_pback_init = false;
|
2003-03-18 02:44:44 +08:00
|
|
|
_M_destroy_internal_buffer();
|
2003-04-26 08:23:18 +08:00
|
|
|
|
2003-03-18 02:44:44 +08:00
|
|
|
if (!_M_file.close())
|
|
|
|
__testfail = true;
|
|
|
|
|
|
|
|
if (!__testfail)
|
2002-04-16 08:45:36 +08:00
|
|
|
__ret = this;
|
2000-10-05 19:27:02 +08:00
|
|
|
}
|
2003-04-26 08:23:18 +08:00
|
|
|
_M_last_overflowed = false;
|
2000-10-05 19:27:02 +08:00
|
|
|
return __ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits>
|
|
|
|
streamsize
|
|
|
|
basic_filebuf<_CharT, _Traits>::
|
|
|
|
showmanyc()
|
|
|
|
{
|
|
|
|
streamsize __ret = -1;
|
According to 5.9 para 2 (second bullet) for pointers p...
2003-04-18 Paolo Carlini <pcarlini@unitus.it>
According to 5.9 para 2 (second bullet) for pointers p, q
pointing to the same type, with p == 0 and q == 0, (p < q)
is false.
* include/bits/fstream.tcc (close, overflow, _M_really_overflow,
seekoff): Remove redundant NULL pointer checks from tests
involving _M_out_* and _M_in_*, const qualify bool variables.
(showmanyc, pbackfail, _M_convert_to_external, imbue): Const
qualify bool variables.
* include/bits/streambuf.tcc (sbumpc, sputbackc, sungetc, sputc):
Remove redundant NULL pointer checks from tests involving
_M_out_* and _M_in_*, const qualify bool variables.
* include/std/std_fstream.h (sync): Likewise.
(_M_is_indeterminate): Const qualify bool variables.
* include/std/std_streambuf.h (sgetc, uflow): Remove redundant
NULL pointer checks from tests involving _M_out_* and _M_in_*,
const qualify bool variables.
(_M_in_cur_move, _M_out_cur_move, uflow): Const qualify bool
variables.
From-SVN: r65783
2003-04-18 21:55:22 +08:00
|
|
|
const bool __testin = this->_M_mode & ios_base::in;
|
2003-03-29 02:28:47 +08:00
|
|
|
const locale __loc = this->getloc();
|
|
|
|
const __codecvt_type& __cvt = use_facet<__codecvt_type>(__loc);
|
2000-10-05 19:27:02 +08:00
|
|
|
|
2002-01-09 03:57:01 +08:00
|
|
|
if (__testin && this->is_open())
|
2003-03-29 02:28:47 +08:00
|
|
|
{
|
|
|
|
__ret = this->_M_in_end - this->_M_in_cur;
|
|
|
|
|
|
|
|
// For a stateful encoding (-1) the pending sequence might be just
|
|
|
|
// shift and unshift prefixes with no actual character.
|
|
|
|
if (__cvt.encoding() >= 0)
|
[multiple changes]
2003-05-10 Petur Runolfsson <peturr02@ru.is>
PR libstdc++/9027
PR libstdc++/9520
PR libstdc++/10096
* include/bits/fstream.tcc (basic_file::_M_underflow): Add generic
implementation, based on old wchar_t specialization, add support
for codecvt::in() return value of codecvt_base::noconv, remove
_M_file.sys_ungetc() call.
* include/std/std_fstream.h (basic_file::underflow,
basic_file::uflow, basic_file::_M_underflow): Remove
specialization declarations, call _M_underflow from generic versions
of underflow and uflow.
* src/fstream.cc (basic_file::underflow, basic_file::uflow,
basic_file::_M_underflow): Remove specializations.
* src/Makefile.am (sources): Remove fstream.cc.
* src/Makefile.in: Regenerated.
* testsuite/27_io/basic_filebuf/underflow/10096.cc: New test.
* testsuite/27_io/basic_filebuf/underflow/char/1.cc: New test.
* testsuite/27_io/basic_filebuf/underflow/char/9027.cc: New test.
* testsuite/27_io/basic_filebuf/underflow/wchar_t/9520.cc: New test.
2003-05-10 Benjamin Kosnik <bkoz@redhat.com>
* include/ext/stdio_filebuf.h (__stdio_filebuf): Remove stack
buffer.
* config/io/basic_file_stdio.h (__basic_file::xsgetn): Remove
unbuffered bits.
(__basic_file::xsputn): Same.
(__basic_file::seekoff): Same.
(__basic_file::seekpos): Same.
(__basic_file::showmanyc): Same.
* config/io/basic_file_stdio.cc: Same.
* include/std/std_fstream.h: Same.
* include/bits/fstream.tcc: Same.
* src/fstream.cc: Same.
* testsuite/27_io/basic_filebuf/sgetn/char/1.cc (test05): Tidy.
2003-05-10 Petur Runolfsson <peturr02@ru.is>
PR libstdc++/9520
PR libstdc++/9661
PR libstdc++/9662
* include/ext/stdio_sync_filebuf.h: New file.
(basic_stdiobuf): New.
* include/Makefile.am (ext_headers): Add ext/stdio_sync_filebuf.h
* include/Makefile.in: Regenerate.
* include/bits/ios_base.h (Init::_S_create_buffers,
Init::_S_destroy_buffers): Remove declarations.
* src/globals.cc (buf_cout_sync, buf_cin_sync, buf_cerr_sync,
buf_wcout_sync, buf_wcin_sync, buf_wcerr_sync): Define.
* src/ios.cc (Init::_S_create_buffers,
Init::_S_destroy_buffers): Remove.
(Init::Init): Create and use syncronized buffers.
(ios_base::sync_with_stdio): Destroy syncronized buffers,
create and install unsyncronized buffers.
* testsuite/27_io/objects/char/10.cc: New test.
* testsuite/27_io/objects/char/9.cc: New test.
* testsuite/27_io/objects/char/9661-1.cc: New test.
* testsuite/27_io/objects/char/9661-2_xin.cc: New test.
* testsuite/27_io/objects/char/9661-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/1.cc: New test.
* testsuite/27_io/objects/wchar_t/10.cc: New test.
* testsuite/27_io/objects/wchar_t/2.cc: New test.
* testsuite/27_io/objects/wchar_t/2523-1_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/2523-1_xin.in: New.
* testsuite/27_io/objects/wchar_t/2523-2_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/2523-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/3045.cc: New test.
* testsuite/27_io/objects/wchar_t/3647.cc: New test.
* testsuite/27_io/objects/wchar_t/3_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/3_xin.in: New.
* testsuite/27_io/objects/wchar_t/4_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/4_xin.in: New.
* testsuite/27_io/objects/wchar_t/5.cc: New test.
* testsuite/27_io/objects/wchar_t/5268.cc: New test.
* testsuite/27_io/objects/wchar_t/5280_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/5280_xin.in: New.
* testsuite/27_io/objects/wchar_t/6.cc: New test.
* testsuite/27_io/objects/wchar_t/6548_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/6548_xin.in: New.
* testsuite/27_io/objects/wchar_t/6648-1_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/6648-1_xin.in: New.
* testsuite/27_io/objects/wchar_t/6648-2_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/6648-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/7.cc: New test.
* testsuite/27_io/objects/wchar_t/7744_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/7744_xin.in: New.
* testsuite/27_io/objects/wchar_t/8.cc: New test.
* testsuite/27_io/objects/wchar_t/9_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/9_xin.in: New.
* testsuite/27_io/objects/wchar_t/9520.cc: New test.
* testsuite/27_io/objects/wchar_t/9661-1.cc: New test.
* testsuite/27_io/objects/wchar_t/9661-2_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/9661-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/9662.cc: New test.
* testsuite/ext/stdiobuf_char.cc: New test.
* testsuite/ext/stdiobuf_wchar_t.cc: New test.
From-SVN: r66678
2003-05-11 12:20:57 +08:00
|
|
|
__ret += _M_file.showmanyc() / __cvt.max_length();
|
2003-03-29 02:28:47 +08:00
|
|
|
}
|
|
|
|
|
2000-10-05 19:27:02 +08:00
|
|
|
_M_last_overflowed = false;
|
|
|
|
return __ret;
|
|
|
|
}
|
|
|
|
|
[multiple changes]
2003-05-10 Petur Runolfsson <peturr02@ru.is>
PR libstdc++/9027
PR libstdc++/9520
PR libstdc++/10096
* include/bits/fstream.tcc (basic_file::_M_underflow): Add generic
implementation, based on old wchar_t specialization, add support
for codecvt::in() return value of codecvt_base::noconv, remove
_M_file.sys_ungetc() call.
* include/std/std_fstream.h (basic_file::underflow,
basic_file::uflow, basic_file::_M_underflow): Remove
specialization declarations, call _M_underflow from generic versions
of underflow and uflow.
* src/fstream.cc (basic_file::underflow, basic_file::uflow,
basic_file::_M_underflow): Remove specializations.
* src/Makefile.am (sources): Remove fstream.cc.
* src/Makefile.in: Regenerated.
* testsuite/27_io/basic_filebuf/underflow/10096.cc: New test.
* testsuite/27_io/basic_filebuf/underflow/char/1.cc: New test.
* testsuite/27_io/basic_filebuf/underflow/char/9027.cc: New test.
* testsuite/27_io/basic_filebuf/underflow/wchar_t/9520.cc: New test.
2003-05-10 Benjamin Kosnik <bkoz@redhat.com>
* include/ext/stdio_filebuf.h (__stdio_filebuf): Remove stack
buffer.
* config/io/basic_file_stdio.h (__basic_file::xsgetn): Remove
unbuffered bits.
(__basic_file::xsputn): Same.
(__basic_file::seekoff): Same.
(__basic_file::seekpos): Same.
(__basic_file::showmanyc): Same.
* config/io/basic_file_stdio.cc: Same.
* include/std/std_fstream.h: Same.
* include/bits/fstream.tcc: Same.
* src/fstream.cc: Same.
* testsuite/27_io/basic_filebuf/sgetn/char/1.cc (test05): Tidy.
2003-05-10 Petur Runolfsson <peturr02@ru.is>
PR libstdc++/9520
PR libstdc++/9661
PR libstdc++/9662
* include/ext/stdio_sync_filebuf.h: New file.
(basic_stdiobuf): New.
* include/Makefile.am (ext_headers): Add ext/stdio_sync_filebuf.h
* include/Makefile.in: Regenerate.
* include/bits/ios_base.h (Init::_S_create_buffers,
Init::_S_destroy_buffers): Remove declarations.
* src/globals.cc (buf_cout_sync, buf_cin_sync, buf_cerr_sync,
buf_wcout_sync, buf_wcin_sync, buf_wcerr_sync): Define.
* src/ios.cc (Init::_S_create_buffers,
Init::_S_destroy_buffers): Remove.
(Init::Init): Create and use syncronized buffers.
(ios_base::sync_with_stdio): Destroy syncronized buffers,
create and install unsyncronized buffers.
* testsuite/27_io/objects/char/10.cc: New test.
* testsuite/27_io/objects/char/9.cc: New test.
* testsuite/27_io/objects/char/9661-1.cc: New test.
* testsuite/27_io/objects/char/9661-2_xin.cc: New test.
* testsuite/27_io/objects/char/9661-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/1.cc: New test.
* testsuite/27_io/objects/wchar_t/10.cc: New test.
* testsuite/27_io/objects/wchar_t/2.cc: New test.
* testsuite/27_io/objects/wchar_t/2523-1_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/2523-1_xin.in: New.
* testsuite/27_io/objects/wchar_t/2523-2_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/2523-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/3045.cc: New test.
* testsuite/27_io/objects/wchar_t/3647.cc: New test.
* testsuite/27_io/objects/wchar_t/3_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/3_xin.in: New.
* testsuite/27_io/objects/wchar_t/4_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/4_xin.in: New.
* testsuite/27_io/objects/wchar_t/5.cc: New test.
* testsuite/27_io/objects/wchar_t/5268.cc: New test.
* testsuite/27_io/objects/wchar_t/5280_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/5280_xin.in: New.
* testsuite/27_io/objects/wchar_t/6.cc: New test.
* testsuite/27_io/objects/wchar_t/6548_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/6548_xin.in: New.
* testsuite/27_io/objects/wchar_t/6648-1_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/6648-1_xin.in: New.
* testsuite/27_io/objects/wchar_t/6648-2_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/6648-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/7.cc: New test.
* testsuite/27_io/objects/wchar_t/7744_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/7744_xin.in: New.
* testsuite/27_io/objects/wchar_t/8.cc: New test.
* testsuite/27_io/objects/wchar_t/9_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/9_xin.in: New.
* testsuite/27_io/objects/wchar_t/9520.cc: New test.
* testsuite/27_io/objects/wchar_t/9661-1.cc: New test.
* testsuite/27_io/objects/wchar_t/9661-2_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/9661-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/9662.cc: New test.
* testsuite/ext/stdiobuf_char.cc: New test.
* testsuite/ext/stdiobuf_wchar_t.cc: New test.
From-SVN: r66678
2003-05-11 12:20:57 +08:00
|
|
|
template<typename _CharT, typename _Traits>
|
|
|
|
typename basic_filebuf<_CharT, _Traits>::int_type
|
|
|
|
basic_filebuf<_CharT, _Traits>::_M_underflow(bool __bump)
|
|
|
|
{
|
|
|
|
int_type __ret = traits_type::eof();
|
|
|
|
const bool __testin = this->_M_mode & ios_base::in;
|
|
|
|
const bool __testout = this->_M_mode & ios_base::out;
|
|
|
|
|
|
|
|
if (__testin)
|
|
|
|
{
|
|
|
|
// Check for pback madness, and if so swich back to the
|
|
|
|
// normal buffers and jet outta here before expensive
|
|
|
|
// fileops happen...
|
|
|
|
if (_M_pback_init)
|
|
|
|
_M_destroy_pback();
|
|
|
|
|
|
|
|
if (this->_M_in_cur < this->_M_in_end)
|
|
|
|
{
|
|
|
|
__ret = traits_type::to_int_type(*this->_M_in_cur);
|
|
|
|
if (__bump)
|
|
|
|
_M_move_in_cur(1);
|
|
|
|
return __ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sync internal and external buffers.
|
|
|
|
// NB: __testget -> __testput as _M_buf_unified here.
|
|
|
|
if (this->_M_in_cur > this->_M_in_beg)
|
|
|
|
{
|
|
|
|
if (__testout)
|
|
|
|
_M_overflow();
|
|
|
|
else if (this->_M_in_cur != _M_filepos)
|
|
|
|
_M_file.seekoff(this->_M_in_cur - _M_filepos, ios_base::cur,
|
|
|
|
ios_base::in);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_M_buf_size)
|
|
|
|
{
|
|
|
|
streamsize __elen = 0;
|
|
|
|
streamsize __ilen = 0;
|
|
|
|
const locale __loc = this->getloc();
|
|
|
|
const __codecvt_type& __cvt = use_facet<__codecvt_type>(__loc);
|
|
|
|
if (__cvt.always_noconv())
|
|
|
|
{
|
|
|
|
__elen = _M_file.xsgetn(reinterpret_cast<char*>(this->_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;
|
|
|
|
codecvt_base::result __r;
|
|
|
|
__r = __cvt.in(_M_state_cur, __buf, __buf + __elen, __eend,
|
|
|
|
this->_M_in_beg,
|
|
|
|
this->_M_in_beg + _M_buf_size, __iend);
|
|
|
|
if (__r == codecvt_base::ok)
|
|
|
|
__ilen = __iend - this->_M_in_beg;
|
|
|
|
else if (__r == codecvt_base::noconv)
|
|
|
|
{
|
|
|
|
traits_type::copy(this->_M_in_beg,
|
|
|
|
reinterpret_cast<char_type*>(__buf),
|
|
|
|
__elen);
|
|
|
|
__ilen = __elen;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Unwind.
|
|
|
|
__ilen = 0;
|
|
|
|
_M_file.seekoff(-__elen, ios_base::cur, ios_base::in);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0 < __ilen)
|
|
|
|
{
|
|
|
|
_M_set_determinate(__ilen);
|
|
|
|
__ret = traits_type::to_int_type(*this->_M_in_cur);
|
|
|
|
if (__bump)
|
|
|
|
_M_move_in_cur(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_M_last_overflowed = false;
|
|
|
|
return __ret;
|
|
|
|
}
|
|
|
|
|
2000-10-05 19:27:02 +08:00
|
|
|
template<typename _CharT, typename _Traits>
|
2001-07-20 08:09:31 +08:00
|
|
|
typename basic_filebuf<_CharT, _Traits>::int_type
|
2000-10-05 19:27:02 +08:00
|
|
|
basic_filebuf<_CharT, _Traits>::
|
|
|
|
pbackfail(int_type __i)
|
|
|
|
{
|
|
|
|
int_type __ret = traits_type::eof();
|
According to 5.9 para 2 (second bullet) for pointers p...
2003-04-18 Paolo Carlini <pcarlini@unitus.it>
According to 5.9 para 2 (second bullet) for pointers p, q
pointing to the same type, with p == 0 and q == 0, (p < q)
is false.
* include/bits/fstream.tcc (close, overflow, _M_really_overflow,
seekoff): Remove redundant NULL pointer checks from tests
involving _M_out_* and _M_in_*, const qualify bool variables.
(showmanyc, pbackfail, _M_convert_to_external, imbue): Const
qualify bool variables.
* include/bits/streambuf.tcc (sbumpc, sputbackc, sungetc, sputc):
Remove redundant NULL pointer checks from tests involving
_M_out_* and _M_in_*, const qualify bool variables.
* include/std/std_fstream.h (sync): Likewise.
(_M_is_indeterminate): Const qualify bool variables.
* include/std/std_streambuf.h (sgetc, uflow): Remove redundant
NULL pointer checks from tests involving _M_out_* and _M_in_*,
const qualify bool variables.
(_M_in_cur_move, _M_out_cur_move, uflow): Const qualify bool
variables.
From-SVN: r65783
2003-04-18 21:55:22 +08:00
|
|
|
const bool __testin = this->_M_mode & ios_base::in;
|
2000-10-05 19:27:02 +08:00
|
|
|
|
|
|
|
if (__testin)
|
|
|
|
{
|
According to 5.9 para 2 (second bullet) for pointers p...
2003-04-18 Paolo Carlini <pcarlini@unitus.it>
According to 5.9 para 2 (second bullet) for pointers p, q
pointing to the same type, with p == 0 and q == 0, (p < q)
is false.
* include/bits/fstream.tcc (close, overflow, _M_really_overflow,
seekoff): Remove redundant NULL pointer checks from tests
involving _M_out_* and _M_in_*, const qualify bool variables.
(showmanyc, pbackfail, _M_convert_to_external, imbue): Const
qualify bool variables.
* include/bits/streambuf.tcc (sbumpc, sputbackc, sungetc, sputc):
Remove redundant NULL pointer checks from tests involving
_M_out_* and _M_in_*, const qualify bool variables.
* include/std/std_fstream.h (sync): Likewise.
(_M_is_indeterminate): Const qualify bool variables.
* include/std/std_streambuf.h (sgetc, uflow): Remove redundant
NULL pointer checks from tests involving _M_out_* and _M_in_*,
const qualify bool variables.
(_M_in_cur_move, _M_out_cur_move, uflow): Const qualify bool
variables.
From-SVN: r65783
2003-04-18 21:55:22 +08:00
|
|
|
const bool __testpb = this->_M_in_beg < this->_M_in_cur;
|
2000-10-05 19:27:02 +08:00
|
|
|
char_type __c = traits_type::to_char_type(__i);
|
According to 5.9 para 2 (second bullet) for pointers p...
2003-04-18 Paolo Carlini <pcarlini@unitus.it>
According to 5.9 para 2 (second bullet) for pointers p, q
pointing to the same type, with p == 0 and q == 0, (p < q)
is false.
* include/bits/fstream.tcc (close, overflow, _M_really_overflow,
seekoff): Remove redundant NULL pointer checks from tests
involving _M_out_* and _M_in_*, const qualify bool variables.
(showmanyc, pbackfail, _M_convert_to_external, imbue): Const
qualify bool variables.
* include/bits/streambuf.tcc (sbumpc, sputbackc, sungetc, sputc):
Remove redundant NULL pointer checks from tests involving
_M_out_* and _M_in_*, const qualify bool variables.
* include/std/std_fstream.h (sync): Likewise.
(_M_is_indeterminate): Const qualify bool variables.
* include/std/std_streambuf.h (sgetc, uflow): Remove redundant
NULL pointer checks from tests involving _M_out_* and _M_in_*,
const qualify bool variables.
(_M_in_cur_move, _M_out_cur_move, uflow): Const qualify bool
variables.
From-SVN: r65783
2003-04-18 21:55:22 +08:00
|
|
|
const bool __testeof = traits_type::eq_int_type(__i, __ret);
|
2000-10-05 19:27:02 +08:00
|
|
|
|
|
|
|
if (__testpb)
|
|
|
|
{
|
According to 5.9 para 2 (second bullet) for pointers p...
2003-04-18 Paolo Carlini <pcarlini@unitus.it>
According to 5.9 para 2 (second bullet) for pointers p, q
pointing to the same type, with p == 0 and q == 0, (p < q)
is false.
* include/bits/fstream.tcc (close, overflow, _M_really_overflow,
seekoff): Remove redundant NULL pointer checks from tests
involving _M_out_* and _M_in_*, const qualify bool variables.
(showmanyc, pbackfail, _M_convert_to_external, imbue): Const
qualify bool variables.
* include/bits/streambuf.tcc (sbumpc, sputbackc, sungetc, sputc):
Remove redundant NULL pointer checks from tests involving
_M_out_* and _M_in_*, const qualify bool variables.
* include/std/std_fstream.h (sync): Likewise.
(_M_is_indeterminate): Const qualify bool variables.
* include/std/std_streambuf.h (sgetc, uflow): Remove redundant
NULL pointer checks from tests involving _M_out_* and _M_in_*,
const qualify bool variables.
(_M_in_cur_move, _M_out_cur_move, uflow): Const qualify bool
variables.
From-SVN: r65783
2003-04-18 21:55:22 +08:00
|
|
|
const bool __testout = this->_M_mode & ios_base::out;
|
2003-04-22 05:44:44 +08:00
|
|
|
const bool __testeq = traits_type::eq(__c, this->_M_in_cur[-1]);
|
2000-10-05 19:27:02 +08:00
|
|
|
|
2003-04-26 16:31:57 +08:00
|
|
|
--this->_M_in_cur;
|
|
|
|
if (__testout)
|
|
|
|
--this->_M_out_cur;
|
2000-10-05 19:27:02 +08:00
|
|
|
// Try to put back __c into input sequence in one of three ways.
|
|
|
|
// Order these tests done in is unspecified by the standard.
|
|
|
|
if (!__testeof && __testeq)
|
2003-04-26 16:31:57 +08:00
|
|
|
__ret = __i;
|
2000-10-05 19:27:02 +08:00
|
|
|
else if (__testeof)
|
2003-04-26 16:31:57 +08:00
|
|
|
__ret = traits_type::not_eof(__i);
|
|
|
|
else
|
2000-10-05 19:27:02 +08:00
|
|
|
{
|
2003-04-28 12:54:54 +08:00
|
|
|
_M_create_pback();
|
2003-01-17 04:30:50 +08:00
|
|
|
*this->_M_in_cur = __c;
|
2000-10-05 19:27:02 +08:00
|
|
|
__ret = __i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// At the beginning of the buffer, need to make a
|
|
|
|
// putback position available.
|
2003-02-05 06:42:32 +08:00
|
|
|
// But the seek may fail (f.i., at the beginning of
|
|
|
|
// a file, see libstdc++/9439) and in that case
|
|
|
|
// we return traits_type::eof()
|
|
|
|
if (this->seekoff(-1, ios_base::cur) >= 0)
|
|
|
|
{
|
|
|
|
this->underflow();
|
|
|
|
if (!__testeof)
|
2000-10-05 19:27:02 +08:00
|
|
|
{
|
2003-02-05 06:42:32 +08:00
|
|
|
if (!traits_type::eq(__c, *this->_M_in_cur))
|
|
|
|
{
|
2003-04-28 12:54:54 +08:00
|
|
|
_M_create_pback();
|
2003-02-05 06:42:32 +08:00
|
|
|
*this->_M_in_cur = __c;
|
|
|
|
}
|
|
|
|
__ret = __i;
|
2000-10-05 19:27:02 +08:00
|
|
|
}
|
2003-02-05 06:42:32 +08:00
|
|
|
else
|
|
|
|
__ret = traits_type::not_eof(__i);
|
|
|
|
}
|
2000-10-05 19:27:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
_M_last_overflowed = false;
|
|
|
|
return __ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits>
|
2001-07-20 08:09:31 +08:00
|
|
|
typename basic_filebuf<_CharT, _Traits>::int_type
|
2000-10-05 19:27:02 +08:00
|
|
|
basic_filebuf<_CharT, _Traits>::
|
|
|
|
overflow(int_type __c)
|
|
|
|
{
|
|
|
|
int_type __ret = traits_type::eof();
|
According to 5.9 para 2 (second bullet) for pointers p...
2003-04-18 Paolo Carlini <pcarlini@unitus.it>
According to 5.9 para 2 (second bullet) for pointers p, q
pointing to the same type, with p == 0 and q == 0, (p < q)
is false.
* include/bits/fstream.tcc (close, overflow, _M_really_overflow,
seekoff): Remove redundant NULL pointer checks from tests
involving _M_out_* and _M_in_*, const qualify bool variables.
(showmanyc, pbackfail, _M_convert_to_external, imbue): Const
qualify bool variables.
* include/bits/streambuf.tcc (sbumpc, sputbackc, sungetc, sputc):
Remove redundant NULL pointer checks from tests involving
_M_out_* and _M_in_*, const qualify bool variables.
* include/std/std_fstream.h (sync): Likewise.
(_M_is_indeterminate): Const qualify bool variables.
* include/std/std_streambuf.h (sgetc, uflow): Remove redundant
NULL pointer checks from tests involving _M_out_* and _M_in_*,
const qualify bool variables.
(_M_in_cur_move, _M_out_cur_move, uflow): Const qualify bool
variables.
From-SVN: r65783
2003-04-18 21:55:22 +08:00
|
|
|
const bool __testput = this->_M_out_cur < this->_M_out_end;
|
|
|
|
const bool __testout = this->_M_mode & ios_base::out;
|
2000-10-05 19:27:02 +08:00
|
|
|
|
|
|
|
if (__testout)
|
|
|
|
{
|
2003-03-10 05:35:09 +08:00
|
|
|
if (traits_type::eq_int_type(__c, traits_type::eof()))
|
|
|
|
__ret = traits_type::not_eof(__c);
|
|
|
|
else if (__testput)
|
2000-10-05 19:27:02 +08:00
|
|
|
{
|
2003-01-17 04:30:50 +08:00
|
|
|
*this->_M_out_cur = traits_type::to_char_type(__c);
|
2003-04-28 12:54:54 +08:00
|
|
|
_M_move_out_cur(1);
|
2000-10-05 19:27:02 +08:00
|
|
|
__ret = traits_type::not_eof(__c);
|
|
|
|
}
|
|
|
|
else
|
2003-04-28 12:54:54 +08:00
|
|
|
__ret = this->_M_overflow(__c);
|
2000-10-05 19:27:02 +08:00
|
|
|
}
|
|
|
|
|
2003-04-28 12:54:54 +08:00
|
|
|
_M_last_overflowed = false; // Set in _M_overflow, below.
|
2000-10-05 19:27:02 +08:00
|
|
|
return __ret;
|
|
|
|
}
|
|
|
|
|
2002-02-08 09:34:41 +08:00
|
|
|
template<typename _CharT, typename _Traits>
|
|
|
|
void
|
|
|
|
basic_filebuf<_CharT, _Traits>::
|
|
|
|
_M_convert_to_external(_CharT* __ibuf, streamsize __ilen,
|
|
|
|
streamsize& __elen, streamsize& __plen)
|
|
|
|
{
|
|
|
|
const locale __loc = this->getloc();
|
|
|
|
const __codecvt_type& __cvt = use_facet<__codecvt_type>(__loc);
|
re PR libstdc++/7744 (streambuf::in_avail() always returns 0 (zero) for cin input stream)
2003-03-09 Paolo Carlini <pcarlini@unitus.it>
Nathan Myers <ncm@cantrip.org>
PR libstdc++/7744
* config/io/basic_file_stdio.h (__basic_file<>::xsgetn, xsputn,
seekoff, seekpos): Add a boolean parameter __stdio.
* config/io/basic_file_stdio.cc (__basic_file<>::xsgetn, xsputn,
seekoff, seekpos): If __stdio == true, use fread (fwrite, fseek/ftell,
fseek/ftell, respectively), otherwise read (write, lseek, lseek,
respectively).
* include/bits/fstream.tcc (basic_filebuf<>::_M_convert_to_external,
_M_really_overflow, seekoff): Use the boolean parameter in the calls.
* include/std/std_fstream.h (sync): Likewise.
* src/fstream.cc (basic_filebuf<>::_M_underflow_common): Likewise.
* src/ios.cc (ios_base::Init::_S_ios_create(bool)): Revert libstdc++/8399
commit involving isatty(0).
* acinclude.m4 (GLIBCPP_CHECK_UNISTD_DECL_AND_LINKAGE_1): Remove.
(GLIBCPP_CHECK_UNISTD_SUPPORT): Remove
* configure.in: Remove call.
* aclocal.m4: Regenerate.
* config.h.in: Regenerate.
* configure: Regenerate.
* testsuite/27_io/narrow_stream_objects.cc (test11): Add.
Co-Authored-By: Nathan Myers <ncm@cantrip.org>
From-SVN: r64051
2003-03-10 06:31:45 +08:00
|
|
|
|
2002-02-08 09:34:41 +08:00
|
|
|
if (__cvt.always_noconv() && __ilen)
|
|
|
|
{
|
[multiple changes]
2003-05-10 Petur Runolfsson <peturr02@ru.is>
PR libstdc++/9027
PR libstdc++/9520
PR libstdc++/10096
* include/bits/fstream.tcc (basic_file::_M_underflow): Add generic
implementation, based on old wchar_t specialization, add support
for codecvt::in() return value of codecvt_base::noconv, remove
_M_file.sys_ungetc() call.
* include/std/std_fstream.h (basic_file::underflow,
basic_file::uflow, basic_file::_M_underflow): Remove
specialization declarations, call _M_underflow from generic versions
of underflow and uflow.
* src/fstream.cc (basic_file::underflow, basic_file::uflow,
basic_file::_M_underflow): Remove specializations.
* src/Makefile.am (sources): Remove fstream.cc.
* src/Makefile.in: Regenerated.
* testsuite/27_io/basic_filebuf/underflow/10096.cc: New test.
* testsuite/27_io/basic_filebuf/underflow/char/1.cc: New test.
* testsuite/27_io/basic_filebuf/underflow/char/9027.cc: New test.
* testsuite/27_io/basic_filebuf/underflow/wchar_t/9520.cc: New test.
2003-05-10 Benjamin Kosnik <bkoz@redhat.com>
* include/ext/stdio_filebuf.h (__stdio_filebuf): Remove stack
buffer.
* config/io/basic_file_stdio.h (__basic_file::xsgetn): Remove
unbuffered bits.
(__basic_file::xsputn): Same.
(__basic_file::seekoff): Same.
(__basic_file::seekpos): Same.
(__basic_file::showmanyc): Same.
* config/io/basic_file_stdio.cc: Same.
* include/std/std_fstream.h: Same.
* include/bits/fstream.tcc: Same.
* src/fstream.cc: Same.
* testsuite/27_io/basic_filebuf/sgetn/char/1.cc (test05): Tidy.
2003-05-10 Petur Runolfsson <peturr02@ru.is>
PR libstdc++/9520
PR libstdc++/9661
PR libstdc++/9662
* include/ext/stdio_sync_filebuf.h: New file.
(basic_stdiobuf): New.
* include/Makefile.am (ext_headers): Add ext/stdio_sync_filebuf.h
* include/Makefile.in: Regenerate.
* include/bits/ios_base.h (Init::_S_create_buffers,
Init::_S_destroy_buffers): Remove declarations.
* src/globals.cc (buf_cout_sync, buf_cin_sync, buf_cerr_sync,
buf_wcout_sync, buf_wcin_sync, buf_wcerr_sync): Define.
* src/ios.cc (Init::_S_create_buffers,
Init::_S_destroy_buffers): Remove.
(Init::Init): Create and use syncronized buffers.
(ios_base::sync_with_stdio): Destroy syncronized buffers,
create and install unsyncronized buffers.
* testsuite/27_io/objects/char/10.cc: New test.
* testsuite/27_io/objects/char/9.cc: New test.
* testsuite/27_io/objects/char/9661-1.cc: New test.
* testsuite/27_io/objects/char/9661-2_xin.cc: New test.
* testsuite/27_io/objects/char/9661-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/1.cc: New test.
* testsuite/27_io/objects/wchar_t/10.cc: New test.
* testsuite/27_io/objects/wchar_t/2.cc: New test.
* testsuite/27_io/objects/wchar_t/2523-1_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/2523-1_xin.in: New.
* testsuite/27_io/objects/wchar_t/2523-2_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/2523-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/3045.cc: New test.
* testsuite/27_io/objects/wchar_t/3647.cc: New test.
* testsuite/27_io/objects/wchar_t/3_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/3_xin.in: New.
* testsuite/27_io/objects/wchar_t/4_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/4_xin.in: New.
* testsuite/27_io/objects/wchar_t/5.cc: New test.
* testsuite/27_io/objects/wchar_t/5268.cc: New test.
* testsuite/27_io/objects/wchar_t/5280_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/5280_xin.in: New.
* testsuite/27_io/objects/wchar_t/6.cc: New test.
* testsuite/27_io/objects/wchar_t/6548_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/6548_xin.in: New.
* testsuite/27_io/objects/wchar_t/6648-1_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/6648-1_xin.in: New.
* testsuite/27_io/objects/wchar_t/6648-2_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/6648-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/7.cc: New test.
* testsuite/27_io/objects/wchar_t/7744_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/7744_xin.in: New.
* testsuite/27_io/objects/wchar_t/8.cc: New test.
* testsuite/27_io/objects/wchar_t/9_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/9_xin.in: New.
* testsuite/27_io/objects/wchar_t/9520.cc: New test.
* testsuite/27_io/objects/wchar_t/9661-1.cc: New test.
* testsuite/27_io/objects/wchar_t/9661-2_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/9661-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/9662.cc: New test.
* testsuite/ext/stdiobuf_char.cc: New test.
* testsuite/ext/stdiobuf_wchar_t.cc: New test.
From-SVN: r66678
2003-05-11 12:20:57 +08:00
|
|
|
__elen += _M_file.xsputn(reinterpret_cast<char*>(__ibuf), __ilen);
|
2002-02-08 09:34:41 +08:00
|
|
|
__plen += __ilen;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Worst-case number of external bytes needed.
|
|
|
|
int __ext_multiplier = __cvt.encoding();
|
|
|
|
if (__ext_multiplier == -1 || __ext_multiplier == 0)
|
|
|
|
__ext_multiplier = sizeof(char_type);
|
|
|
|
streamsize __blen = __ilen * __ext_multiplier;
|
|
|
|
char* __buf = static_cast<char*>(__builtin_alloca(__blen));
|
|
|
|
char* __bend;
|
|
|
|
const char_type* __iend;
|
2003-04-26 08:23:18 +08:00
|
|
|
codecvt_base::result __r;
|
|
|
|
__r = __cvt.out(_M_state_cur, __ibuf, __ibuf + __ilen,
|
|
|
|
__iend, __buf, __buf + __blen, __bend);
|
|
|
|
|
2003-02-18 03:05:01 +08:00
|
|
|
if (__r == codecvt_base::ok || __r == codecvt_base::partial)
|
2002-02-08 09:34:41 +08:00
|
|
|
__blen = __bend - __buf;
|
2003-02-18 03:05:01 +08:00
|
|
|
else if (__r == codecvt_base::noconv)
|
|
|
|
{
|
2003-04-26 08:23:18 +08:00
|
|
|
// Same as the always_noconv case above.
|
2003-02-18 03:05:01 +08:00
|
|
|
__buf = reinterpret_cast<char*>(__ibuf);
|
|
|
|
__blen = __ilen;
|
|
|
|
}
|
2003-04-26 08:23:18 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// Result == error
|
|
|
|
__blen = 0;
|
|
|
|
}
|
2002-02-08 09:34:41 +08:00
|
|
|
|
|
|
|
if (__blen)
|
|
|
|
{
|
[multiple changes]
2003-05-10 Petur Runolfsson <peturr02@ru.is>
PR libstdc++/9027
PR libstdc++/9520
PR libstdc++/10096
* include/bits/fstream.tcc (basic_file::_M_underflow): Add generic
implementation, based on old wchar_t specialization, add support
for codecvt::in() return value of codecvt_base::noconv, remove
_M_file.sys_ungetc() call.
* include/std/std_fstream.h (basic_file::underflow,
basic_file::uflow, basic_file::_M_underflow): Remove
specialization declarations, call _M_underflow from generic versions
of underflow and uflow.
* src/fstream.cc (basic_file::underflow, basic_file::uflow,
basic_file::_M_underflow): Remove specializations.
* src/Makefile.am (sources): Remove fstream.cc.
* src/Makefile.in: Regenerated.
* testsuite/27_io/basic_filebuf/underflow/10096.cc: New test.
* testsuite/27_io/basic_filebuf/underflow/char/1.cc: New test.
* testsuite/27_io/basic_filebuf/underflow/char/9027.cc: New test.
* testsuite/27_io/basic_filebuf/underflow/wchar_t/9520.cc: New test.
2003-05-10 Benjamin Kosnik <bkoz@redhat.com>
* include/ext/stdio_filebuf.h (__stdio_filebuf): Remove stack
buffer.
* config/io/basic_file_stdio.h (__basic_file::xsgetn): Remove
unbuffered bits.
(__basic_file::xsputn): Same.
(__basic_file::seekoff): Same.
(__basic_file::seekpos): Same.
(__basic_file::showmanyc): Same.
* config/io/basic_file_stdio.cc: Same.
* include/std/std_fstream.h: Same.
* include/bits/fstream.tcc: Same.
* src/fstream.cc: Same.
* testsuite/27_io/basic_filebuf/sgetn/char/1.cc (test05): Tidy.
2003-05-10 Petur Runolfsson <peturr02@ru.is>
PR libstdc++/9520
PR libstdc++/9661
PR libstdc++/9662
* include/ext/stdio_sync_filebuf.h: New file.
(basic_stdiobuf): New.
* include/Makefile.am (ext_headers): Add ext/stdio_sync_filebuf.h
* include/Makefile.in: Regenerate.
* include/bits/ios_base.h (Init::_S_create_buffers,
Init::_S_destroy_buffers): Remove declarations.
* src/globals.cc (buf_cout_sync, buf_cin_sync, buf_cerr_sync,
buf_wcout_sync, buf_wcin_sync, buf_wcerr_sync): Define.
* src/ios.cc (Init::_S_create_buffers,
Init::_S_destroy_buffers): Remove.
(Init::Init): Create and use syncronized buffers.
(ios_base::sync_with_stdio): Destroy syncronized buffers,
create and install unsyncronized buffers.
* testsuite/27_io/objects/char/10.cc: New test.
* testsuite/27_io/objects/char/9.cc: New test.
* testsuite/27_io/objects/char/9661-1.cc: New test.
* testsuite/27_io/objects/char/9661-2_xin.cc: New test.
* testsuite/27_io/objects/char/9661-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/1.cc: New test.
* testsuite/27_io/objects/wchar_t/10.cc: New test.
* testsuite/27_io/objects/wchar_t/2.cc: New test.
* testsuite/27_io/objects/wchar_t/2523-1_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/2523-1_xin.in: New.
* testsuite/27_io/objects/wchar_t/2523-2_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/2523-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/3045.cc: New test.
* testsuite/27_io/objects/wchar_t/3647.cc: New test.
* testsuite/27_io/objects/wchar_t/3_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/3_xin.in: New.
* testsuite/27_io/objects/wchar_t/4_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/4_xin.in: New.
* testsuite/27_io/objects/wchar_t/5.cc: New test.
* testsuite/27_io/objects/wchar_t/5268.cc: New test.
* testsuite/27_io/objects/wchar_t/5280_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/5280_xin.in: New.
* testsuite/27_io/objects/wchar_t/6.cc: New test.
* testsuite/27_io/objects/wchar_t/6548_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/6548_xin.in: New.
* testsuite/27_io/objects/wchar_t/6648-1_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/6648-1_xin.in: New.
* testsuite/27_io/objects/wchar_t/6648-2_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/6648-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/7.cc: New test.
* testsuite/27_io/objects/wchar_t/7744_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/7744_xin.in: New.
* testsuite/27_io/objects/wchar_t/8.cc: New test.
* testsuite/27_io/objects/wchar_t/9_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/9_xin.in: New.
* testsuite/27_io/objects/wchar_t/9520.cc: New test.
* testsuite/27_io/objects/wchar_t/9661-1.cc: New test.
* testsuite/27_io/objects/wchar_t/9661-2_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/9661-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/9662.cc: New test.
* testsuite/ext/stdiobuf_char.cc: New test.
* testsuite/ext/stdiobuf_wchar_t.cc: New test.
From-SVN: r66678
2003-05-11 12:20:57 +08:00
|
|
|
__elen += _M_file.xsputn(__buf, __blen);
|
2002-02-08 09:34:41 +08:00
|
|
|
__plen += __blen;
|
|
|
|
}
|
2003-04-26 08:23:18 +08:00
|
|
|
|
2002-02-08 09:34:41 +08:00
|
|
|
// Try once more for partial conversions.
|
|
|
|
if (__r == codecvt_base::partial)
|
|
|
|
{
|
|
|
|
const char_type* __iresume = __iend;
|
PR libstdc++/9404, PR libstdc++/9701 (partial)
2003-02-24 Paolo Carlini <pcarlini@unitus.it>
Nathan Myers <ncm@cantrip.org>
PR libstdc++/9404, PR libstdc++/9701 (partial)
(aka pptr == epptr implies overflow)
* include/bits/fstream.tcc (_M_allocate_internal_buffer):
Consistently, _M_out_end points to the end of the buffer just
created.
(overflow): Tweak to use _M_out_buf_size().
(_M_convert_to_external): The role of the old _M_out_end is
now played by _M_out_lim.
(_M_really_overflow): Likewise.
(seekoff): Likewise.
(setbuf): _M_out_end points to the end of the external buffer.
* include/bits/sstream.tcc (overflow): Rewrote, taking into
account the resolution of DR 169 (TC).
(seekoff): Use _M_string.capacity(); ios_base::end is now _M_out_lim.
(seekpos): Use _M_string.capacity(); tweak.
* include/bits/streambuf.tcc (sputc, xsputn): Remove comments.
* include/std/std_fstream.h (sync): The role of the old
_M_out_end is now played by _M_out_lim.
(_M_set_indeterminate): Use _M_set_determinate.
(_M_set_determinate): _M_out_end is now _M_out_lim.
(_M_is_indeterminate): Likewise.
* include/std/std_sstream.h (str()): _M_out_end is now _M_out_lim.
(_M_stringbuf_init): Don't set _M_buf_size, unused for sstreams,
which have the information readily available as _M_string.capacity();
for ate and app modes, pass the string size to _M_really_sync.
(_M_really_sync): Consistently set _M_out_end and _M_out_lim, to
point to the end of the buffer (i.e., epptr) and to the string end,
respectively.
* include/std/std_streambuf.h: tweak comments, add _M_out_lim,
which points to the right limit of the used put area.
(_M_out_cur_move): The role of the old _M_out_end is now played
by _M_out_lim.
(_M_out_buf_size): Simplify: now (when _M_out_cur) return simply
_M_out_end - _M_out_cur (i.e., pptr), _very_ close to the letter
of the standard.
(basic_streambuf()): Initialize _M_out_lim too.
* testsuite/27_io/filebuf_virtuals.cc (test10): Trivial tweak.
* testsuite/27_io/filebuf_virtuals.cc (test11): Add.
* testsuite/27_io/stringbuf_virtuals.cc (test09): Add.
Co-Authored-By: Nathan Myers <ncm@cantrip.org>
From-SVN: r63367
2003-02-25 02:22:58 +08:00
|
|
|
streamsize __rlen = this->_M_out_lim - __iend;
|
2002-02-08 09:34:41 +08:00
|
|
|
__r = __cvt.out(_M_state_cur, __iresume, __iresume + __rlen,
|
|
|
|
__iend, __buf, __buf + __blen, __bend);
|
|
|
|
if (__r != codecvt_base::error)
|
|
|
|
{
|
2003-04-26 08:23:18 +08:00
|
|
|
__rlen = __bend - __buf;
|
[multiple changes]
2003-05-10 Petur Runolfsson <peturr02@ru.is>
PR libstdc++/9027
PR libstdc++/9520
PR libstdc++/10096
* include/bits/fstream.tcc (basic_file::_M_underflow): Add generic
implementation, based on old wchar_t specialization, add support
for codecvt::in() return value of codecvt_base::noconv, remove
_M_file.sys_ungetc() call.
* include/std/std_fstream.h (basic_file::underflow,
basic_file::uflow, basic_file::_M_underflow): Remove
specialization declarations, call _M_underflow from generic versions
of underflow and uflow.
* src/fstream.cc (basic_file::underflow, basic_file::uflow,
basic_file::_M_underflow): Remove specializations.
* src/Makefile.am (sources): Remove fstream.cc.
* src/Makefile.in: Regenerated.
* testsuite/27_io/basic_filebuf/underflow/10096.cc: New test.
* testsuite/27_io/basic_filebuf/underflow/char/1.cc: New test.
* testsuite/27_io/basic_filebuf/underflow/char/9027.cc: New test.
* testsuite/27_io/basic_filebuf/underflow/wchar_t/9520.cc: New test.
2003-05-10 Benjamin Kosnik <bkoz@redhat.com>
* include/ext/stdio_filebuf.h (__stdio_filebuf): Remove stack
buffer.
* config/io/basic_file_stdio.h (__basic_file::xsgetn): Remove
unbuffered bits.
(__basic_file::xsputn): Same.
(__basic_file::seekoff): Same.
(__basic_file::seekpos): Same.
(__basic_file::showmanyc): Same.
* config/io/basic_file_stdio.cc: Same.
* include/std/std_fstream.h: Same.
* include/bits/fstream.tcc: Same.
* src/fstream.cc: Same.
* testsuite/27_io/basic_filebuf/sgetn/char/1.cc (test05): Tidy.
2003-05-10 Petur Runolfsson <peturr02@ru.is>
PR libstdc++/9520
PR libstdc++/9661
PR libstdc++/9662
* include/ext/stdio_sync_filebuf.h: New file.
(basic_stdiobuf): New.
* include/Makefile.am (ext_headers): Add ext/stdio_sync_filebuf.h
* include/Makefile.in: Regenerate.
* include/bits/ios_base.h (Init::_S_create_buffers,
Init::_S_destroy_buffers): Remove declarations.
* src/globals.cc (buf_cout_sync, buf_cin_sync, buf_cerr_sync,
buf_wcout_sync, buf_wcin_sync, buf_wcerr_sync): Define.
* src/ios.cc (Init::_S_create_buffers,
Init::_S_destroy_buffers): Remove.
(Init::Init): Create and use syncronized buffers.
(ios_base::sync_with_stdio): Destroy syncronized buffers,
create and install unsyncronized buffers.
* testsuite/27_io/objects/char/10.cc: New test.
* testsuite/27_io/objects/char/9.cc: New test.
* testsuite/27_io/objects/char/9661-1.cc: New test.
* testsuite/27_io/objects/char/9661-2_xin.cc: New test.
* testsuite/27_io/objects/char/9661-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/1.cc: New test.
* testsuite/27_io/objects/wchar_t/10.cc: New test.
* testsuite/27_io/objects/wchar_t/2.cc: New test.
* testsuite/27_io/objects/wchar_t/2523-1_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/2523-1_xin.in: New.
* testsuite/27_io/objects/wchar_t/2523-2_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/2523-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/3045.cc: New test.
* testsuite/27_io/objects/wchar_t/3647.cc: New test.
* testsuite/27_io/objects/wchar_t/3_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/3_xin.in: New.
* testsuite/27_io/objects/wchar_t/4_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/4_xin.in: New.
* testsuite/27_io/objects/wchar_t/5.cc: New test.
* testsuite/27_io/objects/wchar_t/5268.cc: New test.
* testsuite/27_io/objects/wchar_t/5280_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/5280_xin.in: New.
* testsuite/27_io/objects/wchar_t/6.cc: New test.
* testsuite/27_io/objects/wchar_t/6548_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/6548_xin.in: New.
* testsuite/27_io/objects/wchar_t/6648-1_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/6648-1_xin.in: New.
* testsuite/27_io/objects/wchar_t/6648-2_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/6648-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/7.cc: New test.
* testsuite/27_io/objects/wchar_t/7744_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/7744_xin.in: New.
* testsuite/27_io/objects/wchar_t/8.cc: New test.
* testsuite/27_io/objects/wchar_t/9_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/9_xin.in: New.
* testsuite/27_io/objects/wchar_t/9520.cc: New test.
* testsuite/27_io/objects/wchar_t/9661-1.cc: New test.
* testsuite/27_io/objects/wchar_t/9661-2_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/9661-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/9662.cc: New test.
* testsuite/ext/stdiobuf_char.cc: New test.
* testsuite/ext/stdiobuf_wchar_t.cc: New test.
From-SVN: r66678
2003-05-11 12:20:57 +08:00
|
|
|
__elen += _M_file.xsputn(__buf, __rlen);
|
2002-02-08 09:34:41 +08:00
|
|
|
__plen += __rlen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-10-05 19:27:02 +08:00
|
|
|
template<typename _CharT, typename _Traits>
|
2001-07-20 08:09:31 +08:00
|
|
|
typename basic_filebuf<_CharT, _Traits>::int_type
|
2000-10-05 19:27:02 +08:00
|
|
|
basic_filebuf<_CharT, _Traits>::
|
2003-04-28 12:54:54 +08:00
|
|
|
_M_overflow(int_type __c)
|
2000-10-05 19:27:02 +08:00
|
|
|
{
|
|
|
|
int_type __ret = traits_type::eof();
|
According to 5.9 para 2 (second bullet) for pointers p...
2003-04-18 Paolo Carlini <pcarlini@unitus.it>
According to 5.9 para 2 (second bullet) for pointers p, q
pointing to the same type, with p == 0 and q == 0, (p < q)
is false.
* include/bits/fstream.tcc (close, overflow, _M_really_overflow,
seekoff): Remove redundant NULL pointer checks from tests
involving _M_out_* and _M_in_*, const qualify bool variables.
(showmanyc, pbackfail, _M_convert_to_external, imbue): Const
qualify bool variables.
* include/bits/streambuf.tcc (sbumpc, sputbackc, sungetc, sputc):
Remove redundant NULL pointer checks from tests involving
_M_out_* and _M_in_*, const qualify bool variables.
* include/std/std_fstream.h (sync): Likewise.
(_M_is_indeterminate): Const qualify bool variables.
* include/std/std_streambuf.h (sgetc, uflow): Remove redundant
NULL pointer checks from tests involving _M_out_* and _M_in_*,
const qualify bool variables.
(_M_in_cur_move, _M_out_cur_move, uflow): Const qualify bool
variables.
From-SVN: r65783
2003-04-18 21:55:22 +08:00
|
|
|
const bool __testput = this->_M_out_beg < this->_M_out_lim;
|
|
|
|
const bool __testunbuffered = _M_file.is_open() && !this->_M_buf_size;
|
2001-03-27 11:48:17 +08:00
|
|
|
|
|
|
|
if (__testput || __testunbuffered)
|
2000-10-05 19:27:02 +08:00
|
|
|
{
|
2002-02-08 09:34:41 +08:00
|
|
|
// Sizes of external and pending output.
|
|
|
|
streamsize __elen = 0;
|
|
|
|
streamsize __plen = 0;
|
|
|
|
|
2002-04-23 04:28:05 +08:00
|
|
|
// Need to restore current position. The position of the external
|
|
|
|
// byte sequence (_M_file) corresponds to _M_filepos, and we need
|
|
|
|
// to move it to _M_out_beg for the write.
|
2003-01-17 04:30:50 +08:00
|
|
|
if (_M_filepos && _M_filepos != this->_M_out_beg)
|
2002-04-23 04:28:05 +08:00
|
|
|
{
|
2003-01-17 04:30:50 +08:00
|
|
|
off_type __off = this->_M_out_beg - _M_filepos;
|
[multiple changes]
2003-05-10 Petur Runolfsson <peturr02@ru.is>
PR libstdc++/9027
PR libstdc++/9520
PR libstdc++/10096
* include/bits/fstream.tcc (basic_file::_M_underflow): Add generic
implementation, based on old wchar_t specialization, add support
for codecvt::in() return value of codecvt_base::noconv, remove
_M_file.sys_ungetc() call.
* include/std/std_fstream.h (basic_file::underflow,
basic_file::uflow, basic_file::_M_underflow): Remove
specialization declarations, call _M_underflow from generic versions
of underflow and uflow.
* src/fstream.cc (basic_file::underflow, basic_file::uflow,
basic_file::_M_underflow): Remove specializations.
* src/Makefile.am (sources): Remove fstream.cc.
* src/Makefile.in: Regenerated.
* testsuite/27_io/basic_filebuf/underflow/10096.cc: New test.
* testsuite/27_io/basic_filebuf/underflow/char/1.cc: New test.
* testsuite/27_io/basic_filebuf/underflow/char/9027.cc: New test.
* testsuite/27_io/basic_filebuf/underflow/wchar_t/9520.cc: New test.
2003-05-10 Benjamin Kosnik <bkoz@redhat.com>
* include/ext/stdio_filebuf.h (__stdio_filebuf): Remove stack
buffer.
* config/io/basic_file_stdio.h (__basic_file::xsgetn): Remove
unbuffered bits.
(__basic_file::xsputn): Same.
(__basic_file::seekoff): Same.
(__basic_file::seekpos): Same.
(__basic_file::showmanyc): Same.
* config/io/basic_file_stdio.cc: Same.
* include/std/std_fstream.h: Same.
* include/bits/fstream.tcc: Same.
* src/fstream.cc: Same.
* testsuite/27_io/basic_filebuf/sgetn/char/1.cc (test05): Tidy.
2003-05-10 Petur Runolfsson <peturr02@ru.is>
PR libstdc++/9520
PR libstdc++/9661
PR libstdc++/9662
* include/ext/stdio_sync_filebuf.h: New file.
(basic_stdiobuf): New.
* include/Makefile.am (ext_headers): Add ext/stdio_sync_filebuf.h
* include/Makefile.in: Regenerate.
* include/bits/ios_base.h (Init::_S_create_buffers,
Init::_S_destroy_buffers): Remove declarations.
* src/globals.cc (buf_cout_sync, buf_cin_sync, buf_cerr_sync,
buf_wcout_sync, buf_wcin_sync, buf_wcerr_sync): Define.
* src/ios.cc (Init::_S_create_buffers,
Init::_S_destroy_buffers): Remove.
(Init::Init): Create and use syncronized buffers.
(ios_base::sync_with_stdio): Destroy syncronized buffers,
create and install unsyncronized buffers.
* testsuite/27_io/objects/char/10.cc: New test.
* testsuite/27_io/objects/char/9.cc: New test.
* testsuite/27_io/objects/char/9661-1.cc: New test.
* testsuite/27_io/objects/char/9661-2_xin.cc: New test.
* testsuite/27_io/objects/char/9661-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/1.cc: New test.
* testsuite/27_io/objects/wchar_t/10.cc: New test.
* testsuite/27_io/objects/wchar_t/2.cc: New test.
* testsuite/27_io/objects/wchar_t/2523-1_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/2523-1_xin.in: New.
* testsuite/27_io/objects/wchar_t/2523-2_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/2523-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/3045.cc: New test.
* testsuite/27_io/objects/wchar_t/3647.cc: New test.
* testsuite/27_io/objects/wchar_t/3_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/3_xin.in: New.
* testsuite/27_io/objects/wchar_t/4_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/4_xin.in: New.
* testsuite/27_io/objects/wchar_t/5.cc: New test.
* testsuite/27_io/objects/wchar_t/5268.cc: New test.
* testsuite/27_io/objects/wchar_t/5280_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/5280_xin.in: New.
* testsuite/27_io/objects/wchar_t/6.cc: New test.
* testsuite/27_io/objects/wchar_t/6548_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/6548_xin.in: New.
* testsuite/27_io/objects/wchar_t/6648-1_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/6648-1_xin.in: New.
* testsuite/27_io/objects/wchar_t/6648-2_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/6648-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/7.cc: New test.
* testsuite/27_io/objects/wchar_t/7744_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/7744_xin.in: New.
* testsuite/27_io/objects/wchar_t/8.cc: New test.
* testsuite/27_io/objects/wchar_t/9_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/9_xin.in: New.
* testsuite/27_io/objects/wchar_t/9520.cc: New test.
* testsuite/27_io/objects/wchar_t/9661-1.cc: New test.
* testsuite/27_io/objects/wchar_t/9661-2_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/9661-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/9662.cc: New test.
* testsuite/ext/stdiobuf_char.cc: New test.
* testsuite/ext/stdiobuf_wchar_t.cc: New test.
From-SVN: r66678
2003-05-11 12:20:57 +08:00
|
|
|
_M_file.seekoff(__off, ios_base::cur);
|
2002-04-23 04:28:05 +08:00
|
|
|
}
|
|
|
|
|
2002-02-08 09:34:41 +08:00
|
|
|
// Convert internal buffer to external representation, output.
|
|
|
|
// NB: In the unbuffered case, no internal buffer exists.
|
|
|
|
if (!__testunbuffered)
|
2003-01-17 04:30:50 +08:00
|
|
|
_M_convert_to_external(this->_M_out_beg,
|
PR libstdc++/9404, PR libstdc++/9701 (partial)
2003-02-24 Paolo Carlini <pcarlini@unitus.it>
Nathan Myers <ncm@cantrip.org>
PR libstdc++/9404, PR libstdc++/9701 (partial)
(aka pptr == epptr implies overflow)
* include/bits/fstream.tcc (_M_allocate_internal_buffer):
Consistently, _M_out_end points to the end of the buffer just
created.
(overflow): Tweak to use _M_out_buf_size().
(_M_convert_to_external): The role of the old _M_out_end is
now played by _M_out_lim.
(_M_really_overflow): Likewise.
(seekoff): Likewise.
(setbuf): _M_out_end points to the end of the external buffer.
* include/bits/sstream.tcc (overflow): Rewrote, taking into
account the resolution of DR 169 (TC).
(seekoff): Use _M_string.capacity(); ios_base::end is now _M_out_lim.
(seekpos): Use _M_string.capacity(); tweak.
* include/bits/streambuf.tcc (sputc, xsputn): Remove comments.
* include/std/std_fstream.h (sync): The role of the old
_M_out_end is now played by _M_out_lim.
(_M_set_indeterminate): Use _M_set_determinate.
(_M_set_determinate): _M_out_end is now _M_out_lim.
(_M_is_indeterminate): Likewise.
* include/std/std_sstream.h (str()): _M_out_end is now _M_out_lim.
(_M_stringbuf_init): Don't set _M_buf_size, unused for sstreams,
which have the information readily available as _M_string.capacity();
for ate and app modes, pass the string size to _M_really_sync.
(_M_really_sync): Consistently set _M_out_end and _M_out_lim, to
point to the end of the buffer (i.e., epptr) and to the string end,
respectively.
* include/std/std_streambuf.h: tweak comments, add _M_out_lim,
which points to the right limit of the used put area.
(_M_out_cur_move): The role of the old _M_out_end is now played
by _M_out_lim.
(_M_out_buf_size): Simplify: now (when _M_out_cur) return simply
_M_out_end - _M_out_cur (i.e., pptr), _very_ close to the letter
of the standard.
(basic_streambuf()): Initialize _M_out_lim too.
* testsuite/27_io/filebuf_virtuals.cc (test10): Trivial tweak.
* testsuite/27_io/filebuf_virtuals.cc (test11): Add.
* testsuite/27_io/stringbuf_virtuals.cc (test09): Add.
Co-Authored-By: Nathan Myers <ncm@cantrip.org>
From-SVN: r63367
2003-02-25 02:22:58 +08:00
|
|
|
this->_M_out_lim - this->_M_out_beg,
|
2002-02-08 09:34:41 +08:00
|
|
|
__elen, __plen);
|
|
|
|
|
2003-03-08 06:06:28 +08:00
|
|
|
// Checks for codecvt.out failures and _M_file.xsputn failures,
|
|
|
|
// respectively, inside _M_convert_to_external.
|
|
|
|
if (__testunbuffered || (__elen && __elen == __plen))
|
2000-10-05 19:27:02 +08:00
|
|
|
{
|
2003-03-08 06:06:28 +08:00
|
|
|
// Convert pending sequence to external representation, output.
|
|
|
|
// If eof, then just attempt sync.
|
|
|
|
if (!traits_type::eq_int_type(__c, traits_type::eof()))
|
|
|
|
{
|
|
|
|
char_type __pending = traits_type::to_char_type(__c);
|
|
|
|
_M_convert_to_external(&__pending, 1, __elen, __plen);
|
2001-03-27 11:48:17 +08:00
|
|
|
|
2003-04-26 08:23:18 +08:00
|
|
|
// User code must flush when switching modes (thus
|
|
|
|
// don't sync).
|
2003-03-08 06:06:28 +08:00
|
|
|
if (__elen == __plen && __elen)
|
|
|
|
{
|
|
|
|
_M_set_indeterminate();
|
|
|
|
__ret = traits_type::not_eof(__c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!_M_file.sync())
|
2002-04-24 08:33:28 +08:00
|
|
|
{
|
|
|
|
_M_set_indeterminate();
|
|
|
|
__ret = traits_type::not_eof(__c);
|
|
|
|
}
|
|
|
|
}
|
2003-03-08 06:06:28 +08:00
|
|
|
}
|
2000-10-05 19:27:02 +08:00
|
|
|
_M_last_overflowed = true;
|
|
|
|
return __ret;
|
|
|
|
}
|
|
|
|
|
2001-05-23 02:48:19 +08:00
|
|
|
template<typename _CharT, typename _Traits>
|
2001-07-20 08:09:31 +08:00
|
|
|
typename basic_filebuf<_CharT, _Traits>::__streambuf_type*
|
2001-05-23 02:48:19 +08:00
|
|
|
basic_filebuf<_CharT, _Traits>::
|
|
|
|
setbuf(char_type* __s, streamsize __n)
|
|
|
|
{
|
|
|
|
if (!this->is_open() && __s == 0 && __n == 0)
|
2003-04-13 03:21:35 +08:00
|
|
|
this->_M_buf_size = 0;
|
2001-05-23 02:48:19 +08:00
|
|
|
else if (__s && __n)
|
|
|
|
{
|
|
|
|
// This is implementation-defined behavior, and assumes
|
|
|
|
// that an external char_type array of length (__s + __n)
|
|
|
|
// exists and has been pre-allocated. If this is not the
|
|
|
|
// case, things will quickly blow up.
|
PR libstdc++/9404, PR libstdc++/9701 (partial)
2003-02-24 Paolo Carlini <pcarlini@unitus.it>
Nathan Myers <ncm@cantrip.org>
PR libstdc++/9404, PR libstdc++/9701 (partial)
(aka pptr == epptr implies overflow)
* include/bits/fstream.tcc (_M_allocate_internal_buffer):
Consistently, _M_out_end points to the end of the buffer just
created.
(overflow): Tweak to use _M_out_buf_size().
(_M_convert_to_external): The role of the old _M_out_end is
now played by _M_out_lim.
(_M_really_overflow): Likewise.
(seekoff): Likewise.
(setbuf): _M_out_end points to the end of the external buffer.
* include/bits/sstream.tcc (overflow): Rewrote, taking into
account the resolution of DR 169 (TC).
(seekoff): Use _M_string.capacity(); ios_base::end is now _M_out_lim.
(seekpos): Use _M_string.capacity(); tweak.
* include/bits/streambuf.tcc (sputc, xsputn): Remove comments.
* include/std/std_fstream.h (sync): The role of the old
_M_out_end is now played by _M_out_lim.
(_M_set_indeterminate): Use _M_set_determinate.
(_M_set_determinate): _M_out_end is now _M_out_lim.
(_M_is_indeterminate): Likewise.
* include/std/std_sstream.h (str()): _M_out_end is now _M_out_lim.
(_M_stringbuf_init): Don't set _M_buf_size, unused for sstreams,
which have the information readily available as _M_string.capacity();
for ate and app modes, pass the string size to _M_really_sync.
(_M_really_sync): Consistently set _M_out_end and _M_out_lim, to
point to the end of the buffer (i.e., epptr) and to the string end,
respectively.
* include/std/std_streambuf.h: tweak comments, add _M_out_lim,
which points to the right limit of the used put area.
(_M_out_cur_move): The role of the old _M_out_end is now played
by _M_out_lim.
(_M_out_buf_size): Simplify: now (when _M_out_cur) return simply
_M_out_end - _M_out_cur (i.e., pptr), _very_ close to the letter
of the standard.
(basic_streambuf()): Initialize _M_out_lim too.
* testsuite/27_io/filebuf_virtuals.cc (test10): Trivial tweak.
* testsuite/27_io/filebuf_virtuals.cc (test11): Add.
* testsuite/27_io/stringbuf_virtuals.cc (test09): Add.
Co-Authored-By: Nathan Myers <ncm@cantrip.org>
From-SVN: r63367
2003-02-25 02:22:58 +08:00
|
|
|
|
2001-05-23 02:48:19 +08:00
|
|
|
// Step 1: Destroy the current internal array.
|
|
|
|
_M_destroy_internal_buffer();
|
|
|
|
|
|
|
|
// Step 2: Use the external array.
|
2003-01-17 04:30:50 +08:00
|
|
|
this->_M_buf = __s;
|
2003-04-13 03:21:35 +08:00
|
|
|
this->_M_buf_size = __n;
|
2001-05-23 02:48:19 +08:00
|
|
|
_M_set_indeterminate();
|
|
|
|
}
|
|
|
|
_M_last_overflowed = false;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2000-10-05 19:27:02 +08:00
|
|
|
template<typename _CharT, typename _Traits>
|
2001-07-20 08:09:31 +08:00
|
|
|
typename basic_filebuf<_CharT, _Traits>::pos_type
|
2000-10-05 19:27:02 +08:00
|
|
|
basic_filebuf<_CharT, _Traits>::
|
|
|
|
seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __mode)
|
|
|
|
{
|
|
|
|
pos_type __ret = pos_type(off_type(-1));
|
According to 5.9 para 2 (second bullet) for pointers p...
2003-04-18 Paolo Carlini <pcarlini@unitus.it>
According to 5.9 para 2 (second bullet) for pointers p, q
pointing to the same type, with p == 0 and q == 0, (p < q)
is false.
* include/bits/fstream.tcc (close, overflow, _M_really_overflow,
seekoff): Remove redundant NULL pointer checks from tests
involving _M_out_* and _M_in_*, const qualify bool variables.
(showmanyc, pbackfail, _M_convert_to_external, imbue): Const
qualify bool variables.
* include/bits/streambuf.tcc (sbumpc, sputbackc, sungetc, sputc):
Remove redundant NULL pointer checks from tests involving
_M_out_* and _M_in_*, const qualify bool variables.
* include/std/std_fstream.h (sync): Likewise.
(_M_is_indeterminate): Const qualify bool variables.
* include/std/std_streambuf.h (sgetc, uflow): Remove redundant
NULL pointer checks from tests involving _M_out_* and _M_in_*,
const qualify bool variables.
(_M_in_cur_move, _M_out_cur_move, uflow): Const qualify bool
variables.
From-SVN: r65783
2003-04-18 21:55:22 +08:00
|
|
|
const bool __testin = (ios_base::in & this->_M_mode & __mode) != 0;
|
|
|
|
const bool __testout = (ios_base::out & this->_M_mode & __mode) != 0;
|
re PR libstdc++/7744 (streambuf::in_avail() always returns 0 (zero) for cin input stream)
2003-03-09 Paolo Carlini <pcarlini@unitus.it>
Nathan Myers <ncm@cantrip.org>
PR libstdc++/7744
* config/io/basic_file_stdio.h (__basic_file<>::xsgetn, xsputn,
seekoff, seekpos): Add a boolean parameter __stdio.
* config/io/basic_file_stdio.cc (__basic_file<>::xsgetn, xsputn,
seekoff, seekpos): If __stdio == true, use fread (fwrite, fseek/ftell,
fseek/ftell, respectively), otherwise read (write, lseek, lseek,
respectively).
* include/bits/fstream.tcc (basic_filebuf<>::_M_convert_to_external,
_M_really_overflow, seekoff): Use the boolean parameter in the calls.
* include/std/std_fstream.h (sync): Likewise.
* src/fstream.cc (basic_filebuf<>::_M_underflow_common): Likewise.
* src/ios.cc (ios_base::Init::_S_ios_create(bool)): Revert libstdc++/8399
commit involving isatty(0).
* acinclude.m4 (GLIBCPP_CHECK_UNISTD_DECL_AND_LINKAGE_1): Remove.
(GLIBCPP_CHECK_UNISTD_SUPPORT): Remove
* configure.in: Remove call.
* aclocal.m4: Regenerate.
* config.h.in: Regenerate.
* configure: Regenerate.
* testsuite/27_io/narrow_stream_objects.cc (test11): Add.
Co-Authored-By: Nathan Myers <ncm@cantrip.org>
From-SVN: r64051
2003-03-10 06:31:45 +08:00
|
|
|
|
2003-04-26 08:23:18 +08:00
|
|
|
int __width = 0;
|
|
|
|
if (has_facet<__codecvt_type>(this->_M_buf_locale))
|
|
|
|
__width = use_facet<__codecvt_type>(this->_M_buf_locale).encoding();
|
2000-10-05 19:27:02 +08:00
|
|
|
if (__width < 0)
|
|
|
|
__width = 0;
|
2003-04-26 08:23:18 +08:00
|
|
|
|
|
|
|
const bool __testfail = __off != 0 && __width <= 0;
|
2002-04-09 16:48:33 +08:00
|
|
|
if (this->is_open() && !__testfail && (__testin || __testout))
|
2000-10-05 19:27:02 +08:00
|
|
|
{
|
|
|
|
// Ditch any pback buffers to avoid confusion.
|
2003-04-28 12:54:54 +08:00
|
|
|
_M_destroy_pback();
|
2000-10-05 19:27:02 +08:00
|
|
|
|
|
|
|
if (__way != ios_base::cur || __off != 0)
|
|
|
|
{
|
|
|
|
off_type __computed_off = __width * __off;
|
|
|
|
|
According to 5.9 para 2 (second bullet) for pointers p...
2003-04-18 Paolo Carlini <pcarlini@unitus.it>
According to 5.9 para 2 (second bullet) for pointers p, q
pointing to the same type, with p == 0 and q == 0, (p < q)
is false.
* include/bits/fstream.tcc (close, overflow, _M_really_overflow,
seekoff): Remove redundant NULL pointer checks from tests
involving _M_out_* and _M_in_*, const qualify bool variables.
(showmanyc, pbackfail, _M_convert_to_external, imbue): Const
qualify bool variables.
* include/bits/streambuf.tcc (sbumpc, sputbackc, sungetc, sputc):
Remove redundant NULL pointer checks from tests involving
_M_out_* and _M_in_*, const qualify bool variables.
* include/std/std_fstream.h (sync): Likewise.
(_M_is_indeterminate): Const qualify bool variables.
* include/std/std_streambuf.h (sgetc, uflow): Remove redundant
NULL pointer checks from tests involving _M_out_* and _M_in_*,
const qualify bool variables.
(_M_in_cur_move, _M_out_cur_move, uflow): Const qualify bool
variables.
From-SVN: r65783
2003-04-18 21:55:22 +08:00
|
|
|
const bool __testget = this->_M_in_beg < this->_M_in_end;
|
|
|
|
const bool __testput = this->_M_out_beg < this->_M_out_lim;
|
2000-10-05 19:27:02 +08:00
|
|
|
// Sync the internal and external streams.
|
|
|
|
// out
|
|
|
|
if (__testput || _M_last_overflowed)
|
|
|
|
{
|
|
|
|
// Part one: update the output sequence.
|
|
|
|
this->sync();
|
|
|
|
// Part two: output unshift sequence.
|
|
|
|
_M_output_unshift();
|
|
|
|
}
|
|
|
|
//in
|
|
|
|
else if (__testget && __way == ios_base::cur)
|
2003-01-17 04:30:50 +08:00
|
|
|
__computed_off += this->_M_in_cur - _M_filepos;
|
2003-02-05 06:42:32 +08:00
|
|
|
|
|
|
|
// Return pos_type(off_type(-1)) in case of failure.
|
[multiple changes]
2003-05-10 Petur Runolfsson <peturr02@ru.is>
PR libstdc++/9027
PR libstdc++/9520
PR libstdc++/10096
* include/bits/fstream.tcc (basic_file::_M_underflow): Add generic
implementation, based on old wchar_t specialization, add support
for codecvt::in() return value of codecvt_base::noconv, remove
_M_file.sys_ungetc() call.
* include/std/std_fstream.h (basic_file::underflow,
basic_file::uflow, basic_file::_M_underflow): Remove
specialization declarations, call _M_underflow from generic versions
of underflow and uflow.
* src/fstream.cc (basic_file::underflow, basic_file::uflow,
basic_file::_M_underflow): Remove specializations.
* src/Makefile.am (sources): Remove fstream.cc.
* src/Makefile.in: Regenerated.
* testsuite/27_io/basic_filebuf/underflow/10096.cc: New test.
* testsuite/27_io/basic_filebuf/underflow/char/1.cc: New test.
* testsuite/27_io/basic_filebuf/underflow/char/9027.cc: New test.
* testsuite/27_io/basic_filebuf/underflow/wchar_t/9520.cc: New test.
2003-05-10 Benjamin Kosnik <bkoz@redhat.com>
* include/ext/stdio_filebuf.h (__stdio_filebuf): Remove stack
buffer.
* config/io/basic_file_stdio.h (__basic_file::xsgetn): Remove
unbuffered bits.
(__basic_file::xsputn): Same.
(__basic_file::seekoff): Same.
(__basic_file::seekpos): Same.
(__basic_file::showmanyc): Same.
* config/io/basic_file_stdio.cc: Same.
* include/std/std_fstream.h: Same.
* include/bits/fstream.tcc: Same.
* src/fstream.cc: Same.
* testsuite/27_io/basic_filebuf/sgetn/char/1.cc (test05): Tidy.
2003-05-10 Petur Runolfsson <peturr02@ru.is>
PR libstdc++/9520
PR libstdc++/9661
PR libstdc++/9662
* include/ext/stdio_sync_filebuf.h: New file.
(basic_stdiobuf): New.
* include/Makefile.am (ext_headers): Add ext/stdio_sync_filebuf.h
* include/Makefile.in: Regenerate.
* include/bits/ios_base.h (Init::_S_create_buffers,
Init::_S_destroy_buffers): Remove declarations.
* src/globals.cc (buf_cout_sync, buf_cin_sync, buf_cerr_sync,
buf_wcout_sync, buf_wcin_sync, buf_wcerr_sync): Define.
* src/ios.cc (Init::_S_create_buffers,
Init::_S_destroy_buffers): Remove.
(Init::Init): Create and use syncronized buffers.
(ios_base::sync_with_stdio): Destroy syncronized buffers,
create and install unsyncronized buffers.
* testsuite/27_io/objects/char/10.cc: New test.
* testsuite/27_io/objects/char/9.cc: New test.
* testsuite/27_io/objects/char/9661-1.cc: New test.
* testsuite/27_io/objects/char/9661-2_xin.cc: New test.
* testsuite/27_io/objects/char/9661-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/1.cc: New test.
* testsuite/27_io/objects/wchar_t/10.cc: New test.
* testsuite/27_io/objects/wchar_t/2.cc: New test.
* testsuite/27_io/objects/wchar_t/2523-1_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/2523-1_xin.in: New.
* testsuite/27_io/objects/wchar_t/2523-2_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/2523-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/3045.cc: New test.
* testsuite/27_io/objects/wchar_t/3647.cc: New test.
* testsuite/27_io/objects/wchar_t/3_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/3_xin.in: New.
* testsuite/27_io/objects/wchar_t/4_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/4_xin.in: New.
* testsuite/27_io/objects/wchar_t/5.cc: New test.
* testsuite/27_io/objects/wchar_t/5268.cc: New test.
* testsuite/27_io/objects/wchar_t/5280_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/5280_xin.in: New.
* testsuite/27_io/objects/wchar_t/6.cc: New test.
* testsuite/27_io/objects/wchar_t/6548_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/6548_xin.in: New.
* testsuite/27_io/objects/wchar_t/6648-1_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/6648-1_xin.in: New.
* testsuite/27_io/objects/wchar_t/6648-2_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/6648-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/7.cc: New test.
* testsuite/27_io/objects/wchar_t/7744_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/7744_xin.in: New.
* testsuite/27_io/objects/wchar_t/8.cc: New test.
* testsuite/27_io/objects/wchar_t/9_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/9_xin.in: New.
* testsuite/27_io/objects/wchar_t/9520.cc: New test.
* testsuite/27_io/objects/wchar_t/9661-1.cc: New test.
* testsuite/27_io/objects/wchar_t/9661-2_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/9661-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/9662.cc: New test.
* testsuite/ext/stdiobuf_char.cc: New test.
* testsuite/ext/stdiobuf_wchar_t.cc: New test.
From-SVN: r66678
2003-05-11 12:20:57 +08:00
|
|
|
__ret = _M_file.seekoff(__computed_off, __way, __mode);
|
2000-10-05 19:27:02 +08:00
|
|
|
_M_set_indeterminate();
|
|
|
|
}
|
|
|
|
// NB: Need to do this in case _M_file in indeterminate
|
2002-04-16 08:45:36 +08:00
|
|
|
// state, ie _M_file._offset == -1
|
2000-10-05 19:27:02 +08:00
|
|
|
else
|
|
|
|
{
|
[multiple changes]
2003-05-10 Petur Runolfsson <peturr02@ru.is>
PR libstdc++/9027
PR libstdc++/9520
PR libstdc++/10096
* include/bits/fstream.tcc (basic_file::_M_underflow): Add generic
implementation, based on old wchar_t specialization, add support
for codecvt::in() return value of codecvt_base::noconv, remove
_M_file.sys_ungetc() call.
* include/std/std_fstream.h (basic_file::underflow,
basic_file::uflow, basic_file::_M_underflow): Remove
specialization declarations, call _M_underflow from generic versions
of underflow and uflow.
* src/fstream.cc (basic_file::underflow, basic_file::uflow,
basic_file::_M_underflow): Remove specializations.
* src/Makefile.am (sources): Remove fstream.cc.
* src/Makefile.in: Regenerated.
* testsuite/27_io/basic_filebuf/underflow/10096.cc: New test.
* testsuite/27_io/basic_filebuf/underflow/char/1.cc: New test.
* testsuite/27_io/basic_filebuf/underflow/char/9027.cc: New test.
* testsuite/27_io/basic_filebuf/underflow/wchar_t/9520.cc: New test.
2003-05-10 Benjamin Kosnik <bkoz@redhat.com>
* include/ext/stdio_filebuf.h (__stdio_filebuf): Remove stack
buffer.
* config/io/basic_file_stdio.h (__basic_file::xsgetn): Remove
unbuffered bits.
(__basic_file::xsputn): Same.
(__basic_file::seekoff): Same.
(__basic_file::seekpos): Same.
(__basic_file::showmanyc): Same.
* config/io/basic_file_stdio.cc: Same.
* include/std/std_fstream.h: Same.
* include/bits/fstream.tcc: Same.
* src/fstream.cc: Same.
* testsuite/27_io/basic_filebuf/sgetn/char/1.cc (test05): Tidy.
2003-05-10 Petur Runolfsson <peturr02@ru.is>
PR libstdc++/9520
PR libstdc++/9661
PR libstdc++/9662
* include/ext/stdio_sync_filebuf.h: New file.
(basic_stdiobuf): New.
* include/Makefile.am (ext_headers): Add ext/stdio_sync_filebuf.h
* include/Makefile.in: Regenerate.
* include/bits/ios_base.h (Init::_S_create_buffers,
Init::_S_destroy_buffers): Remove declarations.
* src/globals.cc (buf_cout_sync, buf_cin_sync, buf_cerr_sync,
buf_wcout_sync, buf_wcin_sync, buf_wcerr_sync): Define.
* src/ios.cc (Init::_S_create_buffers,
Init::_S_destroy_buffers): Remove.
(Init::Init): Create and use syncronized buffers.
(ios_base::sync_with_stdio): Destroy syncronized buffers,
create and install unsyncronized buffers.
* testsuite/27_io/objects/char/10.cc: New test.
* testsuite/27_io/objects/char/9.cc: New test.
* testsuite/27_io/objects/char/9661-1.cc: New test.
* testsuite/27_io/objects/char/9661-2_xin.cc: New test.
* testsuite/27_io/objects/char/9661-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/1.cc: New test.
* testsuite/27_io/objects/wchar_t/10.cc: New test.
* testsuite/27_io/objects/wchar_t/2.cc: New test.
* testsuite/27_io/objects/wchar_t/2523-1_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/2523-1_xin.in: New.
* testsuite/27_io/objects/wchar_t/2523-2_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/2523-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/3045.cc: New test.
* testsuite/27_io/objects/wchar_t/3647.cc: New test.
* testsuite/27_io/objects/wchar_t/3_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/3_xin.in: New.
* testsuite/27_io/objects/wchar_t/4_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/4_xin.in: New.
* testsuite/27_io/objects/wchar_t/5.cc: New test.
* testsuite/27_io/objects/wchar_t/5268.cc: New test.
* testsuite/27_io/objects/wchar_t/5280_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/5280_xin.in: New.
* testsuite/27_io/objects/wchar_t/6.cc: New test.
* testsuite/27_io/objects/wchar_t/6548_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/6548_xin.in: New.
* testsuite/27_io/objects/wchar_t/6648-1_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/6648-1_xin.in: New.
* testsuite/27_io/objects/wchar_t/6648-2_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/6648-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/7.cc: New test.
* testsuite/27_io/objects/wchar_t/7744_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/7744_xin.in: New.
* testsuite/27_io/objects/wchar_t/8.cc: New test.
* testsuite/27_io/objects/wchar_t/9_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/9_xin.in: New.
* testsuite/27_io/objects/wchar_t/9520.cc: New test.
* testsuite/27_io/objects/wchar_t/9661-1.cc: New test.
* testsuite/27_io/objects/wchar_t/9661-2_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/9661-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/9662.cc: New test.
* testsuite/ext/stdiobuf_char.cc: New test.
* testsuite/ext/stdiobuf_wchar_t.cc: New test.
From-SVN: r66678
2003-05-11 12:20:57 +08:00
|
|
|
pos_type __tmp = _M_file.seekoff(__off, ios_base::cur, __mode);
|
2003-02-05 06:42:32 +08:00
|
|
|
if (__tmp >= 0)
|
2003-02-12 03:53:51 +08:00
|
|
|
{
|
|
|
|
// Seek successful.
|
|
|
|
__ret = __tmp;
|
2003-04-26 08:23:18 +08:00
|
|
|
__ret += std::max(this->_M_out_cur, this->_M_in_cur)
|
|
|
|
- _M_filepos;
|
2003-02-12 03:53:51 +08:00
|
|
|
}
|
2000-10-05 19:27:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
_M_last_overflowed = false;
|
|
|
|
return __ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits>
|
2001-07-20 08:09:31 +08:00
|
|
|
typename basic_filebuf<_CharT, _Traits>::pos_type
|
2000-10-05 19:27:02 +08:00
|
|
|
basic_filebuf<_CharT, _Traits>::
|
|
|
|
seekpos(pos_type __pos, ios_base::openmode __mode)
|
|
|
|
{
|
2002-04-09 14:14:32 +08:00
|
|
|
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
|
|
|
|
// 171. Strange seekpos() semantics due to joint position
|
|
|
|
return this->seekoff(off_type(__pos), ios_base::beg, __mode);
|
|
|
|
#endif
|
2000-10-05 19:27:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits>
|
|
|
|
void
|
|
|
|
basic_filebuf<_CharT, _Traits>::
|
|
|
|
_M_output_unshift()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
template<typename _CharT, typename _Traits>
|
|
|
|
void
|
|
|
|
basic_filebuf<_CharT, _Traits>::
|
|
|
|
imbue(const locale& __loc)
|
|
|
|
{
|
2003-04-22 05:44:44 +08:00
|
|
|
const bool __testbeg = this->_M_in_cur == this->_M_in_beg
|
|
|
|
&& this->_M_out_cur == this->_M_out_beg;
|
2001-03-15 04:46:34 +08:00
|
|
|
|
2003-01-17 04:30:50 +08:00
|
|
|
if (__testbeg && this->_M_buf_locale != __loc)
|
2003-01-24 06:53:35 +08:00
|
|
|
this->_M_buf_locale = __loc;
|
2001-03-15 04:46:34 +08:00
|
|
|
|
2000-10-05 19:27:02 +08:00
|
|
|
// NB this may require the reconversion of previously
|
|
|
|
// converted chars. This in turn may cause the reconstruction
|
|
|
|
// of the original file. YIKES!!
|
|
|
|
// XXX The part in the above comment is not done.
|
|
|
|
_M_last_overflowed = false;
|
|
|
|
}
|
Tune for size.
2002-02-15 Benjamin Kosnik <bkoz@redhat.com>
Tune for size.
* src/string-inst.cc (string::_Rep::_S_terminal): Remove redundant
explicit instantiation.
(string::_Rep::_S_max_size): Same.
* include/bits/basic_string.tcc: Add extern explicit
instantiations for string, wstring.
* include/bits/basic_ios.tcc: Add extern explicit instantiations
for ios, wios.
* include/bits/streambuf.tcc: Same, for streambuf, wstreambuf.
* include/bits/istream.tcc: Same, for istream, wistream.
* include/bits/ostream.tcc: Same for ostream, wostream, iostream,
wiostream.
* include/bits/sstream.tcc: Same, for stringbuf, wstringbuf,
istringstream, wistringstream, ostringstream, wostringstream,
stringstream, wstringstream.
* include/bits/fstream.tcc: Same, for filebuf, wfilebuf, ifstream,
wifstream, ofstream, wofstream, fstream, wfstream.
* src/misc-inst.cc: Correct comments.
Add iomanip instantiations for wide streams.
* include/std/std_iomanip.h: Same.
* include/bits/locale_facets.tcc: Same.
* include/std/std_streambuf.h: Correct
_GLIBCPP_FULLY_COMPLIANT_HEADERS guard.
* include/std/std_sstream.h: Same.
* include/std/std_ostream.h: Same.
* include/std/std_istream.h: Same.
* include/std/std_fstream.h: Same.
* include/std/std_streambuf.h: Add definitions for private copy
ctor and assignment operator.
* include/std/std_istream.h: Remove declared but undefined copy
ctor and assignment operator. This is taken care of in ios_base,
so adding it in the derived class as well is superfluous.
* include/std/std_ostream.h: Same.
* include/bits/basic_ios.h (basic_ios::clear): Don't inline.
* include/bits/basic_ios.tcc (basic_ios::clear): Move definition here.
From-SVN: r49798
2002-02-16 08:19:13 +08:00
|
|
|
|
|
|
|
// Inhibit implicit instantiations for required instantiations,
|
|
|
|
// which are defined via explicit instantiations elsewhere.
|
|
|
|
// NB: This syntax is a GNU extension.
|
2003-02-14 05:39:03 +08:00
|
|
|
#if _GLIBCPP_EXTERN_TEMPLATE
|
Tune for size.
2002-02-15 Benjamin Kosnik <bkoz@redhat.com>
Tune for size.
* src/string-inst.cc (string::_Rep::_S_terminal): Remove redundant
explicit instantiation.
(string::_Rep::_S_max_size): Same.
* include/bits/basic_string.tcc: Add extern explicit
instantiations for string, wstring.
* include/bits/basic_ios.tcc: Add extern explicit instantiations
for ios, wios.
* include/bits/streambuf.tcc: Same, for streambuf, wstreambuf.
* include/bits/istream.tcc: Same, for istream, wistream.
* include/bits/ostream.tcc: Same for ostream, wostream, iostream,
wiostream.
* include/bits/sstream.tcc: Same, for stringbuf, wstringbuf,
istringstream, wistringstream, ostringstream, wostringstream,
stringstream, wstringstream.
* include/bits/fstream.tcc: Same, for filebuf, wfilebuf, ifstream,
wifstream, ofstream, wofstream, fstream, wfstream.
* src/misc-inst.cc: Correct comments.
Add iomanip instantiations for wide streams.
* include/std/std_iomanip.h: Same.
* include/bits/locale_facets.tcc: Same.
* include/std/std_streambuf.h: Correct
_GLIBCPP_FULLY_COMPLIANT_HEADERS guard.
* include/std/std_sstream.h: Same.
* include/std/std_ostream.h: Same.
* include/std/std_istream.h: Same.
* include/std/std_fstream.h: Same.
* include/std/std_streambuf.h: Add definitions for private copy
ctor and assignment operator.
* include/std/std_istream.h: Remove declared but undefined copy
ctor and assignment operator. This is taken care of in ios_base,
so adding it in the derived class as well is superfluous.
* include/std/std_ostream.h: Same.
* include/bits/basic_ios.h (basic_ios::clear): Don't inline.
* include/bits/basic_ios.tcc (basic_ios::clear): Move definition here.
From-SVN: r49798
2002-02-16 08:19:13 +08:00
|
|
|
extern template class basic_filebuf<char>;
|
|
|
|
extern template class basic_ifstream<char>;
|
|
|
|
extern template class basic_ofstream<char>;
|
|
|
|
extern template class basic_fstream<char>;
|
2002-11-02 01:30:36 +08:00
|
|
|
|
|
|
|
#ifdef _GLIBCPP_USE_WCHAR_T
|
|
|
|
extern template class basic_filebuf<wchar_t>;
|
|
|
|
extern template class basic_ifstream<wchar_t>;
|
|
|
|
extern template class basic_ofstream<wchar_t>;
|
Tune for size.
2002-02-15 Benjamin Kosnik <bkoz@redhat.com>
Tune for size.
* src/string-inst.cc (string::_Rep::_S_terminal): Remove redundant
explicit instantiation.
(string::_Rep::_S_max_size): Same.
* include/bits/basic_string.tcc: Add extern explicit
instantiations for string, wstring.
* include/bits/basic_ios.tcc: Add extern explicit instantiations
for ios, wios.
* include/bits/streambuf.tcc: Same, for streambuf, wstreambuf.
* include/bits/istream.tcc: Same, for istream, wistream.
* include/bits/ostream.tcc: Same for ostream, wostream, iostream,
wiostream.
* include/bits/sstream.tcc: Same, for stringbuf, wstringbuf,
istringstream, wistringstream, ostringstream, wostringstream,
stringstream, wstringstream.
* include/bits/fstream.tcc: Same, for filebuf, wfilebuf, ifstream,
wifstream, ofstream, wofstream, fstream, wfstream.
* src/misc-inst.cc: Correct comments.
Add iomanip instantiations for wide streams.
* include/std/std_iomanip.h: Same.
* include/bits/locale_facets.tcc: Same.
* include/std/std_streambuf.h: Correct
_GLIBCPP_FULLY_COMPLIANT_HEADERS guard.
* include/std/std_sstream.h: Same.
* include/std/std_ostream.h: Same.
* include/std/std_istream.h: Same.
* include/std/std_fstream.h: Same.
* include/std/std_streambuf.h: Add definitions for private copy
ctor and assignment operator.
* include/std/std_istream.h: Remove declared but undefined copy
ctor and assignment operator. This is taken care of in ios_base,
so adding it in the derived class as well is superfluous.
* include/std/std_ostream.h: Same.
* include/bits/basic_ios.h (basic_ios::clear): Don't inline.
* include/bits/basic_ios.tcc (basic_ios::clear): Move definition here.
From-SVN: r49798
2002-02-16 08:19:13 +08:00
|
|
|
extern template class basic_fstream<wchar_t>;
|
2002-11-02 01:30:36 +08:00
|
|
|
#endif
|
2003-02-14 05:39:03 +08:00
|
|
|
#endif
|
2000-10-05 19:27:02 +08:00
|
|
|
} // namespace std
|
|
|
|
|
2002-02-01 11:20:39 +08:00
|
|
|
#endif
|