delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1998/09/16/15:49:05

Message-ID: <360012C4.C2554493@vlsi.com>
Date: Wed, 16 Sep 1998 12:34:28 -0700
From: Charles Marslett <charles DOT marslett AT vlsi DOT com>
MIME-Version: 1.0
To: Andris Pavenis <pavenis AT lanet DOT lv>
CC: djgpp-workers AT delorie DOT com
Subject: Re: auto-binary-mode?

Andris Pavenis wrote:
> 
> On Tue, 15 Sep 1998, DJ Delorie wrote:
> 
> >
> > Hey, I just had an idea.  When a file is opened and the first block is
> > read in, if the user didn't specify binary or text, why not look at
> > the data and try to guess?  The presence of null, control, or certain
> > 8-bit characters should indicate binary vs text as a default.
> >
> 
> Maybe slightly different:
>    we can add additional open mode to allow to guess file type
>    for example O_AUTO.
> 
> Or some global variable that enables such feature. I don't think it
> would be good to enable it always.
> 
> Andris

True, an unexpected autodetect would break a number of programs that
"know" the format of their input and (perhaps to make the program
portable to old K&R compilers or for other reasons we are not aware
of) are not able to use the ANSI fopen() parameters.  It also makes
detecting binary files in the program code harder because compilers
that force autodetect are not likely to do it exactly the same way,
necessitating #if's and such for compiler specific algorithms.

You are very right in pointing out hardwired autodetect of text files
is a very bad idea.  I had not considered such a possibility, and
that can be dangerous when talking to people who don't know you well!

Microsoft and Borland use a global variable to define the meaning of
"r" and "w" and library functions to "manipulate" that variable.  This
handles many of the problem cases.  Is DJGPP done similarly already?

--Charles

- Raw text -


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