From 852a332dbcd42a929bd98de248fdce3cc6edc077 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Sat, 20 Jan 2007 21:14:30 +0000 Subject: Add eglib g_io_channel_write implementation --- eglib/gmain.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'eglib/gmain.c') diff --git a/eglib/gmain.c b/eglib/gmain.c index f14b1f09..08d73eb8 100644 --- a/eglib/gmain.c +++ b/eglib/gmain.c @@ -84,8 +84,39 @@ retry: GIOError g_io_channel_write(GIOChannel *channel, const gchar *buf, gsize count, gsize *bytes_written) { - /* Not implemented */ - return G_IO_STATUS_ERROR; + int fd = channel->fd; + gssize result; + + if (channel->closed) + return G_IO_STATUS_ERROR; + + /* At least according to the Debian manpage for read */ + if (count > SSIZE_MAX) + count = SSIZE_MAX; + +retry: + result = write(fd, buf, count); + + if (result < 0) { + *bytes_read = 0; + + switch (errno) { +#ifdef EINTR + case EINTR: + goto retry; +#endif +#ifdef EAGAIN + case EAGAIN: + return G_IO_STATUS_AGAIN; +#endif + default: + return G_IO_STATUS_ERROR; + } + } + + *bytes_written = result; + + return (result > 0) ? G_IO_STATUS_NORMAL : G_IO_STATUS_EOF; } void g_io_channel_close(GIOChannel *channel) -- cgit