Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

basic_streambuf::seekoff what should be returned when ios_base::in | ios_base::out is specified?

27.6.3.4.2 Buffer management and positioning

pos_type seekoff(off_type off, ios_base::seekdir way,
    ios_base::openmode which = ios_base::in | ios_base::out);
  • Effects: Alters the stream positions within one or more of the controlled sequences in a way that is defined separately for each class derived from basic_streambuf in this Clause (27.8.2.4, 27.9.1.5).
  • Default behavior: Returns pos_type(off_type(-1)).

So far, so good. The basic_streambuf derivation I'm using can alter its position separately for ios_base::in and/or ios_base::out. But, what do I need to return when both are specified?

If you specify ios_base::in or ios_base::out, we would return new stream position of the specific sequence.

like image 707
0xbadf00d Avatar asked Jul 23 '11 13:07

0xbadf00d


1 Answers

It is a bit up to your stream to define what happens. The built in streams differ, in that some can have separate read and write positions (stringstream) while others just have one (fstream).

If the user does a reposition and specify both in and out, perhaps you should move both. If it is a seek with a zero offset to get the current position, it is not unreasonable to fail if the positions differ.

like image 147
Bo Persson Avatar answered Sep 22 '22 15:09

Bo Persson