+static CORBA_long
+accessible_content_stream_client_seek (const Accessibility_ContentStream stream,
+ CORBA_long offset,
+ Accessibility_ContentStream_SeekType seek_type,
+ CORBA_Environment *opt_ev)
+{
+ CORBA_Environment *ev, temp_ev;
+ CORBA_long ret_offset;
+
+ if (!opt_ev) {
+ CORBA_exception_init (&temp_ev);
+ ev = &temp_ev;
+ } else
+ ev = opt_ev;
+
+ ret_offset = Accessibility_ContentStream_seek (stream, offset, seek_type, ev);
+ if (BONOBO_EX (ev))
+ ret_offset = -1;
+
+ if (!opt_ev)
+ CORBA_exception_free (&temp_ev);
+
+ return ret_offset;
+}
+
+static guint8*
+accessible_content_stream_client_read (const Accessibility_ContentStream stream,
+ const size_t size,
+ CORBA_long *length_read,
+ CORBA_Environment *ev)
+{
+ size_t pos;
+ guint8 *mem;
+ size_t length;
+
+ g_return_val_if_fail (ev != NULL, NULL);
+
+ if (length_read)
+ *length_read = size;
+
+ length = size;
+
+ if (length == 0)
+ return NULL;
+
+ mem = g_try_malloc (length);
+ if (!mem) {
+ CORBA_exception_set_system (ev, ex_CORBA_NO_MEMORY,
+ CORBA_COMPLETED_NO);
+ return NULL;
+ }
+
+ *length_read = 0;
+
+ for (pos = 0; pos < length;) {
+ Bonobo_Stream_iobuf *buf;
+ CORBA_long len;
+
+ len = (pos + CORBA_BLOCK_SIZE < length) ?
+ CORBA_BLOCK_SIZE : length - pos;
+
+ Accessibility_ContentStream_read (stream, len, &buf, ev);
+
+ if (BONOBO_EX (ev) || !buf)
+ goto io_error;
+
+ if (buf->_length > 0) {
+ memcpy (mem + pos, buf->_buffer, buf->_length);
+ pos += buf->_length;
+ } else {
+ g_warning ("Buffer length %d", buf->_length);
+ goto io_error;
+ }
+ *length_read += buf->_length;
+
+ CORBA_free (buf);
+ }
+
+ return mem;
+
+ io_error:
+ return NULL;
+}
+