summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2013-05-22 14:20:08 -0300
committerDan Winship <danw@gnome.org>2013-05-22 14:25:50 -0300
commit9115dd0a7ce31f69f78aca0b0b32d7d2e4670be3 (patch)
tree62b6717d5a5cb0a8518e808b2f5b7e96e39c3e78
parentc9cc0beb3a8c298b843efdb71822a71cc078a8ac (diff)
downloadglib-9115dd0a7ce31f69f78aca0b0b32d7d2e4670be3.tar.gz
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.
-rw-r--r--glib/gtestutils.c15
1 files changed, 6 insertions, 9 deletions
diff --git a/glib/gtestutils.c b/glib/gtestutils.c
index b5cb321d3..c57b3d95b 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;
}
}