diff options
author | Johan Hedberg <johan.hedberg@nokia.com> | 2007-01-20 21:14:30 +0000 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@nokia.com> | 2007-01-20 21:14:30 +0000 |
commit | 852a332dbcd42a929bd98de248fdce3cc6edc077 (patch) | |
tree | f169272ca072083441373c13ade9de2c3e17c9d9 /eglib | |
parent | 5d3f7702c50861f7f7f5ebeb160ef0073a5470f5 (diff) |
Add eglib g_io_channel_write implementation
Diffstat (limited to 'eglib')
-rw-r--r-- | eglib/gmain.c | 35 |
1 files changed, 33 insertions, 2 deletions
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) |