Web lists-archives.com

Re: A little improvement for setmode(fd, 0)?




On Feb 22 16:43, Michael Haubenwallner wrote:
> 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,

This isn't true.  Just link your application with -ltextreadmode

Why is that not sufficient?



> 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

My patch has already gone upstream.  It just does not enforce
text mode on write, ever.

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

O_RDWR is a special case.  In general you never want to have different
read and write modes on the same file, otherwise you're bound to schred
the file to pieces.

Therefore, let's stick to O_BINARY mode by default, and use O_TEXT
only in border case.


Corinna

-- 
Corinna Vinschen
Cygwin Maintainer

Attachment: signature.asc
Description: PGP signature