delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1998/09/17/03:45:08

Date: Thu, 17 Sep 1998 10:31:16 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Charles Marslett <charles DOT marslett AT vlsi DOT com>
cc: djgpp-workers AT delorie DOT com
Subject: Re: auto-binary-mode?
In-Reply-To: <3600096D.7CEF24DD@vlsi.com>
Message-ID: <Pine.SUN.3.91.980917103054.10547F-100000@is>
MIME-Version: 1.0

On Wed, 16 Sep 1998, Charles Marslett wrote:

> Well, I was thinking of the issue as only being between Unix (binaryish)
> text files and DOS text files.

That's exactly the point: O_BINARY and "rb"/"wb" are mostly needed for
*binary*, not Unix-style text, files.  If a Unix-style text file is
read by a naive program that doesn't open it in binary mode, nothing
wrong will happen to it.  The problems arise when such a naive program
is used to read/write truely binary data.

> That is, an application would never have been written with an "r" or "w"
> fopen() call if it were important to distinguish between text and binary
> I/O on the system the program was written for (a Unix most likely).

Many people, even those who work on DOS/Windows, are oblivious to the
problems associated with binary I/O.  So there *are* cases when they
fail to include binary flags in opening files.  I'd guess that many
"...for dummies" books avoid mentioning such issues, so newbies are
unprepared to them.  I think DJ's proposal was targeting those naive
programs, not the ones written by people who know better.

> The problem was and is that GNU Emacs does not have an
> inherent way of specifying a file as being text or binary -- exactly the
> problem addressed by "rb" or "rt", and the problem pointed out by you
> and others with installing autodetect in the library.

Which version of Emacs did you look in to say that?  In fact, Emacs
does have a way of specifying that a file is binary.  This has been so
for at least 5 years in the DOS/Windows versions of Emacs, and for the
last 18 months it is also true for Unix.  Latest versions of Emacs
also auto-detect pure binary files, as well as other text encodings,
but this guesswork has controversial record among users, apparently
because of several subtle bugs and because when the guess is wrong,
you lose bug time.  But at least in Emacs you can repair the damage of
a wrong guess by forcing it to reread the file as binary/text, as the
case may be.

> As an unrelated side issue, what difference is there between a text and
> binary file in the Microsoft world except for the processing of the ^Z
> and CR/NL characters?

There are additional aspects that are related to I/O to/from character
devices: the default text mode is also associated with the so-called
``cooked mode'' of I/O whereby some special characters are
interpreted.  E.g., ^S stops the output, TAB is converted to spaces,
etc.

> (And of course the side effects of that processing that leaks into
> ftell(), fseek()

DJGPP's versions of `fseek' and `ftell' don't have these
side-effects.

- Raw text -


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