Title
Strange seekpos() semantics due to joint position
Status
cd1
Section
[filebuf.virtuals]
Submitter
Dietmar Kühl

Created on 1999-07-20.00:00:00 last changed 171 months ago

Messages

Date: 2010-10-21.18:28:33

[ Post-Tokyo: Dietmar supplied the above wording. ]

Date: 2010-10-21.18:28:33

[ Kona: Dietmar is working on a proposed resolution. ]

Date: 2010-10-21.18:28:33

Proposed resolution:

Change the unnumbered paragraph in 27.8.1.4 (lib.filebuf.virtuals) before paragraph 14 from:

pos_type seekpos(pos_type sp, ios_base::openmode = ios_base::in | ios_base::out);

Alters the file position, if possible, to correspond to the position stored in sp (as described below).

- if (which&ios_base::in)!=0, set the file position to sp, then update the input sequence

- if (which&ios_base::out)!=0, then update the output sequence, write any unshift sequence, and set the file position to sp.

to:

pos_type seekpos(pos_type sp, ios_base::openmode = ios_base::in | ios_base::out);

Alters the file position, if possible, to correspond to the position stored in sp (as described below). Altering the file position performs as follows:

1. if (om & ios_base::out)!=0, then update the output sequence and write any unshift sequence;

2. set the file position to sp;

3. if (om & ios_base::in)!=0, then update the input sequence;

where om is the open mode passed to the last call to open(). The operation fails if is_open() returns false.

Date: 1999-07-20.00:00:00

Overridden virtual functions, seekpos()

In [filebuf] paragraph 3, it is stated that a joint input and output position is maintained by basic_filebuf. Still, the description of seekpos() seems to talk about different file positions. In particular, it is unclear (at least to me) what is supposed to happen to the output buffer (if there is one) if only the input position is changed. The standard seems to mandate that the output buffer is kept and processed as if there was no positioning of the output position (by changing the input position). Of course, this can be exactly what you want if the flag ios_base::ate is set. However, I think, the standard should say something like this:

  • If (which & mode) == 0 neither read nor write position is changed and the call fails. Otherwise, the joint read and write position is altered to correspond to sp.
  • If there is an output buffer, the output sequences is updated and any unshift sequence is written before the position is altered.
  • If there is an input buffer, the input sequence is updated after the position is altered.

Plus the appropriate error handling, that is...

History
Date User Action Args
2010-10-21 18:28:33adminsetmessages: + msg1746
2010-10-21 18:28:33adminsetmessages: + msg1745
2010-10-21 18:28:33adminsetmessages: + msg1744
1999-07-20 00:00:00admincreate