encoding of GIOChannel
- From: Shixin Zeng <shixinzeng gmail com>
- To: gtk-app-devel-list gnome org
- Subject: encoding of GIOChannel
- Date: Fri, 10 Dec 2004 00:36:21 +0800
The parent process use two pipes to communicate with the child, one
for read and the other one for write.
gboolean to_child(gpointer io)
{
printf("%s\n", __FUNCTION__);
GIOChannel *cl = (GIOChannel *)io;
gchar *buff = g_new0(gchar, 1024);
fgets(buff, 1024, stdin);
GError *error = NULL;
if(G_IO_STATUS_ERROR == g_io_channel_write_chars(cl, buff, 1024,
NULL, &error)){
printf("error: %s", error->message);
}
g_free(buff);
return TRUE;
}
in main:
GIOChannel *parent_in = g_io_channel_unix_new(pipe_child_stdout[0]);
GIOChannel *parent_out = g_io_channel_unix_new(pipe_child_stdin[1]);
const char* charset;
if(g_get_charset(&charset))
if(G_IO_STATUS_ERROR == g_io_channel_set_encoding(parent_in, charset, NULL)
|| G_IO_STATUS_ERROR ==g_io_channel_set_encoding(parent_out,
charset, NULL)){/*IF I SET THE CHARSET TO NULL, IT WORKS FINE*/
perror("Setting encoding error");
}
g_free(charset);
g_io_add_watch(parent_in, G_IO_IN, from_child, main_loop);
g_idle_add(to_child, parent_out);
It compiles fine, but I got a runtime error, when I input something:
GLib: Cannot convert message: Conversion from character set 'UTF-8' to
'' is not supported
GLib-ERROR **: file giochannel.c: line 2113
(g_io_channel_write_chars): should not be reached
aborting...
Program received signal SIGABRT, Aborted.
Any help?
My locales:
LANG=en_US.UTF-8
LC_CTYPE=zh_CN.UTF-8
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
--
Best regards
Shixin Zeng
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]