Hi.

When calling 

freopen(NULL, mode, stream);

on MS Windows using MinGW segfaults because it tries to strcmp(NULL,
"/dev/null")... *ouch*

--------------------
--- freopen.c.orig      2011-08-03 14:22:15 +0200
+++ freopen.c   2011-08-25 21:01:46 +0200
@@ -38,7 +38,7 @@
 rpl_freopen (const char *filename, const char *mode, FILE *stream)
 {
 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-  if (strcmp (filename, "/dev/null") == 0)
+  if (filename && strcmp (filename, "/dev/null") == 0)
     filename = "NUL";
 #endif
 
--------------------

Furthermore, using NULL as filename does not work at all using the MS
C runtime library (debug assertion violation).

--------------------
--- freopen.c.1 2011-08-25 21:05:34 +0200
+++ freopen.c   2011-08-25 21:08:52 +0200
@@ -38,6 +38,9 @@
 rpl_freopen (const char *filename, const char *mode, FILE *stream)
 {
 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+#  ifdef _MSC_VER
+  if (!filename) return NULL; /* would trigger a runtime error on MSVC */
+#  endif
   if (filename && strcmp (filename, "/dev/null") == 0)
     filename = "NUL";
 #endif

--------------------

Using MinGW and trying to change stdout's mode to binary simply fails:

if (!isatty(fileno(stdout))
   freopen(NULL, "wb", stdout); /* <- returns NULL */

Would it be feasible to use the _setmode function in rpl_freopen
instead of freopen if the filename == NULL on win32 (non-cygwin)?

What about the fsetbinary, xfchangemode functions discussed here
[http://lists.gnu.org/archive/html/bug-gnulib/2010-03/msg00111.html]?


Cheers,
-- 
Claudio


Reply via email to