Pending change to cygwin DLL and binmode/textmode musings
Sat Jun 24 20:42:00 GMT 2000
[This was also posted to cygwin-apps but since both mailing lists are
subscribe-post-only, I thought it best to send two separate messages.]
I've been playing around with a change to the cygwin DLL that attempts to
duplicate functionality that is found in MSVC.
I've created an object called "binmode.o" which, when added to a link line
will cause any open that does not specify binary or text mode access to
default to binary access.
This is not 100% the same as Microsoft since you also have to worry about
text mode and bin mode mounts in Cygwin. My implementation gives precedence
to the (little used?) _fmode variable which has always been around in Cygwin.
Setting this variable to O_BINARY used to be the same as CYGWIN=binmode,
i.e., it didn't affect disk files. Now it does. CYGWIN=binmode still
affects only non-disk files, however.
So, this effectively duplicates MSVC functionality, AFAICT.
Corinna and I were talking about another interface that is more general
and possibly more useful.
We were talking about developing a "cygwin_set_default_open" function.
It would work something like this:
/* Reads of /etc/passwd default to text unless explicitly specified */
set_default_open ("/etc/passwd", O_RDONLY | O_TEXT);
/* Writes of /tmp/bar default to binary unless explicitly specified */
set_default_open ("/tmp/bar", O_WRONLY | O_BINARY);
/* Accesses of any file named foof default to binary unless... */
set_default_open ("foof", O_BINARY);
The premise here is that calls to this function can live in a program's
"main()" to avoid modifying opens or fopens throughout the source.
Alternatively, this could be added to a "premain()" function which would
be called prior to main(). This would mean that you only have to modify
a Makefile to link in the file containing the premain() function.
DJ has also suggested that we could maintain a database of files which
are known to have a certain format. So, for instance, /etc/passwd
and /etc/group would be marked in this database as "always text".
Another possibility is to set aside a block of space in each cygwin
executable that could be filled in with names and modes of files
that the executable uses. So, tcsh.exe would be modified, after
linking, to set .cshrc as "always text".
Anyway, that's what we're thinking of for ways to minimize the
neverending binmode/textmode problems.
More information about the Cygwin-developers