Message-ID: <360012C4.C2554493@vlsi.com> Date: Wed, 16 Sep 1998 12:34:28 -0700 From: Charles Marslett MIME-Version: 1.0 To: Andris Pavenis CC: djgpp-workers AT delorie DOT com Subject: Re: auto-binary-mode? Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Precedence: bulk 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