diff options
author | Jeffrey Stedfast <fejj@helixcode.com> | 2000-06-07 06:55:06 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2000-06-07 06:55:06 +0800 |
commit | 4b82b86ee5df1cfcbcbc46cc421804a6a0cb8da2 (patch) | |
tree | 122b4b705f90414589e8b0d07586ceb7a2489067 /camel | |
parent | af805a2733c9e2ca44e27360c6162d60cfc1aa53 (diff) | |
download | gsoc2013-evolution-4b82b86ee5df1cfcbcbc46cc421804a6a0cb8da2.tar gsoc2013-evolution-4b82b86ee5df1cfcbcbc46cc421804a6a0cb8da2.tar.gz gsoc2013-evolution-4b82b86ee5df1cfcbcbc46cc421804a6a0cb8da2.tar.bz2 gsoc2013-evolution-4b82b86ee5df1cfcbcbc46cc421804a6a0cb8da2.tar.lz gsoc2013-evolution-4b82b86ee5df1cfcbcbc46cc421804a6a0cb8da2.tar.xz gsoc2013-evolution-4b82b86ee5df1cfcbcbc46cc421804a6a0cb8da2.tar.zst gsoc2013-evolution-4b82b86ee5df1cfcbcbc46cc421804a6a0cb8da2.zip |
Changed the read and write method prototypes to return an ssize_t type
2000-06-06 Jeffrey Stedfast <fejj@helixcode.com>
* camel-stream.[c,h]: Changed the read and write method prototypes
to return an ssize_t type rather than an int and also changed
the 'number of bytes' to read or write to a size_t type
* camel-stream-fs.c: same as above
* camel-stream-mem.c: again, same as above
* camel-stream-buffer.c: same
* camel-imap-stream.[c,h]: Added this new stream, cache's previously
read data so each successive call will instead read from the cache
svn path=/trunk/; revision=3450
Diffstat (limited to 'camel')
-rw-r--r-- | camel/ChangeLog | 13 | ||||
-rw-r--r-- | camel/camel-imap-stream.c | 208 | ||||
-rw-r--r-- | camel/camel-imap-stream.h | 70 | ||||
-rw-r--r-- | camel/camel-stream-buffer.c | 38 | ||||
-rw-r--r-- | camel/camel-stream-filter.c | 28 | ||||
-rw-r--r-- | camel/camel-stream-fs.c | 16 | ||||
-rw-r--r-- | camel/camel-stream-mem.c | 46 | ||||
-rw-r--r-- | camel/camel-stream.h | 17 |
8 files changed, 372 insertions, 64 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog index 5c6e410388..d55f24814c 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -5,6 +5,19 @@ so it still won't build until camel-imap-summary is finished along with a few methods in camel-imap-folder) + * camel-stream.[c,h]: Changed the read and write method prototypes + to return an ssize_t type rather than an int and also changed + the 'number of bytes' to read or write to a size_t type + + * camel-stream-fs.c: same as above + + * camel-stream-mem.c: again, same as above + + * camel-stream-buffer.c: same + + * camel-imap-stream.[c,h]: Added this new stream, cache's previously read + data so each successive call will instead read from the cache + 2000-06-05 Dan Winship <danw@helixcode.com> * camel-mime-part.c (camel_mime_part_set_disposition): fix diff --git a/camel/camel-imap-stream.c b/camel/camel-imap-stream.c new file mode 100644 index 0000000000..24198bfd49 --- /dev/null +++ b/camel/camel-imap-stream.c @@ -0,0 +1,208 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Authors: Jeffrey Stedfast <fejj@helixcode.com> + * + * Copyright 2000 Helix Code, Inc. (www.helixcode.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA. + * + */ + + +#include <config.h> +#include "camel-imap-stream.h" +#include <sys/types.h> +#include <errno.h> + +static CamelStreamClass *parent_class = NULL; + +/* Returns the class for a CamelImapStream */ +#define CIS_CLASS(so) CAMEL_IMAP_STREAM_CLASS (GTK_OBJECT(so)->klass) + +static ssize_t stream_read (CamelStream *stream, char *buffer, size_t n); +static int stream_reset (CamelStream *stream); +static gboolean stream_eos (CamelStream *stream); + +static void finalize (GtkObject *object); + +static void +camel_imap_stream_class_init (CamelImapStreamClass *camel_imap_stream_class) +{ + CamelStreamClass *camel_stream_class = + CAMEL_STREAM_CLASS (camel_imap_stream_class); + GtkObjectClass *gtk_object_class = + GTK_OBJECT_CLASS (camel_imap_stream_class); + + parent_class = gtk_type_class (camel_stream_get_type ()); + + /* virtual method overload */ + camel_stream_class->read = stream_read; + /*camel_stream_class->write = stream_write;*/ + camel_stream_class->reset = stream_reset; + camel_stream_class->eos = stream_eos; + + gtk_object_class->finalize = finalize; +} + +static void +camel_imap_stream_init (gpointer object, gpointer klass) +{ + CamelImapStream *imap_stream = CAMEL_IMAP_STREAM (object); + + imap_stream->cache = NULL; + imap_stream->cache_ptr = NULL; +} + +GtkType +camel_imap_stream_get_type (void) +{ + static GtkType camel_imap_stream_type = 0; + + if (!camel_imap_stream_type) { + GtkTypeInfo camel_imap_stream_info = + { + "CamelImapStream", + sizeof (CamelImapStream), + sizeof (CamelImapStreamClass), + (GtkClassInitFunc) camel_imap_stream_class_init, + (GtkObjectInitFunc) camel_imap_stream_init, + /* reserved_1 */ NULL, + /* reserved_2 */ NULL, + (GtkClassInitFunc) NULL, + }; + + camel_imap_stream_type = gtk_type_unique (camel_stream_get_type (), &camel_imap_stream_info); + } + + return camel_imap_stream_type; +} + +CamelStream * +camel_imap_stream_new (CamelImapFolder *folder, char *command) +{ + CamelImapStream *imap_stream; + + imap_stream = gtk_type_new (camel_imap_stream_get_type ()); + + imap_stream->folder = folder; + gtk_object_ref(GTK_OBJECT (imap_stream->folder)); + + imap_stream->command = g_strdup(command); + + return CAMEL_STREAM (imap_stream); +} + +static void +finalize (GtkObject *object) +{ + CamelImapStream *imap_stream = CAMEL_IMAP_STREAM (object); + + g_free(imap_stream->cache); + g_free(imap_stream->command); + + if (imap_stream->folder) + gtk_object_unref(imap_stream->folder); + + GTK_OBJECT_CLASS (parent_class)->finalize (object); +} + +static ssize_t +stream_read (CamelStream *stream, char *buffer, size_t n) +{ + ssize_t nread; + + /* do we want to do any IMAP specific parsing in here? If not, maybe rename to camel-stream-cache? */ + CamelImapStream *imap_stream = CAMEL_IMAP_STREAM (stream); + + if (!imap_stream->cache) { + /* We need to send the IMAP command since this is our first fetch */ + CamelImapStore *store = CAMEL_IMAP_STORE (imap_stream->folder->parent_store); + gint status; + + status = camel_imap_command_extended(store->ostream, imap_stream->cache, "%s", + imap_stream->command); + + if (status != CAMEL_IMAP_OK) { + /* we got an error, dump this stuff */ + g_free(imap_stream->cache); + imap_stream->cache = NULL; + + return -1; + } + + /* we don't need the folder anymore... */ + gtk_object_unref(GTK_OBJECT (imap_stream->folder)); + + imap_stream->cache_ptr = imap_stream->cache; + } + + /* we've already read this stream, so return whats in the cache */ + nread = MIN (n, strlen(imap_stream->cache_ptr)); + + if (nread > 0) { + memcpy(buffer, imap_stream->cache_ptr, nread); + imap_stream->cache_ptr += nread; + } else { + nread = -1; + } + + return nread; +} + +static int +stream_write (CamelStream *stream, const char *buffer, unsigned int n) +{ + /* I don't think we need/want this functionality */ + CamelImapStream *imap_stream = CAMEL_IMAP_STREAM (stream); + + if (!imap_stream->cache) { + imap_stream->cache = g_malloc0(n + 1); + memcpy(imap_stream->cache, buffer, n); + } else { + imap_stream->cache = g_realloc(strlen(imap_stream->cache) + n + 1); + memcpy(imap_stream->cache[strlen(imap_stream->cache)], buffer, n); + } + + return n; +} + +static int +stream_reset (CamelStream *stream) +{ + CamelImapStream *imap_stream = CAMEL_IMAP_STREAM (stream); + + imap_stream->cache_ptr = imap_stream->cache; + + return 1; +} + +static gboolean +stream_eos (CamelStream *stream) +{ + CamelImapStream *imap_stream = CAMEL_IMAP_STREAM (stream); + + return (imap_stream->cache_ptr && strlen(imap_stream->cache_ptr)); +} + + + + + + + + + + + diff --git a/camel/camel-imap-stream.h b/camel/camel-imap-stream.h new file mode 100644 index 0000000000..01e7e59e18 --- /dev/null +++ b/camel/camel-imap-stream.h @@ -0,0 +1,70 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Authors: Jeffrey Stedfast <fejj@helixcode.com> + * + * Copyright 2000 Helix Code, Inc. (www.helixcode.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA. + * + */ + + + +#ifndef CAMEL_IMAP_STREAM_H +#define CAMEL_IMAP_STREAM_H + + +#ifdef __cplusplus +extern "C" { +#pragma } +#endif /* __cplusplus }*/ + +#include <camel/camel-stream.h> +#include <camel/providers/imap/camel-imap-folder.h> +#include <camel/providers/imap/camel-imap-store.h> +#include <sys/types.h> + +#define CAMEL_IMAP_STREAM_TYPE (camel_imap_stream_get_type ()) +#define CAMEL_IMAP_STREAM(obj) (GTK_CHECK_CAST((obj), CAMEL_IMAP_STREAM_TYPE, CamelImapStream)) +#define CAMEL_IMAP_STREAM_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), CAMEL_IMAP_STREAM_TYPE, CamelImapStreamClass)) +#define CAMEL_IS_IMAP_STREAM(o) (GTK_CHECK_TYPE((o), CAMEL_IMAP_STREAM_TYPE)) + +struct _CamelImapStream +{ + CamelStream parent_object; + + CamelImapFolder *folder; + char *command; + char *cache; + char *cache_ptr; +}; + +typedef struct { + CamelStreamClass parent_class; + + /* Virtual methods */ +} CamelImapStreamClass; + +/* Standard Gtk function */ +GtkType camel_imap_stream_get_type (void); + +/* public methods */ +CamelStream *camel_imap_stream_new (CamelImapFolder *folder, char *command); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* CAMEL_IMAP_STREAM_H */ diff --git a/camel/camel-stream-buffer.c b/camel/camel-stream-buffer.c index 68dcc7ad21..633e42095b 100644 --- a/camel/camel-stream-buffer.c +++ b/camel/camel-stream-buffer.c @@ -38,8 +38,8 @@ enum { #define BUF_SIZE 1024 -static int stream_read (CamelStream *stream, char *buffer, unsigned int n); -static int stream_write (CamelStream *stream, const char *buffer, unsigned int n); +static ssize_t stream_read (CamelStream *stream, char *buffer, size_t n); +static ssize_t stream_write (CamelStream *stream, const char *buffer, size_t n); static int stream_flush (CamelStream *stream); static int stream_close (CamelStream *stream); static gboolean stream_eos (CamelStream *stream); @@ -75,7 +75,7 @@ camel_stream_buffer_class_init (CamelStreamBufferClass *camel_stream_buffer_clas } static void -camel_stream_buffer_init (gpointer object, gpointer klass) +camel_stream_buffer_init (gpointer object, gpointer klass) { CamelStreamBuffer *sbf = CAMEL_STREAM_BUFFER (object); @@ -246,12 +246,12 @@ CamelStream *camel_stream_buffer_new_with_vbuf (CamelStream *stream, CamelStream return CAMEL_STREAM (sbf); } -static int -stream_read (CamelStream *stream, char *buffer, unsigned int n) +static ssize_t +stream_read (CamelStream *stream, char *buffer, size_t n) { CamelStreamBuffer *sbf = CAMEL_STREAM_BUFFER (stream); - int bytes_read = 1; - int bytes_left; + ssize_t bytes_read = 1; + ssize_t bytes_left; char *bptr = buffer; g_return_val_if_fail( (sbf->mode & CAMEL_STREAM_BUFFER_MODE) == CAMEL_STREAM_BUFFER_READ, 0); @@ -291,17 +291,17 @@ stream_read (CamelStream *stream, char *buffer, unsigned int n) } } - return bptr-buffer; + return (ssize_t)(bptr - buffer); } -static int -stream_write (CamelStream *stream, const char *buffer, unsigned int n) +static ssize_t +stream_write (CamelStream *stream, const char *buffer, size_t n) { CamelStreamBuffer *sbf = CAMEL_STREAM_BUFFER (stream); const char *bptr = buffer; - int bytes_written = 1; - int bytes_left; - int total = n; + ssize_t bytes_written = 1; + ssize_t bytes_left; + ssize_t total = n; g_return_val_if_fail( (sbf->mode & CAMEL_STREAM_BUFFER_MODE) == CAMEL_STREAM_BUFFER_WRITE, 0); @@ -336,6 +336,7 @@ stream_write (CamelStream *stream, const char *buffer, unsigned int n) } if (bytes_written == -1) return -1; + return total; } @@ -405,7 +406,7 @@ int camel_stream_buffer_gets(CamelStreamBuffer *sbf, char *buf, unsigned int max while (inptr<inend && outptr<outend) { c = *inptr++; *outptr++ = c; - if (c=='\n') { + if (c == '\n') { *outptr = 0; sbf->ptr = inptr; return outptr-buf; @@ -422,10 +423,10 @@ int camel_stream_buffer_gets(CamelStreamBuffer *sbf, char *buf, unsigned int max } while (bytes_read>0); sbf->ptr = inptr; - if (outptr<=outend) + if (outptr <= outend) *outptr = 0; - return outptr-buf; + return (int)(outptr - buf); } /** @@ -473,3 +474,8 @@ camel_stream_buffer_read_line (CamelStreamBuffer *sbf) return g_strdup(sbf->linebuf); } + + + + + diff --git a/camel/camel-stream-filter.c b/camel/camel-stream-filter.c index 3aaa1a20ed..547796c660 100644 --- a/camel/camel-stream-filter.c +++ b/camel/camel-stream-filter.c @@ -48,8 +48,8 @@ struct _CamelStreamFilterPrivate { static void camel_stream_filter_class_init (CamelStreamFilterClass *klass); static void camel_stream_filter_init (CamelStreamFilter *obj); -static int do_read (CamelStream *stream, char *buffer, unsigned int n); -static int do_write (CamelStream *stream, const char *buffer, unsigned int n); +static ssize_t do_read (CamelStream *stream, char *buffer, size_t n); +static ssize_t do_write (CamelStream *stream, const char *buffer, size_t n); static int do_flush (CamelStream *stream); static int do_close (CamelStream *stream); static gboolean do_eos (CamelStream *stream); @@ -215,12 +215,12 @@ camel_stream_filter_remove(CamelStreamFilter *filter, int id) } } -static int -do_read (CamelStream *stream, char *buffer, unsigned int n) +static ssize_t +do_read (CamelStream *stream, char *buffer, size_t n) { CamelStreamFilter *filter = (CamelStreamFilter *)stream; struct _CamelStreamFilterPrivate *p = _PRIVATE(filter); - int size; + ssize_t size; struct _filter *f; p->last_was_read = TRUE; @@ -229,26 +229,28 @@ do_read (CamelStream *stream, char *buffer, unsigned int n) int presize = READ_SIZE; size = camel_stream_read(filter->source, p->buffer, READ_SIZE); - if (size<=0) { + if (size <= 0) { /* this is somewhat untested */ if (camel_stream_eos(filter->source)) { f = p->filters; p->filtered = p->buffer; p->filteredlen = 0; while (f) { - camel_mime_filter_complete(f->filter, p->filtered, p->filteredlen, presize, &p->filtered, &p->filteredlen, &presize); + camel_mime_filter_complete(f->filter, p->filtered, p->filteredlen, + presize, &p->filtered, &p->filteredlen, &presize); f = f->next; } size = p->filteredlen; } - if (size<=0) + if (size <= 0) return size; } else { f = p->filters; p->filtered = p->buffer; p->filteredlen = size; while (f) { - camel_mime_filter_filter(f->filter, p->filtered, p->filteredlen, presize, &p->filtered, &p->filteredlen, &presize); + camel_mime_filter_filter(f->filter, p->filtered, p->filteredlen, presize, + &p->filtered, &p->filteredlen, &presize); f = f->next; } } @@ -262,8 +264,8 @@ do_read (CamelStream *stream, char *buffer, unsigned int n) return size; } -static int -do_write (CamelStream *stream, const char *buf, unsigned int n) +static ssize_t +do_write (CamelStream *stream, const char *buf, size_t n) { CamelStreamFilter *filter = (CamelStreamFilter *)stream; struct _CamelStreamFilterPrivate *p = _PRIVATE(filter); @@ -305,7 +307,7 @@ do_flush (CamelStream *stream) camel_mime_filter_complete(f->filter, buffer, len, presize, &buffer, &len, &presize); f = f->next; } - if (len>0 && camel_stream_write(filter->source, buffer, len) == -1) + if (len > 0 && camel_stream_write(filter->source, buffer, len) == -1) return -1; return camel_stream_flush(filter->source); } @@ -328,7 +330,7 @@ do_eos (CamelStream *stream) CamelStreamFilter *filter = (CamelStreamFilter *)stream; struct _CamelStreamFilterPrivate *p = _PRIVATE(filter); - if (p->filteredlen >0) + if (p->filteredlen > 0) return FALSE; return camel_stream_eos(filter->source); diff --git a/camel/camel-stream-fs.c b/camel/camel-stream-fs.c index 4b5a6015a4..b1a7dde41a 100644 --- a/camel/camel-stream-fs.c +++ b/camel/camel-stream-fs.c @@ -37,8 +37,8 @@ static CamelSeekableStreamClass *parent_class = NULL; /* Returns the class for a CamelStreamFS */ #define CSFS_CLASS(so) CAMEL_STREAM_FS_CLASS (GTK_OBJECT(so)->klass) -static int stream_read (CamelStream *stream, char *buffer, unsigned int n); -static int stream_write (CamelStream *stream, const char *buffer, unsigned int n); +static ssize_t stream_read (CamelStream *stream, char *buffer, size_t n); +static ssize_t stream_write (CamelStream *stream, const char *buffer, size_t n); static int stream_flush (CamelStream *stream); static int stream_close (CamelStream *stream); static off_t stream_seek (CamelSeekableStream *stream, off_t offset, @@ -211,12 +211,12 @@ camel_stream_fs_new_with_name_and_bounds (const char *name, int flags, } -static int -stream_read (CamelStream *stream, char *buffer, unsigned int n) +static ssize_t +stream_read (CamelStream *stream, char *buffer, size_t n) { CamelStreamFs *stream_fs = CAMEL_STREAM_FS (stream); CamelSeekableStream *seekable = CAMEL_SEEKABLE_STREAM (stream); - int nread; + ssize_t nread; if (seekable->bound_end != CAMEL_STREAM_UNBOUND) n = MIN (seekable->bound_end - seekable->position, n); @@ -233,12 +233,12 @@ stream_read (CamelStream *stream, char *buffer, unsigned int n) return nread; } -static int -stream_write (CamelStream *stream, const char *buffer, unsigned int n) +static ssize_t +stream_write (CamelStream *stream, const char *buffer, size_t n) { CamelStreamFs *stream_fs = CAMEL_STREAM_FS (stream); CamelSeekableStream *seekable = CAMEL_SEEKABLE_STREAM (stream); - int v, written = 0; + ssize_t v, written = 0; if (seekable->bound_end != CAMEL_STREAM_UNBOUND) n = MIN (seekable->bound_end - seekable->position, n); diff --git a/camel/camel-stream-mem.c b/camel/camel-stream-mem.c index ca384485b6..2d5c84a113 100644 --- a/camel/camel-stream-mem.c +++ b/camel/camel-stream-mem.c @@ -35,8 +35,8 @@ static CamelStreamClass *parent_class = NULL; /* Returns the class for a CamelStreamMem */ #define CSM_CLASS(so) CAMEL_STREAM_MEM_CLASS (GTK_OBJECT(so)->klass) -static int stream_read (CamelStream *stream, char *buffer, unsigned int n); -static int stream_write (CamelStream *stream, const char *buffer, unsigned int n); +static ssize_t stream_read (CamelStream *stream, char *buffer, size_t n); +static ssize_t stream_write (CamelStream *stream, const char *buffer, size_t n); static gboolean stream_eos (CamelStream *stream); static off_t stream_seek (CamelSeekableStream *stream, off_t offset, CamelStreamSeekPolicy policy); @@ -157,47 +157,49 @@ finalize (GtkObject *object) GTK_OBJECT_CLASS (parent_class)->finalize (object); } -static int -stream_read (CamelStream *stream, char *buffer, unsigned int n) +static ssize_t +stream_read (CamelStream *stream, char *buffer, size_t n) { CamelStreamMem *camel_stream_mem = CAMEL_STREAM_MEM (stream); CamelSeekableStream *seekable = CAMEL_SEEKABLE_STREAM (stream); + ssize_t nread; if (seekable->bound_end != CAMEL_STREAM_UNBOUND) n = MIN(seekable->bound_end - seekable->position, n); - n = MIN (n, camel_stream_mem->buffer->len - seekable->position); - if (n > 0) { + nread = MIN (n, camel_stream_mem->buffer->len - seekable->position); + if (nread > 0) { memcpy (buffer, camel_stream_mem->buffer->data + - seekable->position, n); - seekable->position += n; + seekable->position, nread); + seekable->position += nread; } else - n = -1; + nread = -1; - return n; + return nread; } -static int -stream_write (CamelStream *stream, const char *buffer, unsigned int n) +static ssize_t +stream_write (CamelStream *stream, const char *buffer, size_t n) { CamelStreamMem *stream_mem = CAMEL_STREAM_MEM (stream); CamelSeekableStream *seekable = CAMEL_SEEKABLE_STREAM (stream); - + ssize_t nwrite = n; + if (seekable->bound_end != CAMEL_STREAM_UNBOUND) - n = MIN(seekable->bound_end - seekable->position, n); + nwrite = MIN(seekable->bound_end - seekable->position, n); #warning "g_byte_arrays use g_malloc and so are totally unsuitable for this object" if (seekable->position == stream_mem->buffer->len) { stream_mem->buffer = - g_byte_array_append (stream_mem->buffer, (const guint8 *)buffer, n); + g_byte_array_append (stream_mem->buffer, (const guint8 *)buffer, nwrite); } else { g_byte_array_set_size (stream_mem->buffer, - n+stream_mem->buffer->len); - memcpy (stream_mem->buffer->data + seekable->position, buffer, n); + nwrite + stream_mem->buffer->len); + memcpy (stream_mem->buffer->data + seekable->position, buffer, nwrite); } - seekable->position += n; + seekable->position += nwrite; - return n; + return nwrite; } static gboolean @@ -226,6 +228,9 @@ stream_seek (CamelSeekableStream *stream, off_t offset, case CAMEL_STREAM_END: position = (stream_mem->buffer)->len + offset; break; + default: + position = offset; + break; } if (stream->bound_end == CAMEL_STREAM_UNBOUND) @@ -246,3 +251,6 @@ stream_seek (CamelSeekableStream *stream, off_t offset, return position; } + + + diff --git a/camel/camel-stream.h b/camel/camel-stream.h index 44562b3321..5660ca6e4c 100644 --- a/camel/camel-stream.h +++ b/camel/camel-stream.h @@ -35,6 +35,7 @@ extern "C" { #include <camel/camel-object.h> #include <stdarg.h> +#include <unistd.h> #define CAMEL_STREAM_TYPE (camel_stream_get_type ()) #define CAMEL_STREAM(obj) (GTK_CHECK_CAST((obj), CAMEL_STREAM_TYPE, CamelStream)) @@ -53,8 +54,8 @@ typedef struct { /* Virtual methods */ - int (*read) (CamelStream *stream, char *buffer, unsigned int n); - int (*write) (CamelStream *stream, const char *buffer, unsigned int n); + ssize_t (*read) (CamelStream *stream, char *buffer, size_t n); + ssize_t (*write) (CamelStream *stream, const char *buffer, size_t n); int (*close) (CamelStream *stream); int (*flush) (CamelStream *stream); gboolean (*eos) (CamelStream *stream); @@ -66,22 +67,22 @@ typedef struct { GtkType camel_stream_get_type (void); /* public methods */ -int camel_stream_read (CamelStream *stream, char *buffer, unsigned int n); -int camel_stream_write (CamelStream *stream, const char *buffer, unsigned int n); +ssize_t camel_stream_read (CamelStream *stream, char *buffer, size_t n); +ssize_t camel_stream_write (CamelStream *stream, const char *buffer, size_t n); int camel_stream_flush (CamelStream *stream); int camel_stream_close (CamelStream *stream); gboolean camel_stream_eos (CamelStream *stream); int camel_stream_reset (CamelStream *stream); /* utility macros and funcs */ -int camel_stream_write_string (CamelStream *stream, const char *string); -int camel_stream_printf (CamelStream *stream, const char *fmt, ... ) G_GNUC_PRINTF (2, 3); -int camel_stream_vprintf (CamelStream *stream, const char *fmt, va_list ap); +ssize_t camel_stream_write_string (CamelStream *stream, const char *string); +ssize_t camel_stream_printf (CamelStream *stream, const char *fmt, ... ) G_GNUC_PRINTF (2, 3); +ssize_t camel_stream_vprintf (CamelStream *stream, const char *fmt, va_list ap); /* Write a whole stream to another stream, until eof or error on * either stream. */ -int camel_stream_write_to_stream (CamelStream *stream, CamelStream *output_stream); +ssize_t camel_stream_write_to_stream (CamelStream *stream, CamelStream *output_stream); #ifdef __cplusplus } |