Fix abort in GC_printf when gctest is built as WinMain executable (Cygwin)
authorIvan Maidanski <ivmai@mail.ru>
Sat, 9 Nov 2019 06:14:32 +0000 (09:14 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Sat, 9 Nov 2019 06:14:32 +0000 (09:14 +0300)
* misc.c [!NACL && (CYGWIN32 || CONSOLE_LOG && MSWIN32)] (GC_printf):
If WRITE(GC_stdout) failed but GC_stdout is GC_DEFAULT_STDOUT_FD then
ignore the failure.
* misc.c [!NACL && (CYGWIN32 || CONSOLE_LOG && MSWIN32)]
(GC_log_printf): If WRITE(GC_log) failed but GC_log is
GC_DEFAULT_STDERR_FD then ignore the failure.

misc.c

diff --git a/misc.c b/misc.c
index 438ef2c..1d35a19 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -1807,8 +1807,13 @@ void GC_printf(const char *format, ...)
         (void)WRITE(GC_stdout, buf, strlen(buf));
         /* Ignore errors silently.      */
 #     else
-        if (WRITE(GC_stdout, buf, strlen(buf)) < 0)
+        if (WRITE(GC_stdout, buf, strlen(buf)) < 0
+#           if defined(CYGWIN32) || (defined(CONSOLE_LOG) && defined(MSWIN32))
+              && GC_stdout != GC_DEFAULT_STDOUT_FD
+#           endif
+           ) {
           ABORT("write to stdout failed");
+        }
 #     endif
     }
 }
@@ -1829,8 +1834,13 @@ void GC_log_printf(const char *format, ...)
 #   ifdef NACL
       (void)WRITE(GC_log, buf, strlen(buf));
 #   else
-      if (WRITE(GC_log, buf, strlen(buf)) < 0)
+      if (WRITE(GC_log, buf, strlen(buf)) < 0
+#         if defined(CYGWIN32) || (defined(CONSOLE_LOG) && defined(MSWIN32))
+            && GC_log != GC_DEFAULT_STDERR_FD
+#         endif
+         ) {
         ABORT("write to GC log failed");
+      }
 #   endif
 }