X-Spam-Check-By: sourceware.org To: cygwin AT cygwin DOT com From: Eric Blake Subject: Re: 1.5.24: data corruption problem with popen and gzip on a text mounted filesystem Date: Mon, 23 Jul 2007 15:42:55 +0000 (UTC) Lines: 28 Message-ID: References: <46A4BC14 DOT 1050603 AT merl DOT com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit User-Agent: Loom/3.14 (http://gmane.org/) X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Hugh Secker-Walker merl.com> writes: > 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. Indeed - so you are handing the data to gzip in binary mode. The problem, then, is likely not your program, but gzip - it seems to me that gzip should be forcing binary mode but does not. cgf is the cygwin gzip maintainer, so hopefully he can do something about this. In the meantime, I'll probably fire off a mail to the bug-gzip list with a patch (since the upstream maintainer for gzip also maintains coreutils, so he is already familiar with text vs. binary issues in other apps that he maintains). As a workaround, you can force gzip to see stdout in binary mode by using an intermediary pipe, as in popen("gzip | cat > outputfile", "wb"). -- Eric Blake -- 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/