Historical question: LF vs. CR\LF in text files
Doug Gwyn
gwyn at smoke.BRL.MIL
Wed May 30 22:43:56 AEST 1990
In article <952 at ashton.UUCP> tomr at ashton.UUCP (Tom Rombouts) writes:
>Forgive the bandwidth, but seeing that others beside myself are
>having occassional problems relating to the differences between
>UNIX vs. DOS (and CP/M, correct?) in handling end of lines, I am
>wondering how this started. Since UNIX came first, I am going to
>guess that at some time, somewhere someone said "Hey - let's add
>a carriage return!" Does anyone know the (possibly amusing?) story
>behind this? What was the essential rationale?
Actually, neither UNIX nor MS-DOS came first. There have been many
conventions for indicating record sizes/boundaries in disk files,
including per-line byte counts, fixed record size with trailing-
blank padding, CR stream delimiters (e.g. Apple II), etc. The real
original of CR/LF pairs can be traced back to teletypewriters,
which required both control characters to perform the "new-line"
function. It was fairly natural to embed these in disk files so
that a simple dump of the file to a teletypewriter would print
properly. An alternate interpretation of the LF code allowed by
the ASCII standard was the entire new-line function, and some newer
terminals were designed to support this (if I recall correctly, the
Teletype model 37 may have been one of these). Apparently the UNIX
designers took advantage of this convention and adopted it as the
standard interpretation for files considered as text; it has the
advantage of simplifying code that processes text files. Note that
even the universal C standard requires that this convention be
followed for files opened as "text streams", which means that C
implementations on CR/LF-using systems are obliged to watch for
line delimiters and convert the external CR/LF to and from the
internal C character code '\n' (typically same code as ASCII LF),
at least for stdio text streams.
My personal opinion is that the people who "designed" MS-DOS did
not pay sufficient attention to lessons that should have been
learned from the UNIX system, but too closely followed CP/M which
in turn was pretty much a direct rip-off of DEC's RT-11 design.
More information about the Comp.unix.questions
mailing list