diff options
| author | Johan Hedberg <johan.hedberg@nokia.com> | 2006-08-26 16:55:47 +0000 | 
|---|---|---|
| committer | Johan Hedberg <johan.hedberg@nokia.com> | 2006-08-26 16:55:47 +0000 | 
| commit | ea7b976177bffc7f3c89e380a1273e1d85b2a24f (patch) | |
| tree | 146321302301da35c12ae5ac10fd6f6700c13945 /common/glib-ectomy.c | |
| parent | 448146fdeb6a90cdf11826fcdc88ce9068eb9646 (diff) | |
Cleanup/fix glib-ectomy.c and its usage
Diffstat (limited to 'common/glib-ectomy.c')
| -rw-r--r-- | common/glib-ectomy.c | 23 | 
1 files changed, 22 insertions, 1 deletions
| diff --git a/common/glib-ectomy.c b/common/glib-ectomy.c index 41641ee6..33d20533 100644 --- a/common/glib-ectomy.c +++ b/common/glib-ectomy.c @@ -24,6 +24,11 @@ struct timeout {  	GSourceFunc function;  }; +struct _GIOChannel { +	int fd; +	gboolean close_on_unref; +}; +  struct _GMainContext {  	guint next_id;  	glong next_timeout; @@ -82,8 +87,17 @@ void g_io_channel_close(GIOChannel *channel)  		return;  	close(channel->fd); +	channel->fd = -1; +} + +void g_io_channel_unref(GIOChannel *channel) +{ +	if (!channel) +		return; + +	if (channel->close_on_unref && channel->fd >= 0) +		g_io_channel_close(channel); -	memset(channel, 0, sizeof(channel));  	free(channel);  } @@ -95,11 +109,18 @@ GIOChannel *g_io_channel_unix_new(int fd)  	if (!channel)  		return NULL; +	memset(channel, 0, sizeof(GIOChannel)); +  	channel->fd = fd;  	return channel;  } +void g_io_channel_set_close_on_unref(GIOChannel *channel, gboolean do_close) +{ +	channel->close_on_unref = do_close; +} +  gint g_io_channel_unix_get_fd(GIOChannel *channel)  {  	return channel->fd; | 
