Mercurial > dovecot > original-hg > dovecot-1.2
changeset 534:45b43851bc9a HEAD
keep i_buffer_seek() void and make it close the buffer if any errors happen.
next read will then notice the error. easier to handle it that way.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 28 Oct 2002 06:33:00 +0200 |
parents | 1f1ff728ff65 |
children | 5a193db8fe56 |
files | src/lib-storage/index/index-fetch-section.c src/lib-storage/index/index-msgcache.c src/lib-storage/index/index-search.c src/lib/ibuffer-data.c src/lib/ibuffer-file.c src/lib/ibuffer-internal.h src/lib/ibuffer-mmap.c src/lib/ibuffer.c src/lib/ibuffer.h |
diffstat | 9 files changed, 28 insertions(+), 41 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/index/index-fetch-section.c Mon Oct 28 06:21:15 2002 +0200 +++ b/src/lib-storage/index/index-fetch-section.c Mon Oct 28 06:33:00 2002 +0200 @@ -307,8 +307,7 @@ uoff_t first_size = ctx.dest_size; ctx.outbuf = outbuf; - if (!i_buffer_seek(inbuf, start_offset)) - failed = TRUE; + i_buffer_seek(inbuf, start_offset); if (!failed && !fetch_header_fields(inbuf, section, &ctx))
--- a/src/lib-storage/index/index-msgcache.c Mon Oct 28 06:21:15 2002 +0200 +++ b/src/lib-storage/index/index-msgcache.c Mon Oct 28 06:33:00 2002 +0200 @@ -83,13 +83,7 @@ static IBuffer *index_msgcache_inbuf_rewind(IBuffer *inbuf, void *context __attr_unused__) { - if (!i_buffer_seek(inbuf, 0)) { - i_error("index_msgcache_inbuf_rewind: lseek() failed: %m"); - - i_buffer_unref(inbuf); - return NULL; - } - + i_buffer_seek(inbuf, 0); return inbuf; }
--- a/src/lib-storage/index/index-search.c Mon Oct 28 06:21:15 2002 +0200 +++ b/src/lib-storage/index/index-search.c Mon Oct 28 06:33:00 2002 +0200 @@ -637,11 +637,7 @@ if (have_text) { if (inbuf->v_offset != 0) { /* need to rewind back to beginning of headers */ - if (!i_buffer_seek(inbuf, 0)) { - errno = inbuf->buf_errno; - i_error("i_buffer_seek() failed: %m"); - return FALSE; - } + i_buffer_seek(inbuf, 0); } old_limit = inbuf->v_limit;
--- a/src/lib/ibuffer-data.c Mon Oct 28 06:21:15 2002 +0200 +++ b/src/lib/ibuffer-data.c Mon Oct 28 06:33:00 2002 +0200 @@ -51,11 +51,10 @@ return buf->pos - buf->skip; } -static int _seek(_IBuffer *buf, uoff_t v_offset) +static void _seek(_IBuffer *buf, uoff_t v_offset) { buf->skip = v_offset; buf->ibuffer.v_offset = v_offset; - return 1; } static void _skip(_IBuffer *buf, uoff_t count)
--- a/src/lib/ibuffer-file.c Mon Oct 28 06:21:15 2002 +0200 +++ b/src/lib/ibuffer-file.c Mon Oct 28 06:33:00 2002 +0200 @@ -232,31 +232,31 @@ buf->ibuffer.v_offset += count; } -static int _seek(_IBuffer *buf, uoff_t v_offset) +static void _seek(_IBuffer *buf, uoff_t v_offset) { uoff_t real_offset; off_t ret; real_offset = buf->ibuffer.start_offset + v_offset; if (real_offset > OFF_T_MAX) { - buf->ibuffer.buf_errno = EINVAL; - return -1; + buf->ibuffer.buf_errno = EOVERFLOW; + ret = -1; + } else { + ret = lseek(buf->fd, (off_t)real_offset, SEEK_SET); + if (ret < 0) + buf->ibuffer.buf_errno = errno; + else if (ret != (off_t)real_offset) { + buf->ibuffer.buf_errno = EINVAL; + ret = -1; + } } - ret = lseek(buf->fd, (off_t)real_offset, SEEK_SET); - if (ret < 0) { - buf->ibuffer.buf_errno = errno; - return -1; + if (ret < 0) + i_buffer_close(&buf->ibuffer); + else { + buf->ibuffer.buf_errno = 0; + buf->ibuffer.v_offset = v_offset; } - - if (ret != (off_t)real_offset) { - buf->ibuffer.buf_errno = EINVAL; - return -1; - } - - buf->ibuffer.buf_errno = 0; - buf->ibuffer.v_offset = v_offset; - return 1; } IBuffer *i_buffer_create_file(int fd, Pool pool, size_t max_buffer_size,
--- a/src/lib/ibuffer-internal.h Mon Oct 28 06:21:15 2002 +0200 +++ b/src/lib/ibuffer-internal.h Mon Oct 28 06:33:00 2002 +0200 @@ -13,7 +13,7 @@ /* methods: */ ssize_t (*read)(_IBuffer *buf); void (*skip_count)(_IBuffer *buf, uoff_t count); - int (*seek)(_IBuffer *buf, uoff_t v_offset); + void (*seek)(_IBuffer *buf, uoff_t v_offset); /* data: */ IBuffer ibuffer;
--- a/src/lib/ibuffer-mmap.c Mon Oct 28 06:21:15 2002 +0200 +++ b/src/lib/ibuffer-mmap.c Mon Oct 28 06:33:00 2002 +0200 @@ -172,7 +172,7 @@ return io_buffer_set_mmaped_pos(buf); } -static int _seek(_IBuffer *buf, uoff_t v_offset) +static void _seek(_IBuffer *buf, uoff_t v_offset) { MmapIBuffer *mbuf = (MmapIBuffer *) buf; uoff_t abs_offset; @@ -190,7 +190,6 @@ } buf->ibuffer.v_offset = v_offset; - return 1; } static void _skip(_IBuffer *buf, uoff_t count)
--- a/src/lib/ibuffer.c Mon Oct 28 06:21:15 2002 +0200 +++ b/src/lib/ibuffer.c Mon Oct 28 06:33:00 2002 +0200 @@ -135,16 +135,16 @@ _buf->skip_count(_buf, count); } -int i_buffer_seek(IBuffer *buf, uoff_t v_offset) +void i_buffer_seek(IBuffer *buf, uoff_t v_offset) { _IBuffer *_buf = buf->real_buffer; i_assert(v_offset <= buf->v_size); if (buf->closed) - return -1; + return; - return _buf->seek(_buf, v_offset); + _buf->seek(_buf, v_offset); } char *i_buffer_next_line(IBuffer *buf)
--- a/src/lib/ibuffer.h Mon Oct 28 06:21:15 2002 +0200 +++ b/src/lib/ibuffer.h Mon Oct 28 06:33:00 2002 +0200 @@ -52,9 +52,9 @@ /* Skip forward a number of bytes. Never fails, the next read tells if it was successful. */ void i_buffer_skip(IBuffer *buf, uoff_t count); -/* Seek to specified position from beginning of file. This works only for - files. Returns 1 if successful, -1 if error. */ -int i_buffer_seek(IBuffer *buf, uoff_t v_offset); +/* Seek to specified position from beginning of file. Never fails, the next + read tells if it was successful. This works only for files. */ +void i_buffer_seek(IBuffer *buf, uoff_t v_offset); /* Returns the next line from input buffer, or NULL if more data is needed to make a full line. NOTE: modifies the data in the buffer for the \0, so it works only with ibuffers that allow it (currently only file). */