At n1256 7.19.5.2 paragraph 2 (with my bold):
If stream points to an output stream or an update stream in which the most recent operation was not input, the fflush function causes any unwritten data for that stream to be delivered to the host environment to be written to the file; otherwise, the behavior is undefined.
If there was not the word 'update stream', the whole paragraph would make sense. But I don't know what it is. Standard itself doesn't introduce it. Google search doesn't seem to work. What's the meaning of it?
The term "update stream" simply means a stream that is both readable and writable.
This is specified in §7.19.5.3 point 3 (link, bold mine):
#include <stdio.h> FILE *fopen(const char * restrict filename,const char * restrict mode);[...]
The argument mode points to a string. If the string is one of the following, the file is open in the indicated mode. Otherwise, the behavior is undefined(237).
r: open text file for readingw: truncate to zero length or create text file for writinga: append; open or create text file for writing at end-of-filerb: open binary file for readingwb: truncate to zero length or create binary file for writingab: append; open or create binary file for writing at end-of-filer+: open text file for update (reading and writing)w+: truncate to zero length or create text file for updatea+: append; open or create text file for update, writing at end-of-file(237)r+borrb+: open binary file for update (reading and writing)w+borwb+: truncate to zero length or create binary file for updatea+borab+: append; open or create binary file for update, writing at end-of-file(237) If the string begins with one of the above sequences, the implementation might choose to ignore the remaining characters, or it might use them to select different kinds of a file (some of which might not conform to the properties in 7.19.2).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With