From ce894603bf0d99149a4f109380b0e6552a24081b Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Mon, 30 Aug 2004 11:33:54 +0000 Subject: [PATCH] re PR libstdc++/17215 ([3.4 only] __basic_file::close ignores errors) 2004-08-30 Paolo Carlini Kenneth C. Schalk PR libstdc++/17215 * config/io/basic_file_stdio.cc (__basic_file::close()): Check the return value of fclose/sync, loop on EINTR. (__basic_file::sys_open): Likewise, for sync. Co-Authored-By: Kenneth C. Schalk From-SVN: r86756 --- libstdc++-v3/ChangeLog | 8 ++++++ libstdc++-v3/config/io/basic_file_stdio.cc | 32 +++++++++++++++++----- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index c7d3ba658f3..42385c2c422 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,11 @@ +2004-08-30 Paolo Carlini + Kenneth C. Schalk + + PR libstdc++/17215 + * config/io/basic_file_stdio.cc (__basic_file::close()): + Check the return value of fclose/sync, loop on EINTR. + (__basic_file::sys_open): Likewise, for sync. + 2004-08-29 Paolo Carlini * include/bits/locale_facets.tcc (time_get<>::_M_extract_via_format, diff --git a/libstdc++-v3/config/io/basic_file_stdio.cc b/libstdc++-v3/config/io/basic_file_stdio.cc index a3ed8391bff..680220bc4c5 100644 --- a/libstdc++-v3/config/io/basic_file_stdio.cc +++ b/libstdc++-v3/config/io/basic_file_stdio.cc @@ -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,23 @@ namespace std __basic_file* __ret = static_cast<__basic_file*>(NULL); if (this->is_open()) { + // 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/fflush must set + // errno upon error. + int __err; + errno = 0; if (_M_cfile_created) - fclose(_M_cfile); + do + __err = fclose(_M_cfile); + while (__err && errno == EINTR); else - this->sync(); + do + __err = this->sync(); + while (__err && errno == EINTR); + if (!__err) + __ret = this; _M_cfile = 0; - __ret = this; } return __ret; } -- 2.30.2