The C reference states that a FILE*
opened in update mode ('+') needs to take the following two precautions:
- Output cannot be followed by input without a call to one of
fflush
,fseek
,fsetpos
, orrewind
. - Input cannot be followed by output wihout a call to one of
fseek
,fsetpos
, orrewind
.
I've learned that fflush
suffices to allow input after output, because a FILE*
opened in +
mode often uses the same buffer for read and write operations. As a result, not using fflush
before input might cause data to be mistakenly read from the buffer (which might not have been flushed, and thus contains data that still needs to be outputted).
However, in order for fseek
, fsetpos
, and rewind
to achieve the same effect, this implies they must internally flush the buffer of the stream passed to them.
Does the C standard require that fseek
, fsetpos
, and rewind
flush the buffer of their streams? If not, why not?