Where's JosAH when you need him?
The saviour is here, fear no more! ;-) End of file characters are coupled to the
stupidity of file systems. Early file systems just knew that a file was store at
secors, say, 5, 9, 24, 42 (in that order) but didn't know for how much that last
sector was filled by the file's data.
The entire last sector was loaded in memory and the user (application) just had
to guess. That's why they came up with a sentinel value, e.g. ^Z to denote the
logical end of file. But what to do if the ^Z value happened to be part of the file
in the last sector? Too bad, the file's length was just a multiple of a sector size.
File systems nowadays do store the exact length of a file so there is no need
anymore to read (or write) those silly sentinel values in the last sector. Deep
down entire sectors are still read but that is way below the application level.
Nowadays people forget to flush buffers (close() does it for them) and expect
reading functions to be psychic, i.e. those functions are expected to predict
whether or not they'll hit an end of file condition at their next read operation.
Because no explicit end-of-file character is being written and because those
single character reading functions have to indicate that they have just bumped
into an end-of-file condition, they have to signal that condition with a sentinel
value again. fgetc() does it by returning -1 which is outside the range of the
valid character values but -1 is not written to a disk file image per se.
kind regards,
Jos