Commit 0c45b8e0 by Benjamin Kosnik

[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
parent aa40083d
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> 2003-03-17 Danny Smith <dannysmith@users.sourceforge.net>
* libsupc++/Makefile.am (C_COMPILE): Remove. * libsupc++/Makefile.am (C_COMPILE): Remove.
......
...@@ -122,21 +122,17 @@ namespace std ...@@ -122,21 +122,17 @@ namespace std
basic_filebuf<_CharT, _Traits>:: basic_filebuf<_CharT, _Traits>::
close() close()
{ {
__filebuf_type *__ret = NULL; __filebuf_type* __ret = NULL;
if (this->is_open()) if (this->is_open())
{ {
bool __testfail = false;
const int_type __eof = traits_type::eof(); const int_type __eof = traits_type::eof();
bool __testput = this->_M_out_cur bool __testput = this->_M_out_cur
&& this->_M_out_beg < this->_M_out_lim; && this->_M_out_beg < this->_M_out_lim;
if (__testput if (__testput
&& traits_type::eq_int_type(_M_really_overflow(__eof), __eof)) && 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 #if 0
// XXX not done // XXX not done
if (_M_last_overflowed) if (_M_last_overflowed)
...@@ -146,10 +142,17 @@ namespace std ...@@ -146,10 +142,17 @@ namespace std
} }
#endif #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; __ret = this;
} }
_M_last_overflowed = false; _M_last_overflowed = false;
return __ret; return __ret;
} }
......
// 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 // 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 // software; you can redistribute it and/or modify it under the
...@@ -89,23 +89,24 @@ void test_02() ...@@ -89,23 +89,24 @@ void test_02()
// read (ext) // read (ext)
FILE* f2 = fopen(name_01, "r"); FILE* f2 = fopen(name_01, "r");
VERIFY( f2 != NULL ); VERIFY( f2 != NULL );
if (f2)
{ {
__gnu_cxx::stdio_filebuf<char> fb(f2, std::ios_base::in, 512); __gnu_cxx::stdio_filebuf<char> fb(f2, std::ios_base::in, 512);
close_num = fclose(f2);
} }
close_num = fclose(f2);
VERIFY( close_num == 0 ); VERIFY( close_num == 0 );
// read (standard) // read (standard)
FILE* f = fopen(name_01, "r"); FILE* f = fopen(name_01, "r");
VERIFY( f != NULL ); VERIFY( f != NULL );
if (f)
{ {
std::ifstream ifstream1(name_01); std::ifstream ifstream1(name_01);
VERIFY( ifstream1.is_open() ); VERIFY( ifstream1.is_open() );
std::ios_base::iostate st01 = ifstream1.rdstate(); std::ios_base::iostate st01 = ifstream1.rdstate();
VERIFY( st01 == std::ios_base::goodbit ); VERIFY( st01 == std::ios_base::goodbit );
close_num = fclose(f);
} }
close_num = fclose(f);
VERIFY( close_num == 0 ); VERIFY( close_num == 0 );
} }
...@@ -128,9 +129,11 @@ void test_03() ...@@ -128,9 +129,11 @@ void test_03()
void void
test_04() test_04()
{ {
bool test = true;
const char* name = "tmp_fifo1";
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
if (0 != mkfifo("xxx", S_IRWXU)) if (0 != mkfifo(name, S_IRWXU))
{ {
std::cerr << "failed to creat fifo" << std::endl; std::cerr << "failed to creat fifo" << std::endl;
exit(-1); exit(-1);
...@@ -140,18 +143,18 @@ test_04() ...@@ -140,18 +143,18 @@ test_04()
if (fval == -1) if (fval == -1)
{ {
std::cerr << "failed to fork" << std::endl; std::cerr << "failed to fork" << std::endl;
unlink("xxx"); unlink(name);
exit(-1); exit(-1);
} }
else if (fval == 0) else if (fval == 0)
{ {
std::ifstream ifs("xxx"); std::ifstream ifs(name);
sleep(1); sleep(1);
ifs.close(); ifs.close();
exit(0); exit(0);
} }
std::ofstream ofs("xxx"); std::ofstream ofs(name);
sleep(2); sleep(2);
ofs.put('t'); ofs.put('t');
...@@ -166,25 +169,27 @@ test_04() ...@@ -166,25 +169,27 @@ test_04()
ofs.close(); ofs.close();
if (!(ofs.rdstate() & std::ios::failbit)) if (!(ofs.rdstate() & std::ios::failbit))
{ {
std::cerr << "fail bit was not set!" << std::endl; test = false;
unlink("xxx"); VERIFY( test );
unlink(name);
exit(-1); exit(-1);
} }
unlink("xxx"); unlink(name);
} }
// Charles Leggett <CGLeggett@lbl.gov> // Charles Leggett <CGLeggett@lbl.gov>
void test_05() void test_05()
{ {
bool test = true; bool test = true;
const char* name = "tmp_file5";
std::fstream scratch_file; std::fstream scratch_file;
scratch_file.open("SCRATCH", std::ios::out); scratch_file.open(name, std::ios::out);
scratch_file.close(); scratch_file.close();
scratch_file.open("SCRATCH", std::ios::in); scratch_file.open(name, std::ios::in);
if (!scratch_file) if (!scratch_file)
VERIFY( false ); VERIFY( false );
scratch_file.close(); scratch_file.close();
...@@ -194,29 +199,66 @@ void test_05() ...@@ -194,29 +199,66 @@ void test_05()
void test_06() void test_06()
{ {
bool test = true; bool test = true;
const char* name = "tmp_fifo2";
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
unlink("yyy"); unlink(name);
mkfifo("yyy", S_IRWXU); mkfifo(name, S_IRWXU);
if (!fork()) if (!fork())
{ {
std::filebuf fbuf; std::filebuf fbuf;
fbuf.open("yyy", std::ios_base::in); fbuf.open(name, std::ios_base::in);
fbuf.sgetc(); fbuf.sgetc();
fbuf.close(); fbuf.close();
exit(0); exit(0);
} }
std::filebuf fbuf; std::filebuf fbuf;
std::filebuf* r = std::filebuf* r = fbuf.open(name, std::ios_base::out | std::ios_base::ate);
fbuf.open("yyy", std::ios_base::out | std::ios_base::ate);
VERIFY( !fbuf.is_open() ); VERIFY( !fbuf.is_open() );
VERIFY( r == NULL ); 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 int
main() main()
{ {
...@@ -226,6 +268,7 @@ main() ...@@ -226,6 +268,7 @@ main()
test_04(); test_04();
test_05(); test_05();
test_06(); test_06();
test_07();
return 0; return 0;
} }
......
...@@ -73,6 +73,5 @@ stamp_wchar: ...@@ -73,6 +73,5 @@ stamp_wchar:
touch testsuite_wchar_t touch testsuite_wchar_t
# By adding these files here, automake will remove them for 'make clean' # By adding these files here, automake will remove them for 'make clean'
CLEANFILES = *.txt *.tst *.exe core* filebuf_* tmp ostream_* *.log *.sum \ CLEANFILES = *.txt *.tst *.exe core* filebuf_* tmp* ostream_* *.log *.sum \
testsuite_files testsuite_wchar_t \ testsuite_files testsuite_wchar_t site.exp abi_check
site.exp abi_check
# 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. # Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation # This Makefile.in is free software; the Free Software Foundation
...@@ -180,9 +180,8 @@ libv3test_a_SOURCES = testsuite_hooks.cc testsuite_allocator.cc ...@@ -180,9 +180,8 @@ libv3test_a_SOURCES = testsuite_hooks.cc testsuite_allocator.cc
abi_check_SOURCES = abi_check.cc abi_check_SOURCES = abi_check.cc
# By adding these files here, automake will remove them for 'make clean' # By adding these files here, automake will remove them for 'make clean'
CLEANFILES = *.txt *.tst *.exe core* filebuf_* tmp ostream_* *.log *.sum \ CLEANFILES = *.txt *.tst *.exe core* filebuf_* tmp* ostream_* *.log *.sum \
testsuite_files testsuite_wchar_t \ testsuite_files testsuite_wchar_t site.exp abi_check
site.exp abi_check
mkinstalldirs = $(SHELL) $(top_srcdir)/../mkinstalldirs mkinstalldirs = $(SHELL) $(top_srcdir)/../mkinstalldirs
CONFIG_HEADER = ../config.h CONFIG_HEADER = ../config.h
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment