This is the mail archive of the
libstdc++@sourceware.cygnus.com
mailing list for the libstdc++ project.
Re: closing stream before opening sets fail bit
on Sat, Jun 17, 2000 at 04:38:47PM -0700, Rob Willis typed aloud:
|
|
| Found this quirky behavior. Is this the correct behavior? Basically, calling
| close() before opening the ofstream causes the fail bit to be
| set. I can live with that... But then, the open command succeeds and the
| fail bit is still set!! And of course the write fails.
27.8.1.3
basic_filebuf<charT,traits>* open(
const char* s,
ios_base::openmode mode);
Effects: If is_open() != false, returns a null pointer. Otherwise,
initializes the filebuf as required.
Now, 'as required' is a bit vague :), but that implies to me that
after a successful open(), the returned basic_filebuf should be
in a normal, operational state... which means we need to explicitly
clear() the [io]fstream inside of open(), which will (re)set the
failbit if there is any _real_ failure in rdbuf()->open(). If this
is sane, the patch below may be applied. If it breaks
Things I Don't Know About, please let me know.
Cheers.
Brent
*** /usr/local/cvs/libstdc++-v3/bits/std_fstream.h Mon May 1 20:27:21 2000
--- std_fstream.h Sun Jun 18 15:55:17 2000
*************** namespace std {
*** 289,297 ****
void
open(const char* __s,
ios_base::openmode __mode = ios_base::out | ios_base::trunc)
! {
if (!rdbuf()->open(__s, __mode | ios_base::out))
! this->setstate (ios_base::failbit);
}
void
--- 289,298 ----
void
open(const char* __s,
ios_base::openmode __mode = ios_base::out | ios_base::trunc)
! {
! this->clear();
if (!rdbuf()->open(__s, __mode | ios_base::out))
! this->setstate(ios_base::failbit);
}
void
--
Damon Brent Verner
Cracker JackŪ Certified Professional
brent@rcfile.org, brent@linux1.org