Mail Archives: djgpp-workers/1998/09/16/15:49:05
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 -