Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

End-of-file

From Wikipedia, the free encyclopedia
Offset that corresponds to the first byte beyond the length of a computer file

Incomputing,end-of-file (EOF)[1] is a condition in a computeroperating system where no more data can be read from a data source. The data source is usually called afile orstream.

Details

[edit]

In theC standard library, the character-reading functions such asgetchar return a value equal to the symbolic value (macro)EOF to indicate that an end-of-file condition has occurred. The actual value ofEOF is implementation-dependent and must be negative (it is commonly −1, such as inglibc[2]). 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 oferrno or dedicated function, such asferror is required to determine which).

EOF character

[edit]

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. InUNIX, 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 aControl-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 (usuallyControl-V).AmigaDOS is similar but uses Control-\ instead of Control-D.

InDOS andWindows (and inCP/M and manyDEC operating systems such as thePDP-6 monitor,[3]RT-11,VMS orTOPS-10[4]), 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 anASCIIControl-Z, code 26. Some MS-DOS programs, including parts of the Microsoft MS-DOS shell (COMMAND.COM) and operating-system utility programs (such asEDLIN), 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 withCP/M. The CP/Mfile system (and also the original8-bit FAT implemented inMicrosoft 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. TheFAT12 filesystem introduced with86-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.

In the ANSI X3.27-1969magnetic tape standard, the end of file was indicated by atape mark, which consisted of a gap of approximately 3.5 inches of tape followed by a single byte containing the character0x13 (hex) fornine-track tapes and017 (octal) forseven-track tapes.[5] Theend-of-tape, commonly abbreviated asEOT, was indicated by two tape marks. This was the standard used, for example, onIBM 360. Thereflective strip that was used to announce impending physical end of tape was also called anEOT marker.

See also

[edit]

References

[edit]
  1. ^Pollock, Wayne."Shell Here Document Overview". hccfl.edu. Archived fromthe original on 2014-05-29. Retrieved2014-05-28.
  2. ^"The GNU C Library".www.gnu.org.
  3. ^"Table of IO Device Characteristics - Console or Teletypewriters".PDP-6 Multiprogramming System Manual(PDF). Maynard, Massachusetts, USA:Digital Equipment Corporation (DEC). 1965. p. 43. DEC-6-0-EX-SYS-UM-IP-PRE00.Archived(PDF) from the original on 2014-07-14. Retrieved2014-07-10. (1+84+10 pages)
  4. ^"5.1.1.1. Device Dependent Functions - Data Modes - Full-Duplex Software A(ASCII) and AL(ASCII Line)".PDP-10 Reference Handbook: Communicating with the Monitor - Time-Sharing Monitors(PDF). Vol. 3.Digital Equipment Corporation (DEC). 1969. pp. 5-3 – 5-6 [5-5 (431)].Archived(PDF) from the original on 2011-11-15. Retrieved2014-07-10. (207 pages)
  5. ^"Tape Transfer (Pre-1977): Exchange Media: MARC 21 Specifications for Record Structure, Character Sets, and Exchange Media (Library of Congress)".www.loc.gov.
Retrieved from "https://en.wikipedia.org/w/index.php?title=End-of-file&oldid=1270889158"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp