1.5.24: data corruption problem with popen and gzip on a text mounted filesystem
Hugh Secker-Walker
hugh@merl.com
Mon Jul 23 14:32:00 GMT 2007
Hi Folks,
I'm having trouble getting correct behavior on a third-party OpenSource
project that I'm building using Cygwin. The problem involves the
writing of corrupt data to a file. The output file is created and
written via popen("gzip > outputfile", "wb"). The data is fine if the
filesystem is mounted in binary mode. The data is corrupted if the
filesystem is mounted in text mode.
My understanding of the documentation is that pipes and shells' stdin
and stdout will be in binary mode if the CYGWIN env variable contains
the 'binmode' setting, regardless of the binary/text mount flag of the
filesystem the file is mounted on. From page 33 of the users guide:
...
c. Pipes and non-file devices are opened in binary mode, except if
the CYGWIN environment variable
contains nobinmode.
Warning!
In b20.1 of 12/98, a file will be opened in binary mode if any
of the
following conditions hold:
1. binary mode is specified in the open call
2. the filename is a MS-DOS filename
3. the file resides on a binary mounted partition
4. CYGWIN contains binmode
5. the file is not a disk file
d. When redirecting, the Cygwin shells uses rules (a-e). [sic,
should be (a-d) -HSW]
For these shells the relevant value of
CYGWIN is that at the time the shell was launched and not that at
the time the program is executed.
Non-Cygwin shells always pipe and redirect with binary mode. With
non-Cygwin shells the
commands cat filename | program and program < filename are not
equivalent when filename
is on a text-mounted partition.
I've generated a small example of the problem. Attached is an annotated
log showing the code and the behaviors. One thing that is not clear
from the logs is that I generally start all executables from within a
bash shell within emacs. However, the problem appears in rxvt shell
windows and in XP cmd.exe windows in which I have run cygwin.bat to get
a bash shell.
I've tried several workarounds of this variety: " sh -c 'CYGWIN=binmode
blah.exe' " both to start the program and within the popen() command,
but none of them has succeeded. The use of "wb" or "w" in the second
argument to popen() has no visible effect on the problem. And the
setting or not of CYGWIN=binmode in the XP environment has no visible
effect.
So far I have no workaround to the problem. I cannot require users to
switch their filesystem mounts to binary.
Any insight or workarounds would be appreciate.
Thanks,
-Hugh
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: popenbug.txt
URL: <http://cygwin.com/pipermail/cygwin/attachments/20070723/c505ea00/attachment.txt>
-------------- next part --------------
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
More information about the Cygwin
mailing list