An open file has only one buffer, whether it was open for reading, writing, or both.
Section 7.21.5.3 of the C standard , which details the function fopen , states:
7 When a file is opened in update mode ( + as the second or third character in the above list of values โโof the mode argument), both inputs and outputs can be performed in the corresponding stream. However, the output should not directly follow the input without an intermediate fflush function or file positioning function ( fseek , fsetpo s, or rewind ), and the input should not be directly followed by output without an intermediate call to the file positioning function if the input operation does not meet the end of the file. Opening (or creating) a text file with update mode may instead open (or create) a binary stream in some implementations.
The paragraph above says that the output buffer must be flushed before performing the input (explicitly or implicitly using the positioning function), as well as when performing the output after input. This is a consequence of having only one buffer.
This also makes sense from a logical point of view, as it prevents reading and writing from reading due to an inconsistent presentation of the contents of the file.
dbush source share