Question Details

No question body available.

Tags

c language-lawyer fwrite stdio

Answers (1)

May 29, 2026 Score: 3 Rep: 1,711 Quality: Medium Completeness: 60%

The FILE handles in C are 'streams', and this is a specifically defined term. It's in a way distinct from files you'd find e.g. in POSIX.

I/O semantic on FILE , and fread/fwrite in particular, dictates only 1 kind of success when requesting non-empty I/O - return equals requested.

I/O semantic on file descriptors (int in POSIX, and Windows CRT) on the other hand, did require write to return equal to requested on success for regular files, but even if write returned less than requested, it's not considered an error until a next call to write is made (by which time, -1 is returned).

I/O semantic on file descriptors are complicated by the fact that availability of data is not guaranteed, the fact that some file descriptors have O_NONBLOCK set by user, and the fact that some file descriptors refer to 'block devices' (think hard drives) that fails unless block alignment requirements are met.