What is the proper way of finding an end of file condition while reading
a file ?
Try to read the file, and if it fails, see if the reason it failed
was "end of file".
How does feof() detects that end of file is reached ?
It does not. It answers a question about "why that earlier failure?"
for a previous read that you already know failed. The two possible
reasons allowed, in Standard C (and in the Unix-like systems on
which C was developed), are "the attempt to read failed because
there was nothing more to read, i.e., a perfectly ordinary end-of-file
occurred" and "the attempt to read failed because of some sort of
underlying failure, such as hitting a bad spot on the disk, or the
hardware is on fire." The "no more data" case causes feof(fp) to
become nonzero, while the "hardware failure/disk drive has melted"
case causes ferror(fp) to become true.
Does this require support from OS ?
It requires only the ability to report failures when reading files,
and to distinguish between "no more data" and "hardware error".
Note that C streams can be connected to interactive devices (like
human beings typing at keyboards, or Internet connections, on
systems that support such things), and it is not possible to predict
in advance just when a human being or Internet connection will
reach "end of input". But there is no need for prescience: if you
want more input, just ask for it, and when you no longer get it,
only *then* do you need to find out why. Sure, it might be nice
sometimes to predict in advance how much input you will get -- but
in the worst case, you can just copy everything to a temporary
file, and then use the copy. This even works on human beings and
Internet connections.