public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Forcing fsync of ofstream with libstdc++-3?
@ 2004-02-25  5:16 Kenneth C. Schalk
  0 siblings, 0 replies; only message in thread
From: Kenneth C. Schalk @ 2004-02-25  5:16 UTC (permalink / raw)
  To: gcc-help

I'm trying to get some older C++ code to work correctly on Fedora Core
1, which uses gcc 3.3.2.  The application is a server designed to be
fault-tolerant.  It uses fstreams for writing files.  Under certain
circumstances, it needs to guarantee that some information has been
committed to disk.

With older C++ run-times, it would do something like:

  fsync(ofs.rdbuf()->fd())

But since the fd method was removed from the filebuf, that's no longer
an option.  It's no longer possible to construct an fstream from a
file descriptor or to attach an fstream to a file descriptor, so it's
not possible to get a fstream and a corresponding file descriptor that
way.  I've run a simple test program under strace, and I'm sure that
flushing an ofstream does *not* call fsync.

I'm aware of the __gnu_cxx::stdio_filebuf class, but I'd rather not
use that as I'd like to maintain portability to different compilers
and C++ run-times.

Essentially it looks to me as though my choices are:

- Write my own fstream-like class that allows me to force an fsync.

- Re-write significant pieces of code to use C stdio instead of C++
streams.

- Use temporary ostringstream objects to build up the bytes to be
written and then write them to the file using C stdio.

None of these particularly appeals to me, so I'm hoping someone can
suggest another reasonably portable option.

--Ken Schalk                            Vesta: Build Smarter
                                        www.vestasys.org

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-02-25  5:08 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-25  5:16 Forcing fsync of ofstream with libstdc++-3? Kenneth C. Schalk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).