linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steve Graegert <graegerts@gmail.com>
To: linux-c-programming@vger.kernel.org
Cc: Hareesh Nagarajan <hareesh.nagarajan@gmail.com>
Subject: Re: Forcing fsync() using an ouput stream in C++
Date: Thu, 3 Mar 2005 09:15:00 +0100	[thread overview]
Message-ID: <6a00c8d50503030015237d9844@mail.gmail.com> (raw)
In-Reply-To: <7728232c05030222384c65f341@mail.gmail.com>

On Thu, 3 Mar 2005 00:38:10 -0600, Hareesh Nagarajan
<hareesh.nagarajan@gmail.com> wrote:
> Hi,
> 
> I am aware this is a C-programming mailing list. I just thought I
> might get some useful inputs from this ML.
> 
> My problem is that I haven't figured out how I must fsync an output
> stream (in C++) even after reading the contents of this link:
> http://gcc.gnu.org/ml/gcc-help/2004-02/msg00285.html
> 
> How must I modify this method (this method doesn't work; it prints the
> error message and exits!) ?
> 
> void logRecovery::syncToDisk(fstream& f)
> {
>    unix_filebuf_t* buf;
>    buf = dynamic_cast<unix_filebuf_t*>(f.rdbuf());
>    if (buf == NULL) {
>        cerr << "Fatal: Don't know fd of stream" << endl;
>        exit(-1);
>    }
> 
>    fsync(buf->fd());
> }
> 
> I am using GCC 3.3.4.
> 
> Thanks,
> 
> Hareesh
> -
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

I have actually now idea why you are using unix_filebuf_t. Why not
simply call f.flush()? If you need to obtain a reference to the
streambuf object associated with a stream you can call f.readbuf() and
then do a sync, like this:

streambuf *buf;
buf = f.readbuf();
buf->sync();

May be I get you wrong, but hope this helps.

-- 
Kind Regards

    \Steve

      reply	other threads:[~2005-03-03  8:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-03  6:38 Forcing fsync() using an ouput stream in C++ Hareesh Nagarajan
2005-03-03  8:15 ` Steve Graegert [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6a00c8d50503030015237d9844@mail.gmail.com \
    --to=graegerts@gmail.com \
    --cc=hareesh.nagarajan@gmail.com \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).