> Date: Mon, 07 May 2012 06:44:00 -0600 > From: Eric Blake <ebl...@redhat.com> > CC: bug-gnulib@gnu.org, bug-gnu-ut...@gnu.org > > > FILE * > > rpl_freopen (const char *filename, const char *mode, FILE *stream) > > { > > #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ > > - if (filename != NULL && strcmp (filename, "/dev/null") == 0) > > + if (filename == NULL) > > + { > > + if (strchr (mode, 'b')) > > + return _setmode (_fileno (stream), _O_BINARY) == -1 ? NULL : stream; > > + else > > + return _setmode (_fileno (stream), _O_TEXT) == -1 ? NULL : stream; > > Shouldn't we be doing some sanity checking, as in ensuring that a > read-only stream is not being reopened with 'w', or a write-only stream > is not being reopened with 'r'?
It's desirable, but I don't know how to do that with MinGW. There's no F_GETFL or its equivalent, AFAIK (but I'd be glad to learn that I'm wrong). > Also, shouldn't we be honoring 'w' vs. > 'a' and adjusting the underlying fd's O_APPEND bit accordingly? Again, I don't know how to do that. According to MSDN, _setmode supports only O_BINARY and O_TEXT. If the reality is different, please tell. (One thing that is missing in my patch is a call to fflush, since you cannot switch modes in the middle of a buffered operation.)