[dovecot-cvs] dovecot/src/lib ibuffer-data.c,1.4,1.5 ibuffer-file.c,1.5,1.6 ibuffer-internal.h,1.3,1.4 ibuffer-mmap.c,1.8,1.9 ibuffer.c,1.7,1.8 ibuffer.h,1.3,1.4
cras at procontrol.fi
cras at procontrol.fi
Mon Oct 28 06:33:02 EET 2002
Update of /home/cvs/dovecot/src/lib
In directory danu:/tmp/cvs-serv7993/lib
Modified Files:
ibuffer-data.c ibuffer-file.c ibuffer-internal.h
ibuffer-mmap.c ibuffer.c ibuffer.h
Log Message:
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.
Index: ibuffer-data.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/ibuffer-data.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- ibuffer-data.c 28 Oct 2002 04:18:26 -0000 1.4
+++ ibuffer-data.c 28 Oct 2002 04:33:00 -0000 1.5
@@ -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)
Index: ibuffer-file.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/ibuffer-file.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- ibuffer-file.c 28 Oct 2002 04:21:15 -0000 1.5
+++ ibuffer-file.c 28 Oct 2002 04:33:00 -0000 1.6
@@ -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;
- }
-
- ret = lseek(buf->fd, (off_t)real_offset, SEEK_SET);
- if (ret < 0) {
- buf->ibuffer.buf_errno = errno;
- 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;
+ }
}
- if (ret != (off_t)real_offset) {
- buf->ibuffer.buf_errno = EINVAL;
- return -1;
+ if (ret < 0)
+ i_buffer_close(&buf->ibuffer);
+ else {
+ buf->ibuffer.buf_errno = 0;
+ buf->ibuffer.v_offset = v_offset;
}
-
- 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,
Index: ibuffer-internal.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib/ibuffer-internal.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- ibuffer-internal.h 24 Oct 2002 22:04:49 -0000 1.3
+++ ibuffer-internal.h 28 Oct 2002 04:33:00 -0000 1.4
@@ -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;
Index: ibuffer-mmap.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/ibuffer-mmap.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- ibuffer-mmap.c 28 Oct 2002 04:18:26 -0000 1.8
+++ ibuffer-mmap.c 28 Oct 2002 04:33:00 -0000 1.9
@@ -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)
Index: ibuffer.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/ibuffer.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- ibuffer.c 28 Oct 2002 04:18:26 -0000 1.7
+++ ibuffer.c 28 Oct 2002 04:33:00 -0000 1.8
@@ -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)
Index: ibuffer.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib/ibuffer.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- ibuffer.h 28 Oct 2002 04:18:26 -0000 1.3
+++ ibuffer.h 28 Oct 2002 04:33:00 -0000 1.4
@@ -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). */
More information about the dovecot-cvs
mailing list