]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR libstdc++/17215 ([3.4 only] __basic_file<char>::close ignores errors)
authorPaolo Carlini <pcarlini@suse.de>
Mon, 8 Nov 2004 00:41:15 +0000 (00:41 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Mon, 8 Nov 2004 00:41:15 +0000 (00:41 +0000)
2004-11-07  Paolo Carlini  <pcarlini@suse.de>
    Andrea Arcangeli  <andrea@suse.de>

* config/io/basic_file_stdio.cc (__basic_file<>::close)): Don't
call unnecessarily sync, that is fflush: the library, since 3.4.0
does not use buffered fread/fwrite.
* include/bits/fstream.tcc (basic_filebuf<>::overflow): Likewise.

2004-11-07  Paolo Carlini  <pcarlini@suse.de>
    Kenneth C. Schalk  <ken@xorian.net>

PR libstdc++/17215
* config/io/basic_file_stdio.cc (__basic_file<char>::close()):
Check the return value of fclose/sync, loop on EINTR.
(__basic_file<char>::sys_open): Likewise, for sync.

Co-Authored-By: Andrea Arcangeli <andrea@suse.de>
Co-Authored-By: Kenneth C. Schalk <ken@xorian.net>
From-SVN: r90251

libstdc++-v3/ChangeLog
libstdc++-v3/config/io/basic_file_stdio.cc
libstdc++-v3/include/bits/fstream.tcc

index 6e4ddc090ce4eaea5411ee2837405768ebb0ce50..466b7b7bd34c8615c8ed5d8a56bb6e08ed5b40ad 100644 (file)
@@ -1,3 +1,19 @@
+2004-11-07  Paolo Carlini  <pcarlini@suse.de>
+           Andrea Arcangeli  <andrea@suse.de>
+
+       * config/io/basic_file_stdio.cc (__basic_file<>::close)): Don't
+       call unnecessarily sync, that is fflush: the library, since 3.4.0
+       does not use buffered fread/fwrite.
+       * include/bits/fstream.tcc (basic_filebuf<>::overflow): Likewise.
+
+2004-11-07  Paolo Carlini  <pcarlini@suse.de>
+           Kenneth C. Schalk  <ken@xorian.net>
+
+       PR libstdc++/17215
+       * config/io/basic_file_stdio.cc (__basic_file<char>::close()):
+       Check the return value of fclose/sync, loop on EINTR.
+       (__basic_file<char>::sys_open): Likewise, for sync.
+
 2004-11-04  Release Manager
 
        * GCC 3.4.3 released.
index a3ed8391bfffa194bd2aee22e00e2450850832be..0a4e154ebbc9c054c953cc076a27775ef08f33d6 100644 (file)
@@ -189,10 +189,17 @@ namespace std
     __basic_file* __ret = NULL;
     if (!this->is_open() && __file)
       {
-       _M_cfile = __file;
-       _M_cfile_created = false;
-       this->sync();
-       __ret = this;
+       int __err;
+       errno = 0;      
+       do
+         __err = this->sync();
+       while (__err && errno == EINTR);
+       if (!__err)
+         {
+           _M_cfile = __file;
+           _M_cfile_created = false;
+           __ret = this;
+         }
       }
     return __ret;
   }
@@ -252,12 +259,21 @@ namespace std
     __basic_file* __ret = static_cast<__basic_file*>(NULL);
     if (this->is_open())
       {
+       int __err = 0;
        if (_M_cfile_created)
-         fclose(_M_cfile);
-       else
-         this->sync();
+         {
+           // In general, no need to zero errno in advance if checking
+           // for error first. However, C89/C99 (at variance with IEEE
+           // 1003.1, f.i.) do not mandate that fclose must set errno
+           // upon error.
+           errno = 0;
+           do
+             __err = fclose(_M_cfile);
+           while (__err && errno == EINTR);
+         }
        _M_cfile = 0;
-       __ret = this;
+       if (!__err)
+         __ret = this;
       }
     return __ret;
   }
index a1ed485783ef50111a6142eb9de4bc1789f85a57..25a4d48cb7207c6093b64a16c29e1329c340b4b3 100644 (file)
@@ -396,8 +396,7 @@ namespace std
              // Convert pending sequence to external representation,
              // and output.
              if (_M_convert_to_external(this->pbase(),
-                                        this->pptr() - this->pbase())
-                 && (!__testeof || !_M_file.sync()))
+                                        this->pptr() - this->pbase()))
                {
                  _M_set_buffer(0);
                  __ret = traits_type::not_eof(__c);
@@ -792,7 +791,6 @@ namespace std
     {
       // Make sure that the internal buffer resyncs its idea of
       // the file position with the external file.
-      // NB: _M_file.sync() will be called within.
       int __ret = 0;
       if (this->pbase() < this->pptr())
        {