the C standard doesn't say file positioning functions internally flush output to device or clear input cache.
The Standard indeed hasn't mentioned about the detail of somewhat internal buffering mechanism, because it varies from OS to OS; that is, implementation dependent. Thus, the standard is not responsible for defining it.
I was wondering why the file positioning functions (if not fflush) should be called between output and input?
Since the behaviour is implementation dependent, for some OS (e.g. Ubuntu), interestingly, there is no need for us to call fflush(),fseek() explicitly, while others(e.g. macOS) strictly needs.
For the sake of a concrete description, I've run some tests on two OS:
- macOS Big Sur (Darwin Kernel Version 20.6.0)
- Ubuntu 14 (GNU/Linux 4.4.0-142-generic)
Taking an example of "replace the 5th character in the file", and assume that the file content is
1234_6789
and the program is as followes:
show_file_content();
getc(fp);
getc(fp);
getc(fp);
getc(fp);
/* this line is indispensable for macos, but NOT for ubuntu */
fseek(fp,0,SEEK_CUR);
putc('5', fp);
printf("->");
show_file_content();
the above program's output is (no matter running on macOS or Ubuntu):
1234_6789->123456789
But, if we comment the line of fseek, things are different; the outputs are...
macOS:
1234_6789->1234_67895
Ubuntu:
1234_6789->123456789
You can try this test on other different OSes. The comparison between two different Unix-based OSes suffices to understand the APUE's statement.