This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: GNU coreutils does not work on Cygwin because of freopen() ?
-----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@byu.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/