tags:

views:

105

answers:

2

Hi,

When I use file functions in PHP, I check for EOF. I wonder if EOF actually exist in a file. When I create an empty text file, it displays 0KB. How does EOF exist in a file with 0KB?

+7  A: 

There is an end-of-file control character (in the ASCII character set it's CTRL+Z or 26 or 0x1A), but it hasn't actually been needed to mark the end of a file since OSes released in the 80's. All modern OSes store the file size as metadata in the directory structure (exact format depends on filesystem) and high level file access functions will check the file size to decide when to indicate EOF to you, the programmer.

If there is an end-of-file in the data AND you have text-mode translations turned on (in most languages this is the same setting that controls NL <-> CRLF conversions), then the file access may stop when it hits that EOF character. In binary mode, reads will keep going until the file size is hit.

Ben Voigt
ctrl+z is windows/DOS. ctrl+d is unix.
gnud
Right, and other OSes used file separator (28) and so forth. Just another reason we should be glad using a character to mark end of file is obsolete.
Ben Voigt
A: 

it doesn't exist.. but file size does, and that's how you know where is eof

fazo