don't sync() on an fstream at EOF

K

kartik

I open an fstream in read-only mode, read till the end, then try to
sync() before seeking to position 0 & reading again. But the sync
fails. I discovered that clear()ing the stream before the sync causes
the sync to work. Seeking to position 0 before the sync doesn't seem
to help.

If you look at sync() as simply invalidating the read buffer (isn't
that right?), isn't it illogical for it to fail in this situation?

Besides sync() doesn't flush the write buffer (on a read-write
stream), does it? Similarly, flush() doesn't invalidate the read
buffer, does it?

I'm using g++ 3.3.2 on Mandrake Linux 10; kernel 2.6.

-kartik
 
J

Jack Klein

I open an fstream in read-only mode, read till the end, then try to
sync() before seeking to position 0 & reading again. But the sync
fails. I discovered that clear()ing the stream before the sync causes
the sync to work. Seeking to position 0 before the sync doesn't seem
to help.

If you look at sync() as simply invalidating the read buffer (isn't
that right?), isn't it illogical for it to fail in this situation?

Besides sync() doesn't flush the write buffer (on a read-write
stream), does it? Similarly, flush() doesn't invalidate the read
buffer, does it?

I'm using g++ 3.3.2 on Mandrake Linux 10; kernel 2.6.

-kartik

Attempting to read past the end of file sets the fail bit on the
stream. All operations on the stream, including sync(), will fail
until clear() is used to remove the fail bit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,252
Latest member
MeredithPl

Latest Threads

Top