filebuf.cc: Tweak.

2000-06-28  Benjamin Kosnik  <bkoz@purist.soma.redhat.com>

	* testsuite/27_io/filebuf.cc: Tweak.
	* testsuite/27_io/filebuf_members.cc (test_01): Fix.
	* config/c_io_libio.cc (__basic_file::~__basic_file): Match libio
	filebuf dtor.
	(__basic_file::basic_file): Clean, add calls similar to
	_IO_file_attach.
	(__basic_file::open): Clean.
	(__basic_file::sys_open): Clean.

	* bits/std_fstream.h: Revert.
	* bits/fstream.tcc (filebuf::close()): Revert.
	(filebuf::basic_filebuf()): Revert.

From-SVN: r34786
This commit is contained in:
Benjamin Kosnik 2000-06-29 18:20:55 +00:00
parent 993c790ecd
commit ab30ba5c23
6 changed files with 42 additions and 38 deletions

View File

@ -1,3 +1,18 @@
2000-06-28 Benjamin Kosnik <bkoz@purist.soma.redhat.com>
* testsuite/27_io/filebuf.cc: Tweak.
* testsuite/27_io/filebuf_members.cc (test_01): Fix.
* config/c_io_libio.cc (__basic_file::~__basic_file): Match libio
filebuf dtor.
(__basic_file::basic_file): Clean, add calls similar to
_IO_file_attach.
(__basic_file::open): Clean.
(__basic_file::sys_open): Clean.
* bits/std_fstream.h: Revert.
* bits/fstream.tcc (filebuf::close()): Revert.
(filebuf::basic_filebuf()): Revert.
2000-06-27 Benjamin Kosnik <bkoz@purist.soma.redhat.com>
Update to SGI STL 3.3
@ -30,7 +45,7 @@
* docs/install.html: Fix minor typo as reported.
2000-06-13 Brent Verner <brent@rcfile.org>
2000-06-26 Brent Verner <brent@rcfile.org>
* bits/string.tcc (string::rfind): Fix.
* testsuite/21_strings/rfind.cc: New file.

View File

@ -56,10 +56,9 @@ namespace std
basic_filebuf<_CharT, _Traits>::
basic_filebuf()
: __streambuf_type(), _M_file(NULL), _M_state_cur(), _M_state_beg(),
_M_last_overflowed(false), _M_fileno_based(false)
_M_last_overflowed(false)
{ _M_fcvt = &use_facet<__codecvt_type>(this->getloc()); }
template<typename _CharT, typename _Traits>
basic_filebuf<_CharT, _Traits>::
basic_filebuf(int __fd, const char* /*__name*/, ios_base::openmode __mode)
@ -68,7 +67,6 @@ namespace std
{
_M_fcvt = &use_facet<__codecvt_type>(this->getloc());
_M_init_filebuf();
_M_fileno_based = true;
_M_file->sys_open(__fd, __mode);
if (this->is_open() && _M_buf_size)
{
@ -144,14 +142,10 @@ namespace std
}
#endif
bool __testclosed;
if (_M_fileno_based)
__testclosed = _M_file->sys_close();
else
__testclosed = _M_file->close();
if (__testclosed)
if (_M_file)
{
delete _M_file;
_M_file = NULL;
_M_mode = ios_base::openmode(0);
if (_M_buf_size)
delete [] _M_buf;

View File

@ -71,7 +71,6 @@ namespace std {
const __codecvt_type* _M_fcvt; // Cached value from use_facet.
__mutext_type _M_lock;
bool _M_last_overflowed; // XXX Needed?
bool _M_fileno_based; // Open/closed via filenos.
public:
// Constructors/destructor:
@ -85,8 +84,6 @@ namespace std {
{
this->close();
_M_fcvt = NULL;
delete _M_file;
_M_file = NULL;
_M_last_overflowed = false;
}

View File

@ -39,9 +39,10 @@ namespace std {
__basic_file::__basic_file(__c_lock* __lock)
{
this->_lock = __lock;
_IO_init(this, 0);
_lock = __lock;
_IO_init(this, 0);
_IO_file_init(this);
_IO_file_attach(this, -1);
}
int
@ -50,14 +51,13 @@ namespace std {
__basic_file::~__basic_file()
{
if (_IO_file_is_open(this))
if (this->is_open())
{
_IO_do_flush(this);
if (!(_IO_file_flags & _IO_DELETE_DONT_CLOSE))
if (!(_flags & _IO_DELETE_DONT_CLOSE))
_IO_SYSCLOSE(this);
}
else
_IO_un_link(this);
_IO_default_finish(this, 0);
}
__basic_file*
@ -89,13 +89,12 @@ namespace std {
if (__fd >= 0)
{
__retval = this;
_fileno = __fd;
int __mask = _IO_NO_READS + _IO_NO_WRITES + _IO_IS_APPENDING;
_flags = (_flags & ~__mask) | (__rw_mode & __mask);
_IO_link_in(this);
__retval = this;
}
int __mask = _IO_NO_READS + _IO_NO_WRITES + _IO_IS_APPENDING;
_IO_file_flags = (_IO_file_flags & ~__mask) | (__rw_mode & __mask);
_IO_link_in(this);
return __retval;
}
@ -148,22 +147,22 @@ namespace std {
if (__testb)
__p_mode |= O_BINARY;
#endif
if ( !_IO_file_is_open(this))
if (!_IO_file_is_open(this))
{
#if _G_HAVE_IO_FILE_OPEN
__c_file_type* __f;
__f = _IO_file_open(this, __name, __p_mode, __prot, __rw_mode, 0);
__retval = __f ? this: NULL;
#else
int __i = ::open(__name, __p_mode, __prot);
if (__i >= 0)
int __fd = ::open(__name, __p_mode, __prot);
if (__fd >= 0)
{
_fileno = __fd;
int __mask = _IO_NO_READS + _IO_NO_WRITES + _IO_IS_APPENDING;
_flags = (_flags & ~__mask) | (__rw_mode & __mask);
_IO_link_in(this);
__retval = this;
_fileno = __i;
}
int __mask = _IO_NO_READS + _IO_NO_WRITES + _IO_IS_APPENDING;
_IO_file_flags = (_IO_file_flags & ~__mask) | (__rw_mode & __mask);
_IO_link_in(this);
#endif
}
return __retval;
@ -174,10 +173,7 @@ namespace std {
__basic_file*
__basic_file::close()
{
bool __testopen = _IO_file_close_it(this);
return __testopen ? static_cast<__basic_file*>(NULL) : this;
}
{ return _IO_file_close_it(this) ? static_cast<__basic_file*>(NULL) : this; }
// NB: Unused.
int

View File

@ -46,6 +46,7 @@ derived_filebuf fb_03; // in | out
const int buffer_size = 8192;
// initialize filebufs to be the same size regardless of platform
void test00()
{
@ -54,6 +55,7 @@ void test00()
fb_03.set_size(buffer_size);
}
// test the filebuf/stringbuf locale settings
bool test01() {
std::locale loc_tmp;
@ -75,7 +77,7 @@ bool test02() {
test &= !fb_03.is_open();
// filebuf_type* open(const char* __s, ios_base::openmode __mode)
fb_01.open(name_01, std::ios_base::in | std::ios_base::ate);
fb_01.open(name_01, std::ios_base::in | std::ios_base::ate);
fb_02.open(name_02, std::ios_base::in | std::ios_base::out | std::ios_base::trunc);
// Try to open two different files without closing the first:
// Should keep the old file attached, and disregard attempt to overthrow.

View File

@ -60,7 +60,7 @@ test_01()
// read (standard)
FILE* f = fopen(name_01, "r");
test &= !f;
test &= f != NULL;
{
std::ifstream ifstream1(name_01);