This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: ofstream, fsync and data loss bugs
> On Wed, Mar 17, 2010 at 04:11:16PM -0700, Pavel Sanda wrote:
> > > The new C++ standard acknowledges the existence of POSIX and the
> > > threading components provide implementation-defined ways to access
> > > non-portable native handles, it's a shame we didn't revisit iostreams
> > > to do something similar. I don't have a good answer, and it's too late
> > > to deal with it for C++1x.
> >
> > Isn't possible that C++ standard could be interpreted in the way that
> > you are free to use fsync() inside close() implementation?
>
> Are you suggesting putting an fsync() in every close()?
I'm rather mapping out the terrain for something like
ofstream ofs(filename, ios::out|ios::trunc|ios::fsync);
> It seems that there should be a Posix extension to C++ that would
> provide a way to get the Posix file descriptor corresponding to
> an fstream.
The holy grail would be to have the possibility to write portable
code without need to distinguish between win/posix environments.
If the answer for this problem is for unix envi only then I can
directly write ifdefed plain C routine which after each stream
closing do fopen/fsync/fclose... or stop to use fstream completely.
Pavel