From Surf Wiki (app.surf) — the open knowledge base
End-of-file
Offset that corresponds to the first byte beyond the length of a computer file
Offset that corresponds to the first byte beyond the length of a computer file
In computing, end-of-file (EOF) is a condition in a computer operating system where no more data can be read from a data source. The data source is usually called a file or stream.
Details
In the C standard library, the character-reading functions such as getchar return a value equal to the symbolic value (macro) EOF to indicate that an end-of-file condition has occurred. The actual value of EOF is implementation-dependent and must be negative (it is commonly −1, such as in glibc). Block-reading functions return the number of bytes read, and if this is fewer than asked for, then the end of file was reached or an error occurred (checking of errno or of a dedicated function, such as ferror is required to determine which).
EOF character
Input from a terminal never really "ends" (unless the device is disconnected), but it is useful to enter more than one "file" into a terminal, so a key sequence is reserved to indicate end of input. In UNIX, the translation of the keystroke to EOF is performed by the terminal driver, so a program does not need to distinguish terminals from other input files. By default, the driver converts a Control-D character at the start of a line into an end-of-file indicator. To insert an actual Control-D (ASCII 04) character into the input stream, the user precedes it with a "quote" command character (usually Control-V). AmigaDOS is similar but uses Control-\ instead of Control-D.
In DOS and Windows (and in CP/M and many DEC operating systems such as the PDP-6 monitor, RT-11, VMS or TOPS-10), reading from the terminal will never produce an EOF. Instead, programs recognize that the source is a terminal (or other "character device") and interpret a given reserved character or sequence as an end-of-file indicator; most commonly, this is an ASCII Control-Z, code 26. Some MS-DOS programs, including parts of the Microsoft MS-DOS shell (COMMAND.COM) and operating-system utility programs (such as EDLIN), treat a Control-Z in a text file as marking the end of meaningful data, and/or append a Control-Z to the end when writing a text file. This was done for two reasons:
- Backward compatibility with CP/M. The CP/M file system (and also the original 8-bit FAT implemented in Microsoft BASIC) only recorded the lengths of files in multiples of 128-byte "records", so, by convention, a Control-Z character was used to mark the end of meaningful data if it ended in the middle of a record. The FAT12 filesystem introduced with 86-DOS and MS-DOS has always recorded the exact byte-length of files, so this was never necessary on DOS.
- It allows programs to use the same code to read input from both a terminal and a text file.
tape mark
EOT
In the ANSI X3.27-1969 magnetic tape standard, the end of file was indicated by a tape mark, which consisted of a gap of approximately 3.5 inches of tape followed by a single byte containing the character 0x13 (hex) for nine-track tapes and 017 (octal) for seven-track tapes. The end-of-tape, commonly abbreviated as EOT, was indicated by two tape marks. This was the standard used, for example, on IBM 360. The reflective strip that was used to announce impending physical end of tape was also called an EOT marker.
References
References
- "Shell Here Document Overview". hccfl.edu.
- "The GNU C Library".
- (1965). "PDP-6 Multiprogramming System Manual". [[Digital Equipment Corporation]] (DEC).
- (1969). "PDP-10 Reference Handbook: Communicating with the Monitor - Time-Sharing Monitors". [[Digital Equipment Corporation]] (DEC).
- "Tape Transfer (Pre-1977): Exchange Media: MARC 21 Specifications for Record Structure, Character Sets, and Exchange Media (Library of Congress)".
This article was imported from Wikipedia and is available under the Creative Commons Attribution-ShareAlike 4.0 License. Content has been adapted to SurfDoc format. Original contributors can be found on the article history page.
Ask Mako anything about End-of-file — get instant answers, deeper analysis, and related topics.
Research with MakoFree with your Surf account
Create a free account to save articles, ask Mako questions, and organize your research.
Sign up freeThis content may have been generated or modified by AI. CloudSurf Software LLC is not responsible for the accuracy, completeness, or reliability of AI-generated content. Always verify important information from primary sources.
Report