https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81751

--- Comment #5 from Volker Wehrs <bugzilla.volker at kabelmail dot de> ---
I'm sorry but I ignored the first if-clause in sys_open(). That if-clause makes
sure there is no open file referenced by the __basic_file, otherwise sys_open()
fails.

Then the sync() is called before the new __file is set, so in the current
implementation sync() can only see a _M_cfile set to NULL. Thus sync() is wrong
here.

Note that currently the new file (in __file) is implicitly flushed by the call
to fflush("NULL"), i.e. "flush all". So the new file should be sync'd
explicitly.

So sys_open() might look like this:

  __basic_file<char>*
  __basic_file<char>::sys_open(__c_file* __file, ios_base::openmode)
  {
    __basic_file* __ret = NULL;
    if (!this->is_open() && __file)
      {
        _M_cfile = __file;
        _M_cfile_created = false;
        __ret = this;
        this->sync();
      }
    return __ret;
  }

[...]

  int
  __basic_file<char>::sync()
  {
    int __err;
    do
      __err = fflush(_M_cfile);
    while ( __err && errno == EINTR );
    return __err;
  }

Reply via email to