Web lists-archives.com

A little improvement for setmode(fd, 0)?




Hi Corinna,

sorry to be annoying, but I'm still not completely happy with the
setmode(fd, 0) API yet:

Using setmode(fd, 0), beyond "I am aware that not everything is binary",
an application's point of view when ported to Cygwin is something like:
"For this (maybe bidirectional) file descriptor, wherever the user does
connect it to (stream, binary mounted fs, text mounted fs, ...), I do
*not need* to transfer binary content.  That is, to stay as POSIXy as
possible, for line breaks I do not want to handle any \r in my text."

Hence, read() should not deliver the \r when reading any line break, and
write(\n) should add the \r only when the target does require that (like
the file on a text mounted fs).

As there is no clean way to ignore \r for reads without forcing \r for
writes, right now a complete-as-possible patch for openssl may look like:
https://gitweb.gentoo.org/repo/proj/prefix.git/tree/dev-libs/openssl/files/openssl-1.1.1a-cygwin-binmode.patch?id=05d897568b21446657001a51660e9a25172474f2

But there still is the difference between readonly and read+write.

Attached is a test script for a collected overview of the behaviour
differences when applications use the setmode() API call.

$ ./setmodetest.sh
Testing behaviour of various setmode() arguments...
---------+--------------------------+--------------------------+
perform: |   read from 0d0a input   |   write the single 0a    |
filesys: | stream | binary |  text  | stream | binary |  text  |
---------+--------+--------+--------+--------+--------+--------+
 default |   0d0a |   0d0a |     0a |     0a |     0a |   0d0a |
O_BINARY |   0d0a |   0d0a |   0d0a |     0a |     0a |     0a |
  0      |   0d0a |   0d0a |     0a |     0a |     0a |   0d0a |
O_TEXT   |     0a |     0a |     0a |   0d0a |   0d0a |   0d0a |
---------+--------+--------+--------+--------+--------+--------+

So what I would like to see is a behaviour like this:
---------+--------------------------+--------------------------+
perform: |   read from 0d0a input   |   write the single 0a    |
filesys: | stream | binary |  text  | stream | binary |  text  |
---------+--------+--------+--------+--------+--------+--------+
  0 ?    |     0a |     0a |     0a |     0a |     0a |   0d0a |
---------+--------+--------+--------+--------+--------+--------+

Even if that would mean that setmode(fd, 0) does not switch back to default
behaviour any more.  But then, isn't the default behaviour designed for
applications that do not use (are unaware of) the setmode() API at all?

Thoughts?

For completion:
$ ./setmodetest.sh --trace
does create the list of commands being executed.

$ ./setmodetest.sh --with-fopen
does use the FILE handle API

Thanks a lot!
/haubi/

Attachment: setmodetest.sh
Description: application/shellscript

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