[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Gnulib's freopen replacement and MinGW

From: Eric Blake
Subject: Re: Gnulib's freopen replacement and MinGW
Date: Mon, 07 May 2012 12:44:56 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120430 Thunderbird/12.0.1

[adding coreutils]

On 05/07/2012 12:11 PM, Bruno Haible wrote:
> Eric Blake wrote:
>> POSIX says that such a call is implementation-defined, so technically,
>> mingw DOES implement the POSIX semantics (by defining that it is
>> unsupported).
> Yes. So, code in freopen.c that would try to support a NULL argument
> in all cases
>   - would be a gnulib extension,
>   - would not be usable to change the read vs. write vs. append mode,
>     because on many systems we would need to fiddle with FILE internals,
>     which is hard and not reliable,
>   - would be only useful to change the text vs. binary mode. But for this
>     purpose gnulib already offers a simpler API: binary-io.h.
>> However, you are correct that it is annoying, and
>> something that gnulib could work around for easier coding.
> I don't agree. It's not easier coding to write
>   xfreopen (NULL, "rb", fp);
> instead of
>   SET_BINARY (fileno (fp));

Waaaay back when, coreutils used to use SET_BINARY.  We changed that to
use freopen(NULL) because of the POSIX wording that allowed NULL to
change mode, because cygwin honored the mode change, and because Paul
preferred using a POSIX interface over a complete extension interface.

Commit 8770c00ef, Jul 2005

Also, at one point, I proposed a patch to xfreopen, to which Bruno
counterproposed a new API fchangemode() that would alter a FILE* to be
binary without the baggage of freopen(NULL), although I never really
pursued it:


Now it looks like we've come full circle, and that the POSIX wording of
freopen(NULL) is so broken as to not be worth using via gnulib, and
we're back to preferring extension interfaces in the form of SET_BINARY.
 It looks like several projects will have to change, coreutils included,
if we indeed decide that use of freopen(NULL) is no longer desirable.

Eric Blake   address@hidden    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]