Re: Gnulib's freopen replacement and MinGW
Bruno Haible <[email protected]>
| Newsgroups | gmane.comp.lib.gnulib.bugs,gmane.comp.gnu.utils.bugs |
|---|---|
| Message-ID | <2214520.EIfM7YPUri@linuix> |
Hi Eli, > Diffutils 3.2 call xfreopen with its first argument NULL, expecting > the underlying reopen to handle this. However, the MS runtime does > not implement the Posix semantics of such a call, and so, for example, > MinGW-compiled cmp fails when invoked to compare its stdin with a > file: > > D:\gnu\diffutils-3.2\src>cat cmp.c | cmp cmp.c - > cmp: failed to reopen `stdin' with mode `rb': No such file or directory > > The following change fixes this: > > 2012-05-05 Eli Zaretskii <[email protected]> > > * lib/freopen.c [_WIN32]: Include io.h and fcntl.h. > (rpl_freopen) [_WIN32]: If the first argument is NULL, call > _setmode to switch STREAM to either binary or text mode, as > specified by MODE. Thanks for the proposed patch, but the problem has already been fixed differently, by avoiding to use xfreopen() [1]. The question whether to extend gnulib's freopen() to support this use-case was discussed in the thread [2][3]. The result of that discussion was "no", because - POSIX says that it is "implementation-defined" whether freopen() supports this [4], - freopen with a NULL filename is not supported on many Unix platforms, - there is no point for the caller to use the freopen() API when the same effect can be achieved with <binary-io.h>. Bruno [1] http://git.savannah.gnu.org/gitweb/?p=diffutils.git;a=commitdiff;h=7508234eabe646abcea074baea83612f8115d3b9 [2] http://lists.gnu.org/archive/html/bug-gnulib/2011-08/msg00224.html [3] http://lists.gnu.org/archive/html/bug-gnulib/2011-09/msg00005.html [4] http://pubs.opengroup.org/onlinepubs/9699919799/functions/freopen.html