Bug#636266: libc6: fread() reads more than specified number of bytes
On Tuesday 02 August 2011, Jonathan Nieder wrote:
> Not sure what libc can do about that. Maybe the kernel could say,
> "Please, do not buffer when reading this file" and libc could respect
> that. But fundamentally, buffering is what fread is all about,
> In the C and POSIX standards, the behavior of fread is defined in
> terms of fgetc. To be reasonably fast and decrease the number of
> system calls, traditionally fgetc attempts to fill a large buffer
> when it calls read(). Should fread behave differently? I would find
> it strange for fread(1, 1) to use a different sequence of system calls
> from fgetc.
Well, how about this: fopen() already seems to do an fstat(), and so it
should easily see that this is neither a file nor a block device (and store
that in the FILE somewhere).
I think that on sockets, pipes, character devices, and similar there should
be _no_ readahead.