Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is an update stream in C?

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?

like image 638
op ol Avatar asked Nov 15 '25 07:11

op ol


1 Answers

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 reading
  • w: truncate to zero length or create text file for writing
  • a: append; open or create text file for writing at end-of-file
  • rb: open binary file for reading
  • wb: truncate to zero length or create binary file for writing
  • ab: append; open or create binary file for writing at end-of-file
  • r+: open text file for update (reading and writing)
  • w+: truncate to zero length or create text file for update
  • a+: append; open or create text file for update, writing at end-of-file(237)
  • r+b or rb+: open binary file for update (reading and writing)
  • w+b or wb+: truncate to zero length or create binary file for update
  • a+b or ab+: 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).

like image 111
Marco Bonelli Avatar answered Nov 17 '25 21:11

Marco Bonelli