Does EOF actually exist?

て烟熏妆下的殇ゞ 提交于 2019-12-12 13:07:10

问题


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?


回答1:


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.




回答2:


In modern filesystems there is no actual EOF character on the disk. It's implemented in some file reading functions by returning a 4 byte value instead of a 1 byte value, but most functions don't use the concept.




回答3:


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



来源:https://stackoverflow.com/questions/2405818/does-eof-actually-exist

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!