delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/02/02/17:27:04

Date: Mon, 2 Feb 1998 19:05:35 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: "John M. Aldrich" <fighteer AT cs DOT com>
cc: djgpp AT delorie DOT com
Subject: Re: Text / binary implementation differences
In-Reply-To: <34D50D05.1493@cs.com>
Message-ID: <Pine.SUN.3.91.980202190517.19322N-100000@is>
MIME-Version: 1.0

On Sun, 1 Feb 1998, John M. Aldrich wrote:

> Second, MS-DOS text files signal EOL with a CR/LF pair.  When reading
> such a file into memory, the extra LF is automatically stripped.
> Likewise, when writing a text file, EOF terminates the write, and CR's
> are translated into CR/LF.

Minor correction: CR is stripped on read and added on write; LF is
retained.

> The moral of the story:  If you are writing text data, use text mode. 
> If you are writing binary data, use binary mode.  Do NOT mix the two, or
> your programs will almost certainly fail.

Unfortunately, this only works up to a point.  One example is
PostScript files, which is mostly text and can be parsed, but can also
have embedded non-printable characters.  Another example is when you
must seek into a file using byte counts.  In such cases, you must open
and read the file in binary mode, and then remove any excess \r
characters while you process it.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019