From: Ron Steinke Date: Mon, 23 Jul 2001 16:49:59 +0000 (+0000) Subject: fixed g_io_channel_seek_position() so that G_SEEK_CUR works for UTF-8 X-Git-Tag: GLIB_1_3_7~70 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d403f5f219f609a6abad44fe85efd401fc25102a;p=platform%2Fupstream%2Fglib.git fixed g_io_channel_seek_position() so that G_SEEK_CUR works for UTF-8 * glib/giochannel.c: fixed g_io_channel_seek_position() so that G_SEEK_CUR works for UTF-8 channel encoding, and unallocated converters are not flushed after the seek; fixed g_io_channel_get_buffer_condition() so that G_IO_IN is only set if the read buffer contains at least one full character --- diff --git a/ChangeLog b/ChangeLog index affe8f9..534c777 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2001-07-23 Ron Steinke + + * glib/giochannel.c: fixed g_io_channel_seek_position() so that + G_SEEK_CUR works for UTF-8 channel encoding, and unallocated + converters are not flushed after the seek; fixed + g_io_channel_get_buffer_condition() so that G_IO_IN is only + set if the read buffer contains at least one full character + 2001-07-23 Sven Neumann * Makefile.am: removed glib.def from EXTRA_DIST ... diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index affe8f9..534c777 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,11 @@ +2001-07-23 Ron Steinke + + * glib/giochannel.c: fixed g_io_channel_seek_position() so that + G_SEEK_CUR works for UTF-8 channel encoding, and unallocated + converters are not flushed after the seek; fixed + g_io_channel_get_buffer_condition() so that G_IO_IN is only + set if the read buffer contains at least one full character + 2001-07-23 Sven Neumann * Makefile.am: removed glib.def from EXTRA_DIST ... diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index affe8f9..534c777 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,11 @@ +2001-07-23 Ron Steinke + + * glib/giochannel.c: fixed g_io_channel_seek_position() so that + G_SEEK_CUR works for UTF-8 channel encoding, and unallocated + converters are not flushed after the seek; fixed + g_io_channel_get_buffer_condition() so that G_IO_IN is only + set if the read buffer contains at least one full character + 2001-07-23 Sven Neumann * Makefile.am: removed glib.def from EXTRA_DIST ... diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index affe8f9..534c777 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,11 @@ +2001-07-23 Ron Steinke + + * glib/giochannel.c: fixed g_io_channel_seek_position() so that + G_SEEK_CUR works for UTF-8 channel encoding, and unallocated + converters are not flushed after the seek; fixed + g_io_channel_get_buffer_condition() so that G_IO_IN is only + set if the read buffer contains at least one full character + 2001-07-23 Sven Neumann * Makefile.am: removed glib.def from EXTRA_DIST ... diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index affe8f9..534c777 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,11 @@ +2001-07-23 Ron Steinke + + * glib/giochannel.c: fixed g_io_channel_seek_position() so that + G_SEEK_CUR works for UTF-8 channel encoding, and unallocated + converters are not flushed after the seek; fixed + g_io_channel_get_buffer_condition() so that G_IO_IN is only + set if the read buffer contains at least one full character + 2001-07-23 Sven Neumann * Makefile.am: removed glib.def from EXTRA_DIST ... diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index affe8f9..534c777 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,11 @@ +2001-07-23 Ron Steinke + + * glib/giochannel.c: fixed g_io_channel_seek_position() so that + G_SEEK_CUR works for UTF-8 channel encoding, and unallocated + converters are not flushed after the seek; fixed + g_io_channel_get_buffer_condition() so that G_IO_IN is only + set if the read buffer contains at least one full character + 2001-07-23 Sven Neumann * Makefile.am: removed glib.def from EXTRA_DIST ... diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index affe8f9..534c777 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,11 @@ +2001-07-23 Ron Steinke + + * glib/giochannel.c: fixed g_io_channel_seek_position() so that + G_SEEK_CUR works for UTF-8 channel encoding, and unallocated + converters are not flushed after the seek; fixed + g_io_channel_get_buffer_condition() so that G_IO_IN is only + set if the read buffer contains at least one full character + 2001-07-23 Sven Neumann * Makefile.am: removed glib.def from EXTRA_DIST ... diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index affe8f9..534c777 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,11 @@ +2001-07-23 Ron Steinke + + * glib/giochannel.c: fixed g_io_channel_seek_position() so that + G_SEEK_CUR works for UTF-8 channel encoding, and unallocated + converters are not flushed after the seek; fixed + g_io_channel_get_buffer_condition() so that G_IO_IN is only + set if the read buffer contains at least one full character + 2001-07-23 Sven Neumann * Makefile.am: removed glib.def from EXTRA_DIST ... diff --git a/glib/giochannel.c b/glib/giochannel.c index bfe42cc..01f503d 100644 --- a/glib/giochannel.c +++ b/glib/giochannel.c @@ -477,9 +477,16 @@ g_io_channel_get_buffer_condition (GIOChannel *channel) { GIOCondition condition = 0; - if ((channel->read_buf && (channel->read_buf->len > 0)) /* FIXME full chars how? */ - || (channel->encoded_read_buf && (channel->encoded_read_buf->len > 0))) - condition |= G_IO_IN; + if (channel->encoding) + { + if (channel->encoded_read_buf && (channel->encoded_read_buf->len > 0)) + condition |= G_IO_IN; /* Only return if we have full characters */ + } + else + { + if (channel->read_buf && (channel->read_buf->len > 0)) + condition |= G_IO_IN; + } if (channel->write_buf && (channel->write_buf->len < channel->buf_size)) condition |= G_IO_OUT; @@ -727,7 +734,8 @@ g_io_channel_seek_position (GIOChannel* channel, case G_SEEK_CUR: /* The user is seeking relative to the head of the buffer */ if (channel->use_buffer) { - if (channel->encoded_read_buf && channel->encoded_read_buf->len > 0) + if (channel->do_encode && channel->encoded_read_buf + && channel->encoded_read_buf->len > 0) { g_warning ("Seek type G_SEEK_CUR not allowed for this" " channel's encoding.\n"); @@ -735,6 +743,17 @@ g_io_channel_seek_position (GIOChannel* channel, } if (channel->read_buf) offset -= channel->read_buf->len; + if (channel->encoded_read_buf) + { + g_assert (channel->encoded_read_buf->len == 0 && !channel->do_encode); + + /* If there's anything here, it's because the encoding is UTF-8, + * so we can just subtract the buffer length, the same as for + * the unencoded data. + */ + + offset -= channel->encoded_read_buf->len; + } } break; case G_SEEK_SET: @@ -758,13 +777,19 @@ g_io_channel_seek_position (GIOChannel* channel, { if (channel->read_buf) g_string_truncate (channel->read_buf, 0); - if (channel->do_encode) /* Conversion state no longer matches position in file */ + + /* Conversion state no longer matches position in file */ + if (channel->read_cd != (GIConv) -1) + g_iconv (channel->read_cd, NULL, NULL, NULL, NULL); + if (channel->write_cd != (GIConv) -1) + g_iconv (channel->write_cd, NULL, NULL, NULL, NULL); + + if (channel->encoded_read_buf) { - g_iconv (channel->read_cd, NULL, NULL, NULL, NULL); - g_iconv (channel->write_cd, NULL, NULL, NULL, NULL); - if (channel->encoded_read_buf) - g_string_truncate (channel->encoded_read_buf, 0); + g_assert (channel->encoded_read_buf->len == 0 || !channel->do_encode); + g_string_truncate (channel->encoded_read_buf, 0); } + if (channel->partial_write_buf[0] != '\0') { g_warning ("Partial character at end of write buffer not flushed.\n");