Web lists-archives.com

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




On 2/16/19 6:43 PM, Corinna Vinschen wrote:
> On Feb 16 18:13, Michael Haubenwallner wrote:
>> On 2/16/19 10:38 AM, Corinna Vinschen wrote:
>>> setmode(fd, O_BINARY) works on Cygwin.
>>
>> Well... true.
>>
>> What I'm trying to say is that restoring the *default* mode is currently 
>> broken, because traditionally the default mode simply is called "text
>> mode" - which is enough for DOS only systems, but confusing in Cygwin.
>>
>> As for Cygwin the default mode is more complex, we may want to call it
>> something like the "Cygwin text mode" instead.  Consequently, the mode
>> that does force \r should be called the "DOS text mode".
>>
>> Whether the "Cygwin text mode" is with or without \r depends on some
>> other property like the text mount.
>>
>> However, after setting the "binary mode", libraries like openssl BIO
>> want to be able to restore the "non-binary mode" - whatever name it
>> may have.  So they use the only available API: setmode(fd, O_TEXT).
>> And IMO they're right to expect the "Cygwin text mode" on Cygwin.
>>
>> If they really need the "DOS text mode", they either should handle the
>> \r in binary mode - or we provide some new setmode(fd, O_DOSTEXT) API.
>>
>> In hope to be more clear now,
>> /haubi/
> 
> 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.

Thanks!
/haubi/

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple