[multiple changes]
authorBenjamin Kosnik <bkoz@gcc.gnu.org>
Mon, 17 Mar 2003 18:44:44 +0000 (18:44 +0000)
committerBenjamin Kosnik <bkoz@gcc.gnu.org>
Mon, 17 Mar 2003 18:44:44 +0000 (18:44 +0000)
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

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/fstream.tcc
libstdc++-v3/testsuite/27_io/filebuf_members.cc
libstdc++-v3/testsuite/Makefile.am
libstdc++-v3/testsuite/Makefile.in

index 0885ee04e07dd0632f24c96a631f488d2eedcf83..555c135cdf927af0b26f56d43e1a877bcf367cd1 100644 (file)
@@ -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.
index f1214f4f426f3eb8bb5ddefc4af41ca6e8240bb5..d854d0b883afa4bc61c11cf4eef676598f971564 100644 (file)
@@ -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;
     }
index 88b05358e7fd2c1deafadd60d735c11dac6fa908..d6a9b35cd3f113f00d0804235b346e1fc35850a0 100644 (file)
@@ -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;
 }
 
index 7380035af3f98b1410e88c064d6a55aedd450a44..fc8f61630111083207d766495ecfb5d514ae21f8 100644 (file)
@@ -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 
index b30b4bdb8df4b9122ce38d192191bedabc6ede52..f9b0d99bf595d31d3d0b83cff4d8997ffd626d60 100644 (file)
@@ -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