2001-08-05 Ron Steinke <rsteinke@w-link.net>
+ * glib/giochannel.c glib/giochannel.c glib/glib.def
+ docs/reference/glib/glib-sections.txt: Added new functions
+ g_io_channel_[read,write]_unichar ()
+
+ * glib/giochannel.h: Finally remembered to remove the
+ old error message G_IO_CHANNEL_ERROR_PCHAR_FLUSH
+
+ * glib/giochannel.c: Some fixes to g_io_channel_fill_buffer ()
+ and g_io_channel_write_chars ()
+
+2001-08-05 Ron Steinke <rsteinke@w-link.net>
+
* glib/giochannel.c: Replaced the local use_buf variable with a macro
in most places. This allows us to check some things without worrying
whether we have allocated the read buffers yet, and allows us to allocate
2001-08-05 Ron Steinke <rsteinke@w-link.net>
+ * glib/giochannel.c glib/giochannel.c glib/glib.def
+ docs/reference/glib/glib-sections.txt: Added new functions
+ g_io_channel_[read,write]_unichar ()
+
+ * glib/giochannel.h: Finally remembered to remove the
+ old error message G_IO_CHANNEL_ERROR_PCHAR_FLUSH
+
+ * glib/giochannel.c: Some fixes to g_io_channel_fill_buffer ()
+ and g_io_channel_write_chars ()
+
+2001-08-05 Ron Steinke <rsteinke@w-link.net>
+
* glib/giochannel.c: Replaced the local use_buf variable with a macro
in most places. This allows us to check some things without worrying
whether we have allocated the read buffers yet, and allows us to allocate
2001-08-05 Ron Steinke <rsteinke@w-link.net>
+ * glib/giochannel.c glib/giochannel.c glib/glib.def
+ docs/reference/glib/glib-sections.txt: Added new functions
+ g_io_channel_[read,write]_unichar ()
+
+ * glib/giochannel.h: Finally remembered to remove the
+ old error message G_IO_CHANNEL_ERROR_PCHAR_FLUSH
+
+ * glib/giochannel.c: Some fixes to g_io_channel_fill_buffer ()
+ and g_io_channel_write_chars ()
+
+2001-08-05 Ron Steinke <rsteinke@w-link.net>
+
* glib/giochannel.c: Replaced the local use_buf variable with a macro
in most places. This allows us to check some things without worrying
whether we have allocated the read buffers yet, and allows us to allocate
2001-08-05 Ron Steinke <rsteinke@w-link.net>
+ * glib/giochannel.c glib/giochannel.c glib/glib.def
+ docs/reference/glib/glib-sections.txt: Added new functions
+ g_io_channel_[read,write]_unichar ()
+
+ * glib/giochannel.h: Finally remembered to remove the
+ old error message G_IO_CHANNEL_ERROR_PCHAR_FLUSH
+
+ * glib/giochannel.c: Some fixes to g_io_channel_fill_buffer ()
+ and g_io_channel_write_chars ()
+
+2001-08-05 Ron Steinke <rsteinke@w-link.net>
+
* glib/giochannel.c: Replaced the local use_buf variable with a macro
in most places. This allows us to check some things without worrying
whether we have allocated the read buffers yet, and allows us to allocate
2001-08-05 Ron Steinke <rsteinke@w-link.net>
+ * glib/giochannel.c glib/giochannel.c glib/glib.def
+ docs/reference/glib/glib-sections.txt: Added new functions
+ g_io_channel_[read,write]_unichar ()
+
+ * glib/giochannel.h: Finally remembered to remove the
+ old error message G_IO_CHANNEL_ERROR_PCHAR_FLUSH
+
+ * glib/giochannel.c: Some fixes to g_io_channel_fill_buffer ()
+ and g_io_channel_write_chars ()
+
+2001-08-05 Ron Steinke <rsteinke@w-link.net>
+
* glib/giochannel.c: Replaced the local use_buf variable with a macro
in most places. This allows us to check some things without worrying
whether we have allocated the read buffers yet, and allows us to allocate
2001-08-05 Ron Steinke <rsteinke@w-link.net>
+ * glib/giochannel.c glib/giochannel.c glib/glib.def
+ docs/reference/glib/glib-sections.txt: Added new functions
+ g_io_channel_[read,write]_unichar ()
+
+ * glib/giochannel.h: Finally remembered to remove the
+ old error message G_IO_CHANNEL_ERROR_PCHAR_FLUSH
+
+ * glib/giochannel.c: Some fixes to g_io_channel_fill_buffer ()
+ and g_io_channel_write_chars ()
+
+2001-08-05 Ron Steinke <rsteinke@w-link.net>
+
* glib/giochannel.c: Replaced the local use_buf variable with a macro
in most places. This allows us to check some things without worrying
whether we have allocated the read buffers yet, and allows us to allocate
2001-08-05 Ron Steinke <rsteinke@w-link.net>
+ * glib/giochannel.c glib/giochannel.c glib/glib.def
+ docs/reference/glib/glib-sections.txt: Added new functions
+ g_io_channel_[read,write]_unichar ()
+
+ * glib/giochannel.h: Finally remembered to remove the
+ old error message G_IO_CHANNEL_ERROR_PCHAR_FLUSH
+
+ * glib/giochannel.c: Some fixes to g_io_channel_fill_buffer ()
+ and g_io_channel_write_chars ()
+
+2001-08-05 Ron Steinke <rsteinke@w-link.net>
+
* glib/giochannel.c: Replaced the local use_buf variable with a macro
in most places. This allows us to check some things without worrying
whether we have allocated the read buffers yet, and allows us to allocate
2001-08-05 Ron Steinke <rsteinke@w-link.net>
+ * glib/giochannel.c glib/giochannel.c glib/glib.def
+ docs/reference/glib/glib-sections.txt: Added new functions
+ g_io_channel_[read,write]_unichar ()
+
+ * glib/giochannel.h: Finally remembered to remove the
+ old error message G_IO_CHANNEL_ERROR_PCHAR_FLUSH
+
+ * glib/giochannel.c: Some fixes to g_io_channel_fill_buffer ()
+ and g_io_channel_write_chars ()
+
+2001-08-05 Ron Steinke <rsteinke@w-link.net>
+
* glib/giochannel.c: Replaced the local use_buf variable with a macro
in most places. This allows us to check some things without worrying
whether we have allocated the read buffers yet, and allows us to allocate
<SUBSECTION>
g_io_channel_new_file
g_io_channel_read_chars
+g_io_channel_read_unichar
g_io_channel_read_line
g_io_channel_read_line_string
g_io_channel_read_to_end
g_io_channel_write_chars
+g_io_channel_write_unichar
g_io_channel_flush
g_io_channel_seek_position
GSeekType
reencode:
inbytes_left = channel->read_buf->len;
- outbytes_left = MIN (channel->buf_size / 4,
+ outbytes_left = MAX (6, MAX (channel->read_buf->len,
channel->encoded_read_buf->allocated_len
- - channel->encoded_read_buf->len);
+ - channel->encoded_read_buf->len));
+
+ inbuf = channel->read_buf->str;
+ outbuf = channel->encoded_read_buf->str + channel->encoded_read_buf->len;
g_string_set_size (channel->encoded_read_buf,
channel->encoded_read_buf->len + outbytes_left);
- inbuf = channel->read_buf->str;
- outbuf = channel->encoded_read_buf->str + channel->encoded_read_buf->len
- - outbytes_left;
-
errnum = g_iconv (channel->read_cd, &inbuf, &inbytes_left,
&outbuf, &outbytes_left);
status = G_IO_STATUS_NORMAL;
break;
case E2BIG:
+ /* Buffer size at least 6, wrote at least on character */
+ g_assert (inbuf != channel->read_buf->str);
goto reencode;
case EILSEQ:
if (oldlen < channel->encoded_read_buf->len)
}
/**
+ * g_io_channel_read_unichar:
+ * @channel: a #GIOChannel
+ * @thechar: a location to return a character
+ * @error: A location to return an error of type #GConvertError
+ * or #GIOChannelError
+ *
+ * This function cannot be called on a channel with %NULL encoding.
+ *
+ * Return value: a #GIOStatus
+ **/
+GIOStatus
+g_io_channel_read_unichar (GIOChannel *channel,
+ gunichar *thechar,
+ GError **error)
+{
+ GIOStatus status = G_IO_STATUS_NORMAL;
+
+ g_return_val_if_fail (channel != NULL, G_IO_STATUS_ERROR);
+ g_return_val_if_fail (channel->encoding != NULL, G_IO_STATUS_ERROR);
+ g_return_val_if_fail ((error == NULL) || (*error == NULL),
+ G_IO_STATUS_ERROR);
+ g_return_val_if_fail (channel->is_readable, G_IO_STATUS_ERROR);
+
+ while (BUF_LEN (channel->encoded_read_buf) == 0 && status == G_IO_STATUS_NORMAL)
+ status = g_io_channel_fill_buffer (channel, error);
+
+ /* Only return an error if we have no data */
+
+ if (BUF_LEN (USE_BUF (channel)) == 0)
+ {
+ g_assert (status != G_IO_STATUS_NORMAL);
+
+ if (status == G_IO_STATUS_EOF && BUF_LEN (channel->read_buf) > 0)
+ {
+ g_set_error (error, G_CONVERT_ERROR,
+ G_CONVERT_ERROR_PARTIAL_INPUT,
+ "Leftover unconverted data in read buffer");
+ status = G_IO_STATUS_ERROR;
+ }
+
+ if (thechar)
+ *thechar = (gunichar) -1;
+
+ return status;
+ }
+
+ if (status == G_IO_STATUS_ERROR)
+ g_clear_error (error);
+
+ if (thechar)
+ *thechar = g_utf8_get_char (channel->encoded_read_buf->str);
+
+ g_string_erase (channel->encoded_read_buf, 0,
+ g_utf8_next_char (channel->encoded_read_buf->str)
+ - channel->encoded_read_buf->str);
+
+ return G_IO_STATUS_NORMAL;
+}
+
+/**
* g_io_channel_write_chars:
* @channel: a #GIOChannel
* @buf: a buffer to write data from
gssize wrote_bytes = 0;
g_return_val_if_fail (channel != NULL, G_IO_STATUS_ERROR);
- g_return_val_if_fail (bytes_written != NULL, G_IO_STATUS_ERROR);
g_return_val_if_fail ((error == NULL) || (*error == NULL),
G_IO_STATUS_ERROR);
g_return_val_if_fail (channel->is_writeable, G_IO_STATUS_ERROR);
did_write += this_time;
}
while (status == G_IO_STATUS_NORMAL &&
- did_write < MIN (channel->write_buf->len,
- MAX (MAX_CHAR_SIZE, channel->buf_size / 4)));
+ did_write < MIN (channel->write_buf->len, MAX_CHAR_SIZE));
g_string_erase (channel->write_buf, 0, did_write);
return G_IO_STATUS_NORMAL;
}
+/**
+ * g_io_channel_write_unichar:
+ * @channel: a #GIOChannel
+ * @thechar: a character
+ * @error: A location to return an error of type #GConvertError
+ * or #GIOChannelError
+ *
+ * This function cannot be called on a channel with %NULL encoding.
+ *
+ * Return value: a #GIOStatus
+ **/
+GIOStatus
+g_io_channel_write_unichar (GIOChannel *channel,
+ gunichar thechar,
+ GError **error)
+{
+ GIOStatus status;
+ gchar static_buf[6];
+ gsize char_len, wrote_len;
+
+ g_return_val_if_fail (channel != NULL, G_IO_STATUS_ERROR);
+ g_return_val_if_fail (channel->encoding != NULL, G_IO_STATUS_ERROR);
+ g_return_val_if_fail ((error == NULL) || (*error == NULL),
+ G_IO_STATUS_ERROR);
+ g_return_val_if_fail (channel->is_writeable, G_IO_STATUS_ERROR);
+
+ char_len = g_unichar_to_utf8 (thechar, static_buf);
+
+ if (channel->partial_write_buf[0] != '\0')
+ {
+ g_warning ("Partial charater written before writing unichar.\n");
+ channel->partial_write_buf[0] = '\0';
+ }
+
+ status = g_io_channel_write_chars (channel, static_buf,
+ char_len, &wrote_len, error);
+
+ /* We validate UTF-8, so we can't get a partial write */
+
+ g_assert (wrote_len == char_len || status != G_IO_STATUS_NORMAL);
+
+ return status;
+}
/**
* g_io_channel_error_quark:
G_IO_CHANNEL_ERROR_OVERFLOW,
G_IO_CHANNEL_ERROR_PIPE,
/* Other */
- G_IO_CHANNEL_ERROR_PCHAR_FLUSH,
- /* Unconverted partial UTF-8 chars in buffer during flush */
G_IO_CHANNEL_ERROR_FAILED
} GIOChannelError;
gsize count,
gsize *bytes_read,
GError **error);
+GIOStatus g_io_channel_read_unichar (GIOChannel *channel,
+ gunichar *thechar,
+ GError **error);
GIOStatus g_io_channel_write_chars (GIOChannel *channel,
const gchar *buf,
gssize count,
gsize *bytes_written,
GError **error);
+GIOStatus g_io_channel_write_unichar (GIOChannel *channel,
+ gunichar thechar,
+ GError **error);
GIOStatus g_io_channel_seek_position (GIOChannel *channel,
glong offset,
GSeekType type,
g_io_channel_read_line
g_io_channel_read_line_string
g_io_channel_read_to_end
+ g_io_channel_read_unichar
g_io_channel_ref
g_io_channel_seek
g_io_channel_seek_position
g_io_channel_win32_set_debug
g_io_channel_write
g_io_channel_write_chars
+ g_io_channel_write_unichar
g_io_create_watch
g_list_alloc
g_list_append