This is the mail archive of the cygwin-apps mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: upload: diffstat-1.40-1, tar-1.15.1-1


> You're saying that the programmer can go out of his way to specify the line
> ending style that they want but cygwin should allow the mount mode to override
> that?  I don't agree that this is logical behavior.

Here's my attempt to clarify my understanding of the current
behavior.  Tell me if any of this is wrong...

binary mode: every character in the file is presented to the application
on read (\r\n is preserved), every character desired to be in the
file must be written by the application (\n is not expanded)

text mode: line endings are compressed before presentation to
the application on read (\n is \n, \r\n is \n), writing a line ending
gets expanded (\n becomes \r\n, \r\n becomes \r\r\n)

mount mode: If linked with binmode.o, use binary read and write.
If linked with automode.o, use text read and binary write.
Otherwise, use the mode of the file system that owns the file.

open(..., <no O_BINARY or O_TEXT> ) - use mount mode, POSIX-compatible
open(..., O_BINARY) - force binary mode, non-POSIX extension
open(..., O_TEXT) - force text mode, non-POSIX extension
The only way to get text read and binary write with O_RDWR is
by using mount mode, so you must use two fd's if you intend
to force behavior.

fopen(..., "r"/"w") - use mount mode on read/write, POSIX-compatible,
but on text mounts violates POSIX
fopen(..., "rb"/"wb") - force binary mode on read/write, POSIX-compatible
fopen(..., "rt"/"wt") - force text mode on read/write, non-POSIX extension
fopen(..., "r+b") - force binary mode on read and write
The only way to get text read and binary write when '+' is in the
string is by using mount mode (maybe it is worth inventing
something like "r+m", with m meaning mixed mode?), so you
must use two FILE* if you intend to force behavior.

freopen(NULL, "rb", 0) - not yet implemented in cygwin, but a
POSIX-compatible idiom used in CVS coreutils to force stdin to be
read as binary.  Implemented in gnulib (used by coreutils) by this:
#define freopen rpl_freopen
rpl_freopen() /* on CYGWIN, if name is NULL and fd is STDIN_FILENO,
call setmode, otherwise fall back to real freopen */

setmode(fd, O_BINARY or O_TEXT) - returns 0 on success, -1 on failure
(different from the cygwin web page doc of returning the previous mode),
and forces mode change.  Not a good idea to call it on a tty.  Non-POSIX
extension.

fcntl(F_GETFL) always returns one of O_BINARY or O_TEXT, among its
other flags.  I don't know if there is a flag for mixed mode fd's that are
open for simultaneous text read and binary write.

fcntl(F_SETFL, O_BINARY or O_TEXT) - currently a no-op.  But in my
opinion, it would be more useful if it behaved as:
neither option - leave mode alone
O_BINARY - behave like setmode(O_BINARY)
O_TEXT - behave like setmode(O_TEXT)
O_BINARY | O_TEXT - toggle mode to the opposite state
That way, fcntl(F_SETFL, fcntl(F_GETFL) | O_BINARY) would work
without having to resort to non-POSIX setmode.

--
Eric Blake



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]