This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Final patch for libstdc++ _M_open_mode and related


The only change from the previous revision of this patch is, I put
back a typo fix in the test cases that was in the original but got
dropped out by mistake in the first revision.  Oh, and as requested
the baseline-symbols.txt changes are dropped from the 3.4 patch.
ChangeLogs remain the same, mostly.

Bootstrapped i686-linux, applied 3.4 and mainline.  Gaby, OK for 3.3
branch?

zw

===================================================================
Index: config/abi/alpha-freebsd5/baseline_symbols.txt
--- config/abi/alpha-freebsd5/baseline_symbols.txt	24 Jun 2003 04:03:25 -0000	1.1
+++ config/abi/alpha-freebsd5/baseline_symbols.txt	5 Feb 2004 03:41:45 -0000
@@ -946,7 +946,6 @@ FUNC:_ZNSt11range_errorC2ERKSs@@GLIBCPP_
 FUNC:_ZNSt11range_errorD0Ev@@GLIBCPP_3.2
 FUNC:_ZNSt11range_errorD1Ev@@GLIBCPP_3.2
 FUNC:_ZNSt12__basic_fileIcE10sys_ungetcEi@@GLIBCPP_3.2
-FUNC:_ZNSt12__basic_fileIcE12_M_open_modeESt13_Ios_OpenmodeRiS2_Pc@@GLIBCPP_3.2
 FUNC:_ZNSt12__basic_fileIcE16showmanyc_helperEv@@GLIBCPP_3.2.3
 FUNC:_ZNSt12__basic_fileIcE2fdEv@@GLIBCPP_3.2
 FUNC:_ZNSt12__basic_fileIcE4openEPKcSt13_Ios_Openmodei@@GLIBCPP_3.2
===================================================================
Index: config/abi/alpha-linux-gnu/baseline_symbols.txt
--- config/abi/alpha-linux-gnu/baseline_symbols.txt	14 Jun 2003 05:38:02 -0000	1.1
+++ config/abi/alpha-linux-gnu/baseline_symbols.txt	5 Feb 2004 03:41:45 -0000
@@ -982,7 +982,6 @@ FUNC:_ZNSt11__timepunctIwED0Ev@@GLIBCPP_
 FUNC:_ZNSt11__timepunctIwED1Ev@@GLIBCPP_3.2
 FUNC:_ZNSt11__timepunctIwED2Ev@@GLIBCPP_3.2
 FUNC:_ZNSt12__basic_fileIcE10sys_ungetcEi@@GLIBCPP_3.2
-FUNC:_ZNSt12__basic_fileIcE12_M_open_modeESt13_Ios_OpenmodeRiS2_Pc@@GLIBCPP_3.2
 FUNC:_ZNSt12__basic_fileIcE2fdEv@@GLIBCPP_3.2
 FUNC:_ZNSt12__basic_fileIcE4openEPKcSt13_Ios_Openmodei@@GLIBCPP_3.2
 FUNC:_ZNSt12__basic_fileIcE4syncEv@@GLIBCPP_3.2
===================================================================
Index: config/abi/hppa-linux-gnu/baseline_symbols.txt
--- config/abi/hppa-linux-gnu/baseline_symbols.txt	18 Jul 2003 09:50:40 -0000	1.1
+++ config/abi/hppa-linux-gnu/baseline_symbols.txt	5 Feb 2004 03:41:46 -0000
@@ -946,7 +946,6 @@ FUNC:_ZNSt11range_errorC2ERKSs@@GLIBCPP_
 FUNC:_ZNSt11range_errorD0Ev@@GLIBCPP_3.2
 FUNC:_ZNSt11range_errorD1Ev@@GLIBCPP_3.2
 FUNC:_ZNSt12__basic_fileIcE10sys_ungetcEi@@GLIBCPP_3.2
-FUNC:_ZNSt12__basic_fileIcE12_M_open_modeESt13_Ios_OpenmodeRiS2_Pc@@GLIBCPP_3.2
 FUNC:_ZNSt12__basic_fileIcE16showmanyc_helperEv@@GLIBCPP_3.2.3
 FUNC:_ZNSt12__basic_fileIcE2fdEv@@GLIBCPP_3.2
 FUNC:_ZNSt12__basic_fileIcE4openEPKcSt13_Ios_Openmodei@@GLIBCPP_3.2
===================================================================
Index: config/abi/i386-freebsd4/baseline_symbols.txt
--- config/abi/i386-freebsd4/baseline_symbols.txt	24 Jun 2003 04:03:27 -0000	1.2
+++ config/abi/i386-freebsd4/baseline_symbols.txt	5 Feb 2004 03:41:46 -0000
@@ -553,7 +553,6 @@ FUNC:_ZNSt11range_errorC2ERKSs@@GLIBCPP_
 FUNC:_ZNSt11range_errorD0Ev@@GLIBCPP_3.2
 FUNC:_ZNSt11range_errorD1Ev@@GLIBCPP_3.2
 FUNC:_ZNSt12__basic_fileIcE10sys_ungetcEi@@GLIBCPP_3.2
-FUNC:_ZNSt12__basic_fileIcE12_M_open_modeESt13_Ios_OpenmodeRiS2_Pc@@GLIBCPP_3.2
 FUNC:_ZNSt12__basic_fileIcE16showmanyc_helperEv@@GLIBCPP_3.2.3
 FUNC:_ZNSt12__basic_fileIcE2fdEv@@GLIBCPP_3.2
 FUNC:_ZNSt12__basic_fileIcE4openEPKcSt13_Ios_Openmodei@@GLIBCPP_3.2
===================================================================
Index: config/abi/i386-freebsd5/baseline_symbols.txt
--- config/abi/i386-freebsd5/baseline_symbols.txt	24 Jun 2003 04:03:29 -0000	1.1
+++ config/abi/i386-freebsd5/baseline_symbols.txt	5 Feb 2004 03:41:47 -0000
@@ -946,7 +946,6 @@ FUNC:_ZNSt11range_errorC2ERKSs@@GLIBCPP_
 FUNC:_ZNSt11range_errorD0Ev@@GLIBCPP_3.2
 FUNC:_ZNSt11range_errorD1Ev@@GLIBCPP_3.2
 FUNC:_ZNSt12__basic_fileIcE10sys_ungetcEi@@GLIBCPP_3.2
-FUNC:_ZNSt12__basic_fileIcE12_M_open_modeESt13_Ios_OpenmodeRiS2_Pc@@GLIBCPP_3.2
 FUNC:_ZNSt12__basic_fileIcE16showmanyc_helperEv@@GLIBCPP_3.2.3
 FUNC:_ZNSt12__basic_fileIcE2fdEv@@GLIBCPP_3.2
 FUNC:_ZNSt12__basic_fileIcE4openEPKcSt13_Ios_Openmodei@@GLIBCPP_3.2
===================================================================
Index: config/abi/i486-linux-gnu/baseline_symbols.txt
--- config/abi/i486-linux-gnu/baseline_symbols.txt	17 Jun 2003 06:09:55 -0000	1.2
+++ config/abi/i486-linux-gnu/baseline_symbols.txt	5 Feb 2004 03:41:47 -0000
@@ -999,7 +999,6 @@ FUNC:_ZNSt11__timepunctIwED0Ev@@GLIBCPP_
 FUNC:_ZNSt11__timepunctIwED1Ev@@GLIBCPP_3.2
 FUNC:_ZNSt11__timepunctIwED2Ev@@GLIBCPP_3.2
 FUNC:_ZNSt12__basic_fileIcE10sys_ungetcEi@@GLIBCPP_3.2
-FUNC:_ZNSt12__basic_fileIcE12_M_open_modeESt13_Ios_OpenmodeRiS2_Pc@@GLIBCPP_3.2
 FUNC:_ZNSt12__basic_fileIcE16showmanyc_helperEv@@GLIBCPP_3.2.3
 FUNC:_ZNSt12__basic_fileIcE2fdEv@@GLIBCPP_3.2
 FUNC:_ZNSt12__basic_fileIcE4openEPKcSt13_Ios_Openmodei@@GLIBCPP_3.2
===================================================================
Index: config/abi/ia64-linux-gnu/baseline_symbols.txt
--- config/abi/ia64-linux-gnu/baseline_symbols.txt	14 Jun 2003 05:38:04 -0000	1.1
+++ config/abi/ia64-linux-gnu/baseline_symbols.txt	5 Feb 2004 03:41:47 -0000
@@ -982,7 +982,6 @@ FUNC:_ZNSt11__timepunctIwED0Ev@@GLIBCPP_
 FUNC:_ZNSt11__timepunctIwED1Ev@@GLIBCPP_3.2
 FUNC:_ZNSt11__timepunctIwED2Ev@@GLIBCPP_3.2
 FUNC:_ZNSt12__basic_fileIcE10sys_ungetcEi@@GLIBCPP_3.2
-FUNC:_ZNSt12__basic_fileIcE12_M_open_modeESt13_Ios_OpenmodeRiS2_Pc@@GLIBCPP_3.2
 FUNC:_ZNSt12__basic_fileIcE2fdEv@@GLIBCPP_3.2
 FUNC:_ZNSt12__basic_fileIcE4openEPKcSt13_Ios_Openmodei@@GLIBCPP_3.2
 FUNC:_ZNSt12__basic_fileIcE4syncEv@@GLIBCPP_3.2
===================================================================
Index: config/abi/mips-linux-gnu/baseline_symbols.txt
--- config/abi/mips-linux-gnu/baseline_symbols.txt	18 Jul 2003 09:50:40 -0000	1.1
+++ config/abi/mips-linux-gnu/baseline_symbols.txt	5 Feb 2004 03:41:47 -0000
@@ -946,7 +946,6 @@ FUNC:_ZNSt11range_errorC2ERKSs@@GLIBCPP_
 FUNC:_ZNSt11range_errorD0Ev@@GLIBCPP_3.2
 FUNC:_ZNSt11range_errorD1Ev@@GLIBCPP_3.2
 FUNC:_ZNSt12__basic_fileIcE10sys_ungetcEi@@GLIBCPP_3.2
-FUNC:_ZNSt12__basic_fileIcE12_M_open_modeESt13_Ios_OpenmodeRiS2_Pc@@GLIBCPP_3.2
 FUNC:_ZNSt12__basic_fileIcE16showmanyc_helperEv@@GLIBCPP_3.2.3
 FUNC:_ZNSt12__basic_fileIcE2fdEv@@GLIBCPP_3.2
 FUNC:_ZNSt12__basic_fileIcE4openEPKcSt13_Ios_Openmodei@@GLIBCPP_3.2
===================================================================
Index: config/abi/sparc-freebsd5/baseline_symbols.txt
--- config/abi/sparc-freebsd5/baseline_symbols.txt	24 Jun 2003 04:03:30 -0000	1.1
+++ config/abi/sparc-freebsd5/baseline_symbols.txt	5 Feb 2004 03:41:47 -0000
@@ -946,7 +946,6 @@ FUNC:_ZNSt11range_errorC2ERKSs@@GLIBCPP_
 FUNC:_ZNSt11range_errorD0Ev@@GLIBCPP_3.2
 FUNC:_ZNSt11range_errorD1Ev@@GLIBCPP_3.2
 FUNC:_ZNSt12__basic_fileIcE10sys_ungetcEi@@GLIBCPP_3.2
-FUNC:_ZNSt12__basic_fileIcE12_M_open_modeESt13_Ios_OpenmodeRiS2_Pc@@GLIBCPP_3.2
 FUNC:_ZNSt12__basic_fileIcE16showmanyc_helperEv@@GLIBCPP_3.2.3
 FUNC:_ZNSt12__basic_fileIcE2fdEv@@GLIBCPP_3.2
 FUNC:_ZNSt12__basic_fileIcE4openEPKcSt13_Ios_Openmodei@@GLIBCPP_3.2
===================================================================
Index: config/abi/sparc-linux-gnu/baseline_symbols.txt
--- config/abi/sparc-linux-gnu/baseline_symbols.txt	18 Jul 2003 09:50:41 -0000	1.1
+++ config/abi/sparc-linux-gnu/baseline_symbols.txt	5 Feb 2004 03:41:48 -0000
@@ -1005,7 +1005,6 @@ FUNC:_ZNSt11range_errorC2ERKSs@@GLIBCPP_
 FUNC:_ZNSt11range_errorD0Ev@@GLIBCPP_3.2
 FUNC:_ZNSt11range_errorD1Ev@@GLIBCPP_3.2
 FUNC:_ZNSt12__basic_fileIcE10sys_ungetcEi@@GLIBCPP_3.2
-FUNC:_ZNSt12__basic_fileIcE12_M_open_modeESt13_Ios_OpenmodeRiS2_Pc@@GLIBCPP_3.2
 FUNC:_ZNSt12__basic_fileIcE16showmanyc_helperEv@@GLIBCPP_3.2.3
 FUNC:_ZNSt12__basic_fileIcE2fdEv@@GLIBCPP_3.2
 FUNC:_ZNSt12__basic_fileIcE4openEPKcSt13_Ios_Openmodei@@GLIBCPP_3.2
===================================================================
Index: config/abi/x86_64-linux-gnu/baseline_symbols.txt
--- config/abi/x86_64-linux-gnu/baseline_symbols.txt	18 Jul 2003 13:24:44 -0000	1.3
+++ config/abi/x86_64-linux-gnu/baseline_symbols.txt	5 Feb 2004 03:41:48 -0000
@@ -946,7 +946,6 @@ FUNC:_ZNSt11range_errorC2ERKSs@@GLIBCPP_
 FUNC:_ZNSt11range_errorD0Ev@@GLIBCPP_3.2
 FUNC:_ZNSt11range_errorD1Ev@@GLIBCPP_3.2
 FUNC:_ZNSt12__basic_fileIcE10sys_ungetcEi@@GLIBCPP_3.2
-FUNC:_ZNSt12__basic_fileIcE12_M_open_modeESt13_Ios_OpenmodeRiS2_Pc@@GLIBCPP_3.2
 FUNC:_ZNSt12__basic_fileIcE16showmanyc_helperEv@@GLIBCPP_3.2.3
 FUNC:_ZNSt12__basic_fileIcE2fdEv@@GLIBCPP_3.2
 FUNC:_ZNSt12__basic_fileIcE4openEPKcSt13_Ios_Openmodei@@GLIBCPP_3.2
===================================================================
Index: config/io/basic_file_stdio.cc
--- config/io/basic_file_stdio.cc	10 Dec 2003 17:37:22 -0000	1.25
+++ config/io/basic_file_stdio.cc	5 Feb 2004 03:41:48 -0000
@@ -1,6 +1,6 @@
 // Wrapper of C-language FILE struct -*- C++ -*-
 
-// Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+// Copyright (C) 2000, 2001, 2002, 2003, 2004 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
@@ -70,6 +70,43 @@
 
 #include <limits> // For <off_t>::max() and min()
 
+namespace __gnu_internal
+{
+  // Map ios_base::openmode flags to a string for use in fopen().
+  // Table of valid combinations as given in [lib.filebuf.members]/2.
+  static const char*
+  fopen_mode(std::ios_base::openmode mode)
+  {
+    enum 
+      {
+	in     = std::ios_base::in,
+	out    = std::ios_base::out,
+	trunc  = std::ios_base::trunc,
+	app    = std::ios_base::app,
+	binary = std::ios_base::binary
+      };
+    
+    switch (mode & (in|out|trunc|app|binary))
+      {
+      case (   out                 ): return "w";  
+      case (   out      |app       ): return "a";  
+      case (   out|trunc           ): return "w";  
+      case (in                     ): return "r";  
+      case (in|out                 ): return "r+"; 
+      case (in|out|trunc           ): return "w+"; 
+	
+      case (   out          |binary): return "wb"; 
+      case (   out      |app|binary): return "ab"; 
+      case (   out|trunc    |binary): return "wb"; 
+      case (in              |binary): return "rb"; 
+      case (in|out          |binary): return "r+b";
+      case (in|out|trunc    |binary): return "w+b";
+	
+      default: return 0; // invalid
+      }
+  }
+} // namespace __gnu_internal
+
 namespace std 
 {
   // Definitions for __basic_file<char>.
@@ -79,53 +116,6 @@ namespace std 
   __basic_file<char>::~__basic_file()
   { this->close(); }
       
-  void 
-  __basic_file<char>::_M_open_mode(ios_base::openmode __mode, int& __p_mode, 
-				   int&, char* __c_mode)
-  {  
-    bool __testb = __mode & ios_base::binary;
-    bool __testi = __mode & ios_base::in;
-    bool __testo = __mode & ios_base::out;
-    bool __testt = __mode & ios_base::trunc;
-    bool __testa = __mode & ios_base::app;
-      
-    // Set __c_mode for use in fopen.
-    // Set __p_mode for use in open.
-    if (!__testi && __testo && !__testt && !__testa)
-      {
-	strcpy(__c_mode, "w");
-	__p_mode = O_WRONLY | O_CREAT;
-      }
-    if (!__testi && __testo && !__testt && __testa)
-      {
-	strcpy(__c_mode, "a");
-	__p_mode = O_WRONLY | O_CREAT | O_APPEND;
-      }
-    if (!__testi && __testo && __testt && !__testa)
-      {
-	strcpy(__c_mode, "w");
-	__p_mode = O_WRONLY | O_CREAT | O_TRUNC;
-      }
-
-    if (__testi && !__testo && !__testt && !__testa)
-      {
-	strcpy(__c_mode, "r");
-	__p_mode = O_RDONLY;
-      }
-    if (__testi && __testo && !__testt && !__testa)
-      {
-	strcpy(__c_mode, "r+");
-	__p_mode = O_RDWR | O_CREAT;
-      }
-    if (__testi && __testo && __testt && !__testa)
-      {
-	strcpy(__c_mode, "w+");
-	__p_mode = O_RDWR | O_CREAT | O_TRUNC;
-      }
-    if (__testb)
-      strcat(__c_mode, "b");
-  }
-  
   __basic_file<char>*
   __basic_file<char>::sys_open(__c_file* __file, ios_base::openmode) 
   {
@@ -144,12 +134,9 @@ namespace std 
   __basic_file<char>::sys_open(int __fd, ios_base::openmode __mode)
   {
     __basic_file* __ret = NULL;
-    int __p_mode = 0;
-    int __rw_mode = 0;
-    char __c_mode[4];
-    
-    _M_open_mode(__mode, __p_mode, __rw_mode, __c_mode);
-    if (!this->is_open() && (_M_cfile = fdopen(__fd, __c_mode)))
+    const char* __c_mode = __gnu_internal::fopen_mode(__mode);
+    if (__c_mode && !this->is_open() 
+	&& (_M_cfile = fdopen(__fd, __c_mode)))
       {
 	_M_cfile_created = true;
 	if (__fd == 0)
@@ -164,13 +151,8 @@ namespace std 
 			   int /*__prot*/)
   {
     __basic_file* __ret = NULL;
-    int __p_mode = 0;
-    int __rw_mode = 0;
-    char __c_mode[4];
-      
-    _M_open_mode(__mode, __p_mode, __rw_mode, __c_mode);
-
-    if (!this->is_open())
+    const char* __c_mode = __gnu_internal::fopen_mode(__mode);
+    if (__c_mode && !this->is_open())
       {
 #ifdef _GLIBCXX_USE_LFS
 	if ((_M_cfile = fopen64(__name, __c_mode)))
@@ -309,5 +291,4 @@ namespace std 
 #endif
     return 0;
   }
-
 }  // namespace std
===================================================================
Index: config/io/basic_file_stdio.h
--- config/io/basic_file_stdio.h	7 Dec 2003 03:46:13 -0000	1.16
+++ config/io/basic_file_stdio.h	5 Feb 2004 03:41:48 -0000
@@ -1,6 +1,6 @@
 // Wrapper of C-language FILE struct -*- C++ -*-
 
-// Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+// Copyright (C) 2000, 2001, 2002, 2003, 2004 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
@@ -62,11 +62,7 @@ namespace std 
 
     public:
       __basic_file(__c_lock* __lock = 0);
-      
-      void 
-      _M_open_mode(ios_base::openmode __mode, int& __p_mode, int& __rw_mode, 
-		   char* __c_mode);
-      
+
       __basic_file* 
       open(const char* __name, ios_base::openmode __mode, int __prot = 0664);
 
===================================================================
Index: testsuite/27_io/basic_filebuf/close/char/9964.cc
--- testsuite/27_io/basic_filebuf/close/char/9964.cc	12 Jan 2004 08:11:05 -0000	1.5
+++ testsuite/27_io/basic_filebuf/close/char/9964.cc	5 Feb 2004 03:41:48 -0000
@@ -59,7 +59,7 @@ void test_07()
   
   filebuf fb;
   sleep(1);
-  filebuf* ret = fb.open(name, ios_base::out | ios_base::trunc);
+  filebuf* ret = fb.open(name, ios_base::in | ios_base::out);
   VERIFY( ret != NULL );
   VERIFY( fb.is_open() );
 
@@ -67,7 +67,7 @@ void test_07()
   fb.sputc('a');
 
   ret = fb.close();
-  VERIFY( ret == NULL );
+  VERIFY( ret != NULL );
   VERIFY( !fb.is_open() );
 }
 
===================================================================
Index: testsuite/27_io/basic_filebuf/open/char/9507.cc
--- testsuite/27_io/basic_filebuf/open/char/9507.cc	12 Jan 2004 08:11:07 -0000	1.4
+++ testsuite/27_io/basic_filebuf/open/char/9507.cc	5 Feb 2004 03:41:48 -0000
@@ -53,7 +53,10 @@ void test_06()
     }
 
   std::filebuf fbuf;
-  std::filebuf* r = fbuf.open(name, std::ios_base::out | std::ios_base::ate);
+  std::filebuf* r = fbuf.open(name,
+			      std::ios_base::in 
+			      | std::ios_base::out
+			      | std::ios_base::ate);
   VERIFY( !fbuf.is_open() );
   VERIFY( r == NULL );
 }
===================================================================
Index: config/io/basic_file_stdio.cc
--- config/io/basic_file_stdio.cc	10 Dec 2003 17:37:22 -0000	1.25
+++ config/io/basic_file_stdio.cc	5 Feb 2004 03:42:22 -0000
@@ -1,6 +1,6 @@
 // Wrapper of C-language FILE struct -*- C++ -*-
 
-// Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+// Copyright (C) 2000, 2001, 2002, 2003, 2004 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
@@ -70,6 +70,43 @@
 
 #include <limits> // For <off_t>::max() and min()
 
+namespace __gnu_internal
+{
+  // Map ios_base::openmode flags to a string for use in fopen().
+  // Table of valid combinations as given in [lib.filebuf.members]/2.
+  static const char*
+  fopen_mode(std::ios_base::openmode mode)
+  {
+    enum 
+      {
+	in     = std::ios_base::in,
+	out    = std::ios_base::out,
+	trunc  = std::ios_base::trunc,
+	app    = std::ios_base::app,
+	binary = std::ios_base::binary
+      };
+    
+    switch (mode & (in|out|trunc|app|binary))
+      {
+      case (   out                 ): return "w";  
+      case (   out      |app       ): return "a";  
+      case (   out|trunc           ): return "w";  
+      case (in                     ): return "r";  
+      case (in|out                 ): return "r+"; 
+      case (in|out|trunc           ): return "w+"; 
+	
+      case (   out          |binary): return "wb"; 
+      case (   out      |app|binary): return "ab"; 
+      case (   out|trunc    |binary): return "wb"; 
+      case (in              |binary): return "rb"; 
+      case (in|out          |binary): return "r+b";
+      case (in|out|trunc    |binary): return "w+b";
+	
+      default: return 0; // invalid
+      }
+  }
+} // namespace __gnu_internal
+
 namespace std 
 {
   // Definitions for __basic_file<char>.
@@ -79,53 +116,6 @@ namespace std 
   __basic_file<char>::~__basic_file()
   { this->close(); }
       
-  void 
-  __basic_file<char>::_M_open_mode(ios_base::openmode __mode, int& __p_mode, 
-				   int&, char* __c_mode)
-  {  
-    bool __testb = __mode & ios_base::binary;
-    bool __testi = __mode & ios_base::in;
-    bool __testo = __mode & ios_base::out;
-    bool __testt = __mode & ios_base::trunc;
-    bool __testa = __mode & ios_base::app;
-      
-    // Set __c_mode for use in fopen.
-    // Set __p_mode for use in open.
-    if (!__testi && __testo && !__testt && !__testa)
-      {
-	strcpy(__c_mode, "w");
-	__p_mode = O_WRONLY | O_CREAT;
-      }
-    if (!__testi && __testo && !__testt && __testa)
-      {
-	strcpy(__c_mode, "a");
-	__p_mode = O_WRONLY | O_CREAT | O_APPEND;
-      }
-    if (!__testi && __testo && __testt && !__testa)
-      {
-	strcpy(__c_mode, "w");
-	__p_mode = O_WRONLY | O_CREAT | O_TRUNC;
-      }
-
-    if (__testi && !__testo && !__testt && !__testa)
-      {
-	strcpy(__c_mode, "r");
-	__p_mode = O_RDONLY;
-      }
-    if (__testi && __testo && !__testt && !__testa)
-      {
-	strcpy(__c_mode, "r+");
-	__p_mode = O_RDWR | O_CREAT;
-      }
-    if (__testi && __testo && __testt && !__testa)
-      {
-	strcpy(__c_mode, "w+");
-	__p_mode = O_RDWR | O_CREAT | O_TRUNC;
-      }
-    if (__testb)
-      strcat(__c_mode, "b");
-  }
-  
   __basic_file<char>*
   __basic_file<char>::sys_open(__c_file* __file, ios_base::openmode) 
   {
@@ -144,12 +134,9 @@ namespace std 
   __basic_file<char>::sys_open(int __fd, ios_base::openmode __mode)
   {
     __basic_file* __ret = NULL;
-    int __p_mode = 0;
-    int __rw_mode = 0;
-    char __c_mode[4];
-    
-    _M_open_mode(__mode, __p_mode, __rw_mode, __c_mode);
-    if (!this->is_open() && (_M_cfile = fdopen(__fd, __c_mode)))
+    const char* __c_mode = __gnu_internal::fopen_mode(__mode);
+    if (__c_mode && !this->is_open() 
+	&& (_M_cfile = fdopen(__fd, __c_mode)))
       {
 	_M_cfile_created = true;
 	if (__fd == 0)
@@ -164,13 +151,8 @@ namespace std 
 			   int /*__prot*/)
   {
     __basic_file* __ret = NULL;
-    int __p_mode = 0;
-    int __rw_mode = 0;
-    char __c_mode[4];
-      
-    _M_open_mode(__mode, __p_mode, __rw_mode, __c_mode);
-
-    if (!this->is_open())
+    const char* __c_mode = __gnu_internal::fopen_mode(__mode);
+    if (__c_mode && !this->is_open())
       {
 #ifdef _GLIBCXX_USE_LFS
 	if ((_M_cfile = fopen64(__name, __c_mode)))
@@ -309,5 +291,4 @@ namespace std 
 #endif
     return 0;
   }
-
 }  // namespace std
===================================================================
Index: config/io/basic_file_stdio.h
--- config/io/basic_file_stdio.h	7 Dec 2003 03:46:13 -0000	1.16
+++ config/io/basic_file_stdio.h	5 Feb 2004 03:42:22 -0000
@@ -1,6 +1,6 @@
 // Wrapper of C-language FILE struct -*- C++ -*-
 
-// Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+// Copyright (C) 2000, 2001, 2002, 2003, 2004 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
@@ -62,11 +62,7 @@ namespace std 
 
     public:
       __basic_file(__c_lock* __lock = 0);
-      
-      void 
-      _M_open_mode(ios_base::openmode __mode, int& __p_mode, int& __rw_mode, 
-		   char* __c_mode);
-      
+
       __basic_file* 
       open(const char* __name, ios_base::openmode __mode, int __prot = 0664);
 
===================================================================
Index: testsuite/27_io/basic_filebuf/close/char/9964.cc
--- testsuite/27_io/basic_filebuf/close/char/9964.cc	12 Jan 2004 08:11:05 -0000	1.5
+++ testsuite/27_io/basic_filebuf/close/char/9964.cc	5 Feb 2004 03:42:23 -0000
@@ -59,7 +59,7 @@ void test_07()
   
   filebuf fb;
   sleep(1);
-  filebuf* ret = fb.open(name, ios_base::out | ios_base::trunc);
+  filebuf* ret = fb.open(name, ios_base::in | ios_base::out);
   VERIFY( ret != NULL );
   VERIFY( fb.is_open() );
 
@@ -67,7 +67,7 @@ void test_07()
   fb.sputc('a');
 
   ret = fb.close();
-  VERIFY( ret == NULL );
+  VERIFY( ret != NULL );
   VERIFY( !fb.is_open() );
 }
 
===================================================================
Index: testsuite/27_io/basic_filebuf/open/char/9507.cc
--- testsuite/27_io/basic_filebuf/open/char/9507.cc	12 Jan 2004 08:11:07 -0000	1.4
+++ testsuite/27_io/basic_filebuf/open/char/9507.cc	5 Feb 2004 03:42:23 -0000
@@ -53,7 +53,10 @@ void test_06()
     }
 
   std::filebuf fbuf;
-  std::filebuf* r = fbuf.open(name, std::ios_base::out | std::ios_base::ate);
+  std::filebuf* r = fbuf.open(name,
+			      std::ios_base::in 
+			      | std::ios_base::out
+			      | std::ios_base::ate);
   VERIFY( !fbuf.is_open() );
   VERIFY( r == NULL );
 }
===================================================================
Index: libstdc++-v3/config/io/basic_file_stdio.cc
--- libstdc++-v3/config/io/basic_file_stdio.cc	21 Jun 2003 15:47:41 -0000	1.6.2.5
+++ libstdc++-v3/config/io/basic_file_stdio.cc	5 Feb 2004 03:43:39 -0000
@@ -1,6 +1,6 @@
 // Wrapper of C-language FILE struct -*- C++ -*-
 
-// Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
+// Copyright (C) 2000, 2001, 2002, 2004 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
@@ -58,6 +58,43 @@
 # endif
 #endif
 
+namespace __gnu_internal
+{
+  // Map ios_base::openmode flags to a string for use in fopen().
+  // Table of valid combinations as given in [lib.filebuf.members]/2.
+  static const char*
+  fopen_mode(std::ios_base::openmode mode)
+  {
+    enum 
+      {
+	in     = std::ios_base::in,
+	out    = std::ios_base::out,
+	trunc  = std::ios_base::trunc,
+	app    = std::ios_base::app,
+	binary = std::ios_base::binary
+      };
+    
+    switch (mode & (in|out|trunc|app|binary))
+      {
+      case (   out                 ): return "w";  
+      case (   out      |app       ): return "a";  
+      case (   out|trunc           ): return "w";  
+      case (in                     ): return "r";  
+      case (in|out                 ): return "r+"; 
+      case (in|out|trunc           ): return "w+"; 
+	
+      case (   out          |binary): return "wb"; 
+      case (   out      |app|binary): return "ab"; 
+      case (   out|trunc    |binary): return "wb"; 
+      case (in              |binary): return "rb"; 
+      case (in|out          |binary): return "r+b";
+      case (in|out|trunc    |binary): return "w+b";
+	
+      default: return 0; // invalid
+      }
+  }
+} // namespace __gnu_internal
+
 namespace std 
 {
   // Definitions for __basic_file<char>.
@@ -66,52 +103,16 @@ namespace std 
 
   __basic_file<char>::~__basic_file()
   { this->close(); }
-      
-  void 
-  __basic_file<char>::_M_open_mode(ios_base::openmode __mode, int& __p_mode, 
-				   int&, char* __c_mode)
-  {  
-    bool __testb = __mode & ios_base::binary;
-    bool __testi = __mode & ios_base::in;
-    bool __testo = __mode & ios_base::out;
-    bool __testt = __mode & ios_base::trunc;
-    bool __testa = __mode & ios_base::app;
-      
-    // Set __c_mode for use in fopen.
-    // Set __p_mode for use in open.
-    if (!__testi && __testo && !__testt && !__testa)
-      {
-	strcpy(__c_mode, "w");
-	__p_mode = (O_WRONLY | O_CREAT);
-      }
-    if (!__testi && __testo && !__testt && __testa)
-      {
-	strcpy(__c_mode, "a");
-	__p_mode |=  O_WRONLY | O_CREAT | O_APPEND;
-      }
-    if (!__testi && __testo && __testt && !__testa)
-      {
-	strcpy(__c_mode, "w");
-	__p_mode |=  O_WRONLY | O_CREAT | O_TRUNC;
-      }
 
-    if (__testi && !__testo && !__testt && !__testa)
-      {
-	strcpy(__c_mode, "r");
-	__p_mode |=  O_RDONLY;
-      }
-    if (__testi && __testo && !__testt && !__testa)
-      {
-	strcpy(__c_mode, "r+");
-	__p_mode |=  O_RDWR | O_CREAT;
-      }
-    if (__testi && __testo && __testt && !__testa)
-      {
-	strcpy(__c_mode, "w+");
-	__p_mode |=  O_RDWR | O_CREAT | O_TRUNC;
-      }
-    if (__testb)
-      strcat(__c_mode, "b");
+  // Preserved for binary compatibility only.
+  // Do not use.  Gone in 3.4.
+  void 
+  __basic_file<char>::_M_open_mode(ios_base::openmode __mode, int&, int&,
+				   char* __c_mode)
+  {
+    const char* r = __gnu_internal::fopen_mode(__mode);
+    if (r)
+      strcpy(__c_mode, r);
   }
   
   __basic_file<char>*
@@ -132,12 +133,9 @@ namespace std 
 			       bool __del) 
   {
     __basic_file* __ret = NULL;
-    int __p_mode = 0;
-    int __rw_mode = 0;
-    char __c_mode[4];
-    
-    _M_open_mode(__mode, __p_mode, __rw_mode, __c_mode);
-    if (!this->is_open() && (_M_cfile = fdopen(__fd, __c_mode)))
+    const char* __c_mode = __gnu_internal::fopen_mode(__mode);
+    if (__c_mode && !this->is_open() 
+	&& (_M_cfile = fdopen(__fd, __c_mode)))
       {
 	// Iff __del is true, then close will fclose the fd.
 	_M_cfile_created = __del;
@@ -163,13 +161,8 @@ namespace std 
 			   int /*__prot*/)
   {
     __basic_file* __ret = NULL;
-    int __p_mode = 0;
-    int __rw_mode = 0;
-    char __c_mode[4];
-      
-    _M_open_mode(__mode, __p_mode, __rw_mode, __c_mode);
-
-    if (!this->is_open())
+    const char* __c_mode = __gnu_internal::fopen_mode(__mode);
+    if (__c_mode && !this->is_open())
       {
 	if ((_M_cfile = fopen(__name, __c_mode)))
 	  {
===================================================================
Index: libstdc++-v3/testsuite/27_io/filebuf_members.cc
--- libstdc++-v3/testsuite/27_io/filebuf_members.cc	22 Apr 2003 21:07:24 -0000	1.16.20.4
+++ libstdc++-v3/testsuite/27_io/filebuf_members.cc	5 Feb 2004 03:43:39 -0000
@@ -217,7 +217,10 @@ void test_06()
     }
 
   std::filebuf fbuf;
-  std::filebuf* r = fbuf.open(name, std::ios_base::out | std::ios_base::ate);
+  std::filebuf* r = fbuf.open(name,
+			      std::ios_base::in
+			      | std::ios_base::out
+			      | std::ios_base::ate);
   VERIFY( !fbuf.is_open() );
   VERIFY( r == NULL );
 }
@@ -249,7 +252,7 @@ void test_07()
   
   filebuf fb;
   sleep(1);
-  filebuf* ret = fb.open(name, ios_base::out | ios_base::trunc);
+  filebuf* ret = fb.open(name, ios_base::in | ios_base::out);
   VERIFY( ret != NULL );
   VERIFY( fb.is_open() );
 
@@ -257,7 +260,7 @@ void test_07()
   fb.sputc('a');
 
   ret = fb.close();
-  VERIFY( ret == NULL );
+  VERIFY( ret != NULL );
   VERIFY( !fb.is_open() );
 }
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]