End-of-file
Encyclopedia
In computing
Computing
Computing is usually defined as the activity of using and improving computer hardware and software. It is the computer-specific part of information technology...

, end of file (commonly abbreviated EOF) is a condition in a computer operating system
Operating system
An operating system is a set of programs that manage computer hardware resources and provide common services for application software. The operating system is the most important type of system software in a computer system...

 where no more data can be read from a data source. The data source is usually called a file or stream.

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 system-dependent (but is commonly -1, such as in glibc) and is unequal to any valid character code. Block-reading functions return the number of bytes read, and if this is fewer than asked for, then the end of file was reached.

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
Unix
Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...

 and AmigaDOS
AmigaDOS
AmigaDOS is the disk operating system of the AmigaOS, which includes file systems, file and directory manipulation, the command-line interface, and file redirection....

, 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
End-of-transmission character
In telecommunication, an end-of-transmission character is a transmission control character. Its intended use is to indicate the conclusion of a transmission that may have included one or more texts and any associated message headings....

 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
Control-V
In computing, Control-V is a control character in ASCII code, also known as the synchronous idle character. It is generated by pressing the key while holding down the key on a computer keyboard...

).

In Microsoft's DOS
DOS
DOS, short for "Disk Operating System", is an acronym for several closely related operating systems that dominated the IBM PC compatible market between 1981 and 1995, or until about 2000 if one includes the partially DOS-based Microsoft Windows versions 95, 98, and Millennium Edition.Related...

 and Windows
Microsoft Windows
Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...

 (and in CP/M and many DEC operating systems), 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
ASCII
The American Standard Code for Information Interchange is a character-encoding scheme based on the ordering of the English alphabet. ASCII codes represent text in computers, communications equipment, and other devices that use text...

 Control-Z
Substitute character
A substitute character is a control character that is used in the place of a character that is recognized to be invalid or in error or that cannot be represented on a given device....

. Some MS-DOS programs, including parts of the Microsoft MS-DOS shell (COMMAND.COM
COMMAND.COM
COMMAND.COM is the filename of the default operating system shell for DOS operating systems and the default command line interpreter on Windows 95, Windows 98 and Windows Me...

) and operating-system utility programs (such as EDLIN
Edlin
Edlin is a line editor included with MS-DOS and later Microsoft operating systems. It provides rudimentary capabilities for editing plain text files through a command-driven interface. Line numbers are specified using numerals, and operations are specified using single-character alphabetic...

), 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
    CP/M
    CP/M was a mass-market operating system created for Intel 8080/85 based microcomputers by Gary Kildall of Digital Research, Inc...

    . The CP/M file system
    File system
    A file system is a means to organize data expected to be retained after a program terminates by providing procedures to store, retrieve and update data, as well as manage the available space on the device which contain it. A file system organizes data in an efficient manner and is tuned to the...

     only recorded the lengths of files in multiples of 128-byte "blocks", so by convention a Control-Z character was used to mark the end of meaningful data if it ended in the middle of a block. The MS-DOS filesystem
    File Allocation Table
    File Allocation Table is a computer file system architecture now widely used on many computer systems and most memory cards, such as those used with digital cameras. FAT file systems are commonly found on floppy disks, flash memory cards, digital cameras, and many other portable devices because of...

     has always recorded the exact byte-length of files, so this was never necessary on MS-DOS.
  • It allows programs to use the same code to read input from both a terminal and a text file.


In the ANSI X3.27-1969 magnetic tape
Magnetic tape
Magnetic tape is a medium for magnetic recording, made of a thin magnetizable coating on a long, narrow strip of plastic. It was developed in Germany, based on magnetic wire recording. Devices that record and play back audio and video using magnetic tape are tape recorders and video tape recorders...

 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 13 (hex) for nine-track tapes and 17 (octal) for seven-track tapes
IBM 7 Track
IBM's first magnetic tape data storage devices, introduced in 1952, use what is now generally known as 7 track tape. The magnetic tape is 1/2" wide and there are 6 data tracks plus 1 parity track for a total of 7 parallel tracks that span the length of the tape...

. 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 used to announce impending physical end of tape was also called an EOT marker.

See also

  • End-of-transmission character
    End-of-transmission character
    In telecommunication, an end-of-transmission character is a transmission control character. Its intended use is to indicate the conclusion of a transmission that may have included one or more texts and any associated message headings....

  • Substitute character
    Substitute character
    A substitute character is a control character that is used in the place of a character that is recognized to be invalid or in error or that cannot be represented on a given device....

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK