www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/01/18/17:26:43

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00,SPF_SOFTFAIL
X-Spam-Check-By: sourceware.org
Message-ID: <4973ACA9.7040008@byu.net>
Date: Sun, 18 Jan 2009 15:26:49 -0700
From: Eric Blake <ebb9 AT byu DOT net>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.19) Gecko/20081209 Thunderbird/2.0.0.19 Mnenhy/0.7.5.666
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: GNU coreutils does not work on Cygwin because of freopen() ?
References: <49738867 DOT 702 AT dazjorz DOT com> <49739D07 DOT 7020507 AT cygwin DOT com> <49739E38 DOT 5080305 AT dazjorz DOT com> <4973A2B1 DOT 9060601 AT users DOT sourceforge DOT net> <4973A927 DOT 1010003 AT dazjorz DOT com> <20090118221940 DOT GZ1247 AT hoeg DOT nl>
In-Reply-To: <20090118221940.GZ1247@hoeg.nl>
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Ed Schouten on 1/18/2009 3:19 PM:
> But that's not a proper fix anyway. cat can't just decide to reopen the
> file descriptor of the standard output. That even breaks the first
> sentence of POSIX:
> 
> 	The cat utility shall read files in sequence and shall write
> 	their contents to the standard output in the same sequence.
> 
> If it says "the standard output" doesn't mean you can reopen the output
> descriptor. This means you end up with two different file descriptors.
> They can point to the same file, but they are not the same file
> descriptor.

That's where you are wrong.  freopen can be passed a NULL pointer instead
of a filename in order to reuse the same file descriptor, but with an
implementation-defined different mode.  In cygwin's case, this means you
can use freopen to swap a file between text and binary mode.

> 
> They fixed it by using SET_BINARY(), but not on Cygwin, because I assume
> SET_BINARY() is a Windows-thing, not Cygwin.

SET_BINARY is an upstream coreutils thing designed for cygwin and other
platforms that have O_BINARY in the first place (Debian doesn't).  It is a
macro that expands to either the non-standard setmode(), or the
standardized (but implementation-dependent) freopen().

> 
> I can't really understand why Cygwin just doesn't force O_BINARY to be
> set. File descriptors on UNIX are supposed to display raw file contents.

That's exactly what that freopen is doing - it is forcing O_BINARY to be
set, regardless of how stdin was inherited.

- --
Don't work too hard, make some time for fun as well!

Eric Blake             ebb9 AT byu DOT net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAklzrKgACgkQ84KuGfSFAYCZzACeJcwTKhDejFWZLP8LkhKRkv/4
bj0AniqGtXHep5FcUIavGtl2YOWeSRwQ
=aiau
-----END PGP SIGNATURE-----

--
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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019