[multiple changes]
2003-03-17 Benjamin Kosnik <bkoz@redhat.com> * testsuite/Makefile.am (CLEANFILES): Add tmp*. * testsuite/Makefile.in: Regenerate. * testsuite/27_io/filebuf_members.cc: Consistently name tmp files. Cleanups. 2003-03-17 Petur Runolfsson <peturr02@ru.is> PR libstdc++/9964 * include/bits/fstream.tcc (basic_filebuf::close): Always close file, even when write fails. * testsuite/27_io/filebuf_members.cc (test_07): New test. From-SVN: r64498
This commit is contained in:
parent
aa40083db9
commit
0c45b8e073
|
@ -1,3 +1,17 @@
|
|||
2003-03-17 Benjamin Kosnik <bkoz@redhat.com>
|
||||
|
||||
* testsuite/Makefile.am (CLEANFILES): Add tmp*.
|
||||
* testsuite/Makefile.in: Regenerate.
|
||||
* testsuite/27_io/filebuf_members.cc: Consistently name tmp files.
|
||||
Cleanups.
|
||||
|
||||
2003-03-17 Petur Runolfsson <peturr02@ru.is>
|
||||
|
||||
PR libstdc++/9964
|
||||
* include/bits/fstream.tcc (basic_filebuf::close):
|
||||
Always close file, even when write fails.
|
||||
* testsuite/27_io/filebuf_members.cc (test_07): New test.
|
||||
|
||||
2003-03-17 Danny Smith <dannysmith@users.sourceforge.net>
|
||||
|
||||
* libsupc++/Makefile.am (C_COMPILE): Remove.
|
||||
|
|
|
@ -122,21 +122,17 @@ namespace std
|
|||
basic_filebuf<_CharT, _Traits>::
|
||||
close()
|
||||
{
|
||||
__filebuf_type *__ret = NULL;
|
||||
__filebuf_type* __ret = NULL;
|
||||
if (this->is_open())
|
||||
{
|
||||
bool __testfail = false;
|
||||
const int_type __eof = traits_type::eof();
|
||||
bool __testput = this->_M_out_cur
|
||||
&& this->_M_out_beg < this->_M_out_lim;
|
||||
&& this->_M_out_beg < this->_M_out_lim;
|
||||
if (__testput
|
||||
&& traits_type::eq_int_type(_M_really_overflow(__eof), __eof))
|
||||
return __ret;
|
||||
__testfail = true;
|
||||
|
||||
// NB: Do this here so that re-opened filebufs will be cool...
|
||||
this->_M_mode = ios_base::openmode(0);
|
||||
_M_destroy_internal_buffer();
|
||||
_M_pback_destroy();
|
||||
|
||||
#if 0
|
||||
// XXX not done
|
||||
if (_M_last_overflowed)
|
||||
|
@ -146,10 +142,17 @@ namespace std
|
|||
}
|
||||
#endif
|
||||
|
||||
if (_M_file.close())
|
||||
// NB: Do this here so that re-opened filebufs will be cool...
|
||||
this->_M_mode = ios_base::openmode(0);
|
||||
_M_destroy_internal_buffer();
|
||||
_M_pback_destroy();
|
||||
|
||||
if (!_M_file.close())
|
||||
__testfail = true;
|
||||
|
||||
if (!__testfail)
|
||||
__ret = this;
|
||||
}
|
||||
|
||||
_M_last_overflowed = false;
|
||||
return __ret;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (C) 2001, 2002 Free Software Foundation, Inc.
|
||||
// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
|
||||
//
|
||||
// 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
|
||||
|
@ -89,23 +89,24 @@ void test_02()
|
|||
// read (ext)
|
||||
FILE* f2 = fopen(name_01, "r");
|
||||
VERIFY( f2 != NULL );
|
||||
if (f2)
|
||||
{
|
||||
__gnu_cxx::stdio_filebuf<char> fb(f2, std::ios_base::in, 512);
|
||||
close_num = fclose(f2);
|
||||
}
|
||||
close_num = fclose(f2);
|
||||
VERIFY( close_num == 0 );
|
||||
|
||||
|
||||
// read (standard)
|
||||
FILE* f = fopen(name_01, "r");
|
||||
VERIFY( f != NULL );
|
||||
if (f)
|
||||
{
|
||||
std::ifstream ifstream1(name_01);
|
||||
VERIFY( ifstream1.is_open() );
|
||||
std::ios_base::iostate st01 = ifstream1.rdstate();
|
||||
VERIFY( st01 == std::ios_base::goodbit );
|
||||
close_num = fclose(f);
|
||||
}
|
||||
close_num = fclose(f);
|
||||
VERIFY( close_num == 0 );
|
||||
}
|
||||
|
||||
|
@ -128,9 +129,11 @@ void test_03()
|
|||
void
|
||||
test_04()
|
||||
{
|
||||
bool test = true;
|
||||
const char* name = "tmp_fifo1";
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
||||
if (0 != mkfifo("xxx", S_IRWXU))
|
||||
if (0 != mkfifo(name, S_IRWXU))
|
||||
{
|
||||
std::cerr << "failed to creat fifo" << std::endl;
|
||||
exit(-1);
|
||||
|
@ -140,18 +143,18 @@ test_04()
|
|||
if (fval == -1)
|
||||
{
|
||||
std::cerr << "failed to fork" << std::endl;
|
||||
unlink("xxx");
|
||||
unlink(name);
|
||||
exit(-1);
|
||||
}
|
||||
else if (fval == 0)
|
||||
{
|
||||
std::ifstream ifs("xxx");
|
||||
std::ifstream ifs(name);
|
||||
sleep(1);
|
||||
ifs.close();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
std::ofstream ofs("xxx");
|
||||
std::ofstream ofs(name);
|
||||
sleep(2);
|
||||
ofs.put('t');
|
||||
|
||||
|
@ -166,25 +169,27 @@ test_04()
|
|||
ofs.close();
|
||||
if (!(ofs.rdstate() & std::ios::failbit))
|
||||
{
|
||||
std::cerr << "fail bit was not set!" << std::endl;
|
||||
unlink("xxx");
|
||||
test = false;
|
||||
VERIFY( test );
|
||||
unlink(name);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
unlink("xxx");
|
||||
unlink(name);
|
||||
}
|
||||
|
||||
// Charles Leggett <CGLeggett@lbl.gov>
|
||||
void test_05()
|
||||
{
|
||||
bool test = true;
|
||||
const char* name = "tmp_file5";
|
||||
|
||||
std::fstream scratch_file;
|
||||
|
||||
scratch_file.open("SCRATCH", std::ios::out);
|
||||
scratch_file.open(name, std::ios::out);
|
||||
scratch_file.close();
|
||||
|
||||
scratch_file.open("SCRATCH", std::ios::in);
|
||||
scratch_file.open(name, std::ios::in);
|
||||
if (!scratch_file)
|
||||
VERIFY( false );
|
||||
scratch_file.close();
|
||||
|
@ -194,29 +199,66 @@ void test_05()
|
|||
void test_06()
|
||||
{
|
||||
bool test = true;
|
||||
const char* name = "tmp_fifo2";
|
||||
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
||||
unlink("yyy");
|
||||
mkfifo("yyy", S_IRWXU);
|
||||
unlink(name);
|
||||
mkfifo(name, S_IRWXU);
|
||||
|
||||
if (!fork())
|
||||
{
|
||||
std::filebuf fbuf;
|
||||
fbuf.open("yyy", std::ios_base::in);
|
||||
fbuf.open(name, std::ios_base::in);
|
||||
fbuf.sgetc();
|
||||
fbuf.close();
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
std::filebuf fbuf;
|
||||
std::filebuf* r =
|
||||
fbuf.open("yyy", std::ios_base::out | std::ios_base::ate);
|
||||
std::filebuf* r = fbuf.open(name, std::ios_base::out | std::ios_base::ate);
|
||||
VERIFY( !fbuf.is_open() );
|
||||
VERIFY( r == NULL );
|
||||
}
|
||||
|
||||
// libstdc++/9964
|
||||
void test_07()
|
||||
{
|
||||
using namespace std;
|
||||
bool test = true;
|
||||
|
||||
const char* name = "tmp_fifo3";
|
||||
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
||||
unlink(name);
|
||||
mkfifo(name, S_IRWXU);
|
||||
|
||||
int child = fork();
|
||||
VERIFY( child != -1 );
|
||||
|
||||
if (child == 0)
|
||||
{
|
||||
filebuf fbin;
|
||||
fbin.open(name, ios_base::in);
|
||||
sleep(1);
|
||||
fbin.close();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
filebuf fb;
|
||||
filebuf* ret = fb.open(name, ios_base::out | ios_base::trunc);
|
||||
VERIFY( ret != NULL );
|
||||
VERIFY( fb.is_open() );
|
||||
|
||||
sleep(2);
|
||||
fb.sputc('a');
|
||||
|
||||
ret = fb.close();
|
||||
VERIFY( ret == NULL );
|
||||
VERIFY( !fb.is_open() );
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
|
@ -226,6 +268,7 @@ main()
|
|||
test_04();
|
||||
test_05();
|
||||
test_06();
|
||||
test_07();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -73,6 +73,5 @@ stamp_wchar:
|
|||
touch testsuite_wchar_t
|
||||
|
||||
# By adding these files here, automake will remove them for 'make clean'
|
||||
CLEANFILES = *.txt *.tst *.exe core* filebuf_* tmp ostream_* *.log *.sum \
|
||||
testsuite_files testsuite_wchar_t \
|
||||
site.exp abi_check
|
||||
CLEANFILES = *.txt *.tst *.exe core* filebuf_* tmp* ostream_* *.log *.sum \
|
||||
testsuite_files testsuite_wchar_t site.exp abi_check
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Makefile.in generated automatically by automake 1.4-p5 from Makefile.am
|
||||
# Makefile.in generated automatically by automake 1.4-p6 from Makefile.am
|
||||
|
||||
# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
|
||||
# This Makefile.in is free software; the Free Software Foundation
|
||||
|
@ -180,9 +180,8 @@ libv3test_a_SOURCES = testsuite_hooks.cc testsuite_allocator.cc
|
|||
abi_check_SOURCES = abi_check.cc
|
||||
|
||||
# By adding these files here, automake will remove them for 'make clean'
|
||||
CLEANFILES = *.txt *.tst *.exe core* filebuf_* tmp ostream_* *.log *.sum \
|
||||
testsuite_files testsuite_wchar_t \
|
||||
site.exp abi_check
|
||||
CLEANFILES = *.txt *.tst *.exe core* filebuf_* tmp* ostream_* *.log *.sum \
|
||||
testsuite_files testsuite_wchar_t site.exp abi_check
|
||||
|
||||
mkinstalldirs = $(SHELL) $(top_srcdir)/../mkinstalldirs
|
||||
CONFIG_HEADER = ../config.h
|
||||
|
|
Loading…
Reference in New Issue