textmode for stdout, what is "correct" now?

Michael Haubenwallner michael.haubenwallner@ssi-schaefer.com
Sat Feb 16 17:40:00 GMT 2019


On 2/16/19 10:38 AM, Corinna Vinschen wrote:
> On Feb 16 09:19, Michael Haubenwallner wrote:
>> On 2/15/19 9:31 PM, Corinna Vinschen wrote:
>>> On Feb 15 19:07, Michael Haubenwallner wrote:
>>>> On 2/15/19 1:48 PM, Corinna Vinschen wrote:
>>>>> On Feb 15 13:03, Michael Haubenwallner wrote:
>>>>>> On 2/15/19 11:22 AM, Corinna Vinschen wrote:
>>>>>>> On Feb 15 08:56, Michael Haubenwallner wrote:
>>>>>>>> On 2/14/19 5:20 PM, Corinna Vinschen wrote:
>>>>>>>>> On Feb 14 16:23, Michael Haubenwallner wrote:
>>>>>>>>>> Hi,
>>>>>>>>>> [SNIP]
>>>>>>>> Down the line in their BIO module they do use setmode(fd, O_TEXT),
>>>>>>>> which is the one that does introduce the \r, as far as I know.
>>>>>>>
>>>>>>> This one is not so nice.  Somebody should tell upstream we only
>>>>>>> want explicit O_BINARY these days, but no explicit O_TEXT.
>>>>
>>>> To me it sounds strange to use the one but not the other:
>>>>
>>>> If we don't want O_TEXT at all, isn't O_BINARY obsolete as well,
>>>> so the advise should be to use neither - just like real *nix?
>>>
>>> No, on text mode mounts O_BINARY makes sure that the result is
>>> actually a binary file.
>>>
>>>> A consequence then might be to deprecate (or even remove) them
>>>> from the public API header files.
>>>
>>> As long as we have text mode mounts, no.
>>
>> Ah... So this feels like a semantic confusion around setmode(O_TEXT):
>>
>> For the fopen() API family, POSIX says that conforming platforms should
>> accept (and eventually ignore) the 'b' character in the mode argument.
>> But note that there is no 't' character specified here.
>>
>> So with the fopen() API family, application developers are able to
>> enable or disable binary mode, but are _not_ able to explicitly
>> enable or disable text mode.
>>
>> Unfortunately, the setmode() API is semantically different, because it
>> does not allow to disable binary mode, but to "enable text mode" instead.
>>
>> So with the setmode() API, when application developers want to disable
>> binary mode, their only option is to "enable text mode".
> 
> 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/

--
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



More information about the Cygwin mailing list