Web lists-archives.com

Re: textmode for stdout, what is "correct" now?

On Feb 18 10:40, Michael Haubenwallner wrote:
> On 2/16/19 6:43 PM, Corinna Vinschen wrote:
> > I really miss the problem you're trying to solve here.  Why should an
> > application setting O_BINARY explicitely revert this decision on the
> > same file descriptor?  That doesn't make sense.
> Well, it's not necessarily about really switching binary mode on and off,
> it's more about avoiding breakage when applications try to intuitively
> follow the original API, even if that actually causes the call to
> setmode(fd, O_TEXT) to be redundant.
> OTOH, this question also would apply to native Win32 applications, so why
> do people call setmode(fd, O_TEXT) with any DOS based platform at all?
> IMO, unfortunately we're not in a position to modify the intention of the
> original API.  And finally, I do want to stop discussions like this one
> with application developers like openssl, as soon as we can argue like:
> "Cygwin does not use \r internally, but does support text mode mounts,
> so we had to invent the Cygwin text mode, which may or may not use \r.
> Hence you get the Cygwin text mode with O_TEXT, and if you really are
> in some 'unix2dos' position, please use the new O_DOSTEXT mode instead."
> However, agreed this does not seem to be trivial to implement.  Yet I
> will look into it when there is a chance for a patches to be accepted.

Bottom line:

- Make O_TEXT equivalent to O_BINARY on the API level so Cygwin
  actually uses binary mode on open(O_TEXT) and setmode(O_TEXT).

- Make O_DOSTEXT equivalent to the former O_TEXT.

Result: we use binary mode even with tools explicitely specifying O_TEXT.

- How do you handle fopen modes "wt", "rt", etc, then?

- What about automode.c, binmode.c, textmode.c, textreadmode.c?

- How do you avoid breakage of existing tools which have been written to
  work explicitely with certain DOS formatted text file and use O_TEXT
  for that?

The answer to the last one could be using a new version check like the
ones already in include/cygwin/version.h.  Existing tools and libs keep
the current behaviour.  Only newly built binaries get the new behaviour.
However, this still may result in breakage if the developer isn't aware
of this subtil change.  As much as I hate O_TEXT mode, there's a
pretty basic expectation how this is supposed to work.


Corinna Vinschen
Cygwin Maintainer

Attachment: signature.asc
Description: PGP signature