The library buffers input and output operations. Check out setvbuf()
and the _IOFBF
, _IOLBF
parameters to that funktion.
fseek()
or fflush()
require the library to commit buffered operations.
The standard specifies a seek or flush operation as mandatory to allow the library some shortcuts; otherwise, for every I/O operation, the lib would have to check if the previous operation was also a read op (or a write op), and trigger a flush by itself if the "direction" of the I/O changed. With the specifications as-is, the library may assume the client did the seek / flush before changing I/O direction.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…