default value of streambuf for new areas of a filebuf

C

Clark Sims

I have this code fragment in a lot of my programs:
std::filebuf _fbuf;
....
_fbuf.pubseekoff( _initial_number_pages*_page_size - 1, std::ios_base::beg);
_fbuf.sputc(0);
_fbuf.pubsync();

I have noticed that the new areas of the file, are always set to the null character.

Is this behavior defined by some standard, or is this just a quirk of the systems I have been using.

Thanks in Advance,

Clark
 
B

Bo Persson

Clark Sims wrote 2012-06-24 17:46:
I have this code fragment in a lot of my programs:
std::filebuf _fbuf;
...
_fbuf.pubseekoff( _initial_number_pages*_page_size - 1, std::ios_base::beg);
_fbuf.sputc(0);
_fbuf.pubsync();

I have noticed that the new areas of the file, are always set to the null character.

Is this behavior defined by some standard, or is this just a quirk of the systems I have been using.


This seems to be a POSIX extension to the C standard fseek() function,
likely used to implement the C++ file seek.

"The fseek() function shall allow the file-position indicator to be set
beyond the end of existing data in the file. If data is later written at
this point, subsequent reads of data in the gap shall return bytes with
the value 0 until data is actually written into the gap."

http://pubs.opengroup.org/onlinepubs/009696699/functions/fseek.html


Bo Persson
 
C

Clark Sims

OK, so I guess the standards dictate what the C++ read functions will do, but they don't dictate what is actually in the file.

The methods I am using to look at the file, are all kernel bypass, so the read functions are never called.

I guess someone took it upon themselves to make the write "non-lazy" and actually fill in the file with 0's, but that I shouldn't necessarily assume this is part of any standard.
 

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,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top