[glib] gtestutils: Use stdio rather than write() to be Windows-friendly



commit 9115dd0a7ce31f69f78aca0b0b32d7d2e4670be3
Author: Dan Winship <danw gnome org>
Date:   Wed May 22 14:20:08 2013 -0300

    gtestutils: Use stdio rather than write() to be Windows-friendly
    
    Windows doesn't define STDOUT_FILENO and STDERR_FILENO, and they're
    not even guaranteed to be 1 and 2. So just use stdio instead. Also fix
    a counting error. Pointed out on gtk-devel-list.

 glib/gtestutils.c |   15 ++++++---------
 1 files changed, 6 insertions(+), 9 deletions(-)
---
diff --git a/glib/gtestutils.c b/glib/gtestutils.c
index b5cb321..c57b3d9 100644
--- a/glib/gtestutils.c
+++ b/glib/gtestutils.c
@@ -2252,7 +2252,7 @@ child_read (GIOChannel *io, GIOCondition cond, gpointer user_data)
   GIOStatus status;
   gsize nread, nwrote, total;
   gchar buf[4096];
-  int echo_fd = -1;
+  FILE *echo_file = NULL;
 
   status = g_io_channel_read_chars (io, buf, sizeof (buf), &nread, NULL);
   if (status == G_IO_STATUS_ERROR || status == G_IO_STATUS_EOF)
@@ -2273,25 +2273,22 @@ child_read (GIOChannel *io, GIOCondition cond, gpointer user_data)
     {
       g_string_append_len (data->stdout_str, buf, nread);
       if (data->echo_stdout)
-        echo_fd = STDOUT_FILENO;
+        echo_file = stdout;
     }
   else
     {
       g_string_append_len (data->stderr_str, buf, nread);
       if (data->echo_stderr)
-        echo_fd = STDERR_FILENO;
+        echo_file = stderr;
     }
 
-  if (echo_fd != -1)
+  if (echo_file)
     {
       for (total = 0; total < nread; total += nwrote)
         {
-          do
-            nwrote = write (echo_fd, buf + total, nread - total);
-          while (nwrote == -1 && errno == EINTR);
-          if (nwrote == -1)
+          nwrote = fwrite (buf + total, 1, nread - total, echo_file);
+          if (nwrote == 0)
             g_error ("write failed: %s", g_strerror (errno));
-          total += nwrote;
         }
     }
 


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