]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
basic_file_stdio.cc (__gnu_internal::fopen_mode): New function.
authorBenjamin Kosnik <bkoz@redhat.com>
Thu, 5 Feb 2004 20:24:48 +0000 (20:24 +0000)
committerZack Weinberg <zack@gcc.gnu.org>
Thu, 5 Feb 2004 20:24:48 +0000 (20:24 +0000)
2004-02-04  Benjamin Kosnik  <bkoz@redhat.com>
    Zack Weinberg  <zack@codesourcery.com>

* config/io/basic_file_stdio.cc (__gnu_internal::fopen_mode):
New function.
(__basic_file<char>::sys_open, __basic_file<char>::open): Use it.
(__basic_file<char>::_M_open_mode): Use it.  Mark deprecated.

* testsuite/27_io/filebuf_members.cc (test_06, test_07):
Correct flags to filebuf::open calls.

From-SVN: r77340

libstdc++-v3/ChangeLog
libstdc++-v3/config/io/basic_file_stdio.cc
libstdc++-v3/testsuite/27_io/filebuf_members.cc

index fed0a597f1d1d6fdb553dd6a7721eef8cd5934fe..aaeb6e1419360378e9151f3ed99024ec9fd86f8d 100644 (file)
@@ -1,5 +1,16 @@
+2004-02-04  Benjamin Kosnik  <bkoz@redhat.com>
+           Zack Weinberg  <zack@codesourcery.com>
+
+       * config/io/basic_file_stdio.cc (__gnu_internal::fopen_mode):
+       New function.
+       (__basic_file<char>::sys_open, __basic_file<char>::open): Use it.
+       (__basic_file<char>::_M_open_mode): Use it.  Mark deprecated.
+
+       * testsuite/27_io/filebuf_members.cc (test_06, test_07):
+       Correct flags to filebuf::open calls.
+
 2004-01-29  Paolo Carlini  <pcarlini@suse.de>
-       
+
        PR libstdc++/12657
        * include/bits/basic_ios.tcc (copyfmt(const basic_ios&)):
        Implement resolution of DR 292 (WP).
@@ -69,7 +80,7 @@
        PR libstdc++/12540
        * config/locale/gnu/monetary_members.cc: Don't leak memory
        on exception.
-       
+
 2004-01-26  Andreas Schwab  <schwab@suse.de>
 
        * config/locale/gnu/monetary_members.cc: Restore locale before
 
 2004-01-07  Paolo Carlini  <pcarlini@suse.de>
            Petur Runolfsson  <peturr02@ru.is>
-       
+
        PR libstdc++/13007
        * include/bits/fstream.tcc (imbue): Don't touch the stored
        locale.
        LD_LIBRARY_PATH to both. Based on libjava.exp.
 
 2003-12-10  Benjamin Kosnik  <bkoz@redhat.com>
-            Alexandre Oliva  <aoliva@redhat.com>
-       
+           Alexandre Oliva  <aoliva@redhat.com>
+
        PR libstdc++/11612
        * testsuite/Makefile.am (GLIBCXX_DIR): New.
        (GLIBGCC_DIR): New.
        * include/bits/basic_ios.tcc: Tweak.
        * include/bits/fstream.tcc: Tweak.
        * include/bits/istream.tcc: Use _M_setstate for common exception
-       handling. Move setstate calls after catch. 
+       handling. Move setstate calls after catch.
        (basic_istream::tellg): Check for exceptions thrown by streambuf
        virtual functions.
        (basic_istream::seekg): Same.
        * include/bits/ostream.tcc: Same, but for ostream.
        (basic_ostream::flush): Check for exceptions thrown by streambuf
        virtual functions.
-       (basic_istream::tellp): Same.   
+       (basic_istream::tellp): Same.
        (basic_istream::seekp): Same.
        * include/bits/locale_facets.tcc: Tweak.
        * include/bits/streambuf.tcc: Tweak.
 
        PR libstdc++/12451
        * libsupc++/cxxabi.h: Move forward declaration of __class_type_info.
-       
+
 2003-10-01  Rainer Orth  <ro@TechFak.Uni-Bielefeld.DE>
 
        * configure.target: Handle Solaris 2.5 micro releases explicitly.
        returns eof.
 
 2003-09-30  Nathan Myers  <ncm@cantrip.org>
-            Paolo Carlini  <pcarlini@unitus.it>
+           Paolo Carlini  <pcarlini@unitus.it>
 
        PR libstdc++/11400
        * include/bits/stl_algo.h (search_n):
index 5393a1487a601867321afac7dd0049e5872a1321..476e11a5d9fdece70dc1862b4029a260b679ed8a 100644 (file)
@@ -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
 # 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 c873b366ade3ccd96cc4996086641a9adabc95d2..a504331a62aa29989b1b5fc4f8b180aec88bb14d 100644 (file)
@@ -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() );
 }