summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2010-05-02 14:20:32 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2010-05-02 14:20:32 +0300
commit14af0505bcf691efbeb8fb60ab5ea99b9836f061 (patch)
tree29a3fbecdf4149b896c4606a5ed53c0d900a44b7
parent7262235cbe6dc9426ad6e37c5fe0f4b023b324a9 (diff)
downloadmailutils-14af0505bcf691efbeb8fb60ab5ea99b9836f061.tar.gz
mailutils-14af0505bcf691efbeb8fb60ab5ea99b9836f061.tar.bz2
Simplify stream->seek.
* include/mailutils/sys/stream.h (_mu_stream) <seek>: Remove the `whence' parameter. * mailbox/stream.c (mu_stream_seek): Update the seek method call. * mailbox/streamref.c (_streamref_seek): Fix the signature. Remove unnecessary code. * mailbox/amd.c (amd_body_stream_seek): Likewise. * mailbox/body.c (_body_seek): Likewise. * mailbox/file_stream.c (fd_seek): Likewise. * mailbox/filter_iconv.c (_icvt_seek): Likewise. * mailbox/fltstream.c (filter_seek): Likewise. * mailbox/header.c (header_seek): Likewise. * mailbox/mapfile_stream.c (_mapfile_seek): Likewise. * mailbox/memory_stream.c (_memory_seek): Likewise. * mailbox/message.c (_message_stream_seek): Likewise. * mailbox/message_stream.c (_message_stream_seek): Likewise. * mailbox/mime.c (_mime_body_seek): Likewise. * mailbox/stdio_stream.c (stdio_seek): Likewise.
-rw-r--r--include/mailutils/sys/stream.h2
-rw-r--r--mailbox/amd.c19
-rw-r--r--mailbox/body.c6
-rw-r--r--mailbox/file_stream.c4
-rw-r--r--mailbox/filter_iconv.c7
-rw-r--r--mailbox/fltstream.c6
-rw-r--r--mailbox/header.c16
-rw-r--r--mailbox/mapfile_stream.c17
-rw-r--r--mailbox/memory_stream.c17
-rw-r--r--mailbox/message.c22
-rw-r--r--mailbox/message_stream.c17
-rw-r--r--mailbox/mime.c15
-rw-r--r--mailbox/stdio_stream.c16
-rw-r--r--mailbox/stream.c2
-rw-r--r--mailbox/streamref.c22
15 files changed, 24 insertions, 164 deletions
diff --git a/include/mailutils/sys/stream.h b/include/mailutils/sys/stream.h
index e63d60d42..90de02f05 100644
--- a/include/mailutils/sys/stream.h
+++ b/include/mailutils/sys/stream.h
@@ -47,7 +47,7 @@ struct _mu_stream
int (*open) (struct _mu_stream *);
int (*close) (struct _mu_stream *);
void (*done) (struct _mu_stream *);
- int (*seek) (struct _mu_stream *, mu_off_t, int, mu_off_t *);
+ int (*seek) (struct _mu_stream *, mu_off_t, mu_off_t *);
int (*size) (struct _mu_stream *, mu_off_t *);
int (*ctl) (struct _mu_stream *, int, void *);
int (*wait) (struct _mu_stream *, int *, struct timeval *);
diff --git a/mailbox/amd.c b/mailbox/amd.c
index d5ff6d5ca..450c7c02a 100644
--- a/mailbox/amd.c
+++ b/mailbox/amd.c
@@ -122,7 +122,7 @@ static int amd_body_stream_readdelim (mu_stream_t is,
int delim,
size_t *pnread);
static int amd_body_stream_size (mu_stream_t str, mu_off_t *psize);
-static int amd_body_stream_seek (mu_stream_t str, mu_off_t off, int whence,
+static int amd_body_stream_seek (mu_stream_t str, mu_off_t off,
mu_off_t *presult);
struct _amd_body_stream
@@ -1703,27 +1703,12 @@ amd_body_stream_readdelim (mu_stream_t is, char *buffer, size_t buflen,
}
static int
-amd_body_stream_seek (mu_stream_t str, mu_off_t off, int whence,
- mu_off_t *presult)
+amd_body_stream_seek (mu_stream_t str, mu_off_t off, mu_off_t *presult)
{
size_t size;
struct _amd_body_stream *amdstr = (struct _amd_body_stream *)str;
- mu_message_t msg = mu_body_get_owner (amdstr->body);
amd_body_size (amdstr->body, &size);
- switch (whence)
- {
- case MU_SEEK_SET:
- break;
-
- case MU_SEEK_CUR:
- off += amdstr->off;
- break;
-
- case MU_SEEK_END:
- off += size;
- break;
- }
if (off < 0 || off >= size)
return ESPIPE;
diff --git a/mailbox/body.c b/mailbox/body.c
index 01f14f0b2..8c5dba1f8 100644
--- a/mailbox/body.c
+++ b/mailbox/body.c
@@ -44,7 +44,7 @@ static int _body_truncate (mu_stream_t, mu_off_t);
static int _body_size (mu_stream_t, mu_off_t *);
static int _body_write (mu_stream_t, const char *, size_t, size_t *);
static int _body_ioctl (mu_stream_t, int, void *);
-static int _body_seek (mu_stream_t, mu_off_t, int, mu_off_t *);
+static int _body_seek (mu_stream_t, mu_off_t, mu_off_t *);
static const char *_body_error_string (mu_stream_t, int);
/* Our own defaults for the body. */
@@ -281,11 +281,11 @@ mu_body_set_size (mu_body_t body, int (*_size)(mu_body_t, size_t*) , void *owner
/* Stub function for the body stream. */
static int
-_body_seek (mu_stream_t stream, mu_off_t off, int whence, mu_off_t *presult)
+_body_seek (mu_stream_t stream, mu_off_t off, mu_off_t *presult)
{
struct _mu_body_stream *str = (struct _mu_body_stream*) stream;
mu_body_t body = str->body;
- return mu_stream_seek (body->fstream, off, whence, presult);
+ return mu_stream_seek (body->fstream, off, MU_SEEK_SET, presult);
}
static const char *
diff --git a/mailbox/file_stream.c b/mailbox/file_stream.c
index abf63acf6..c97075f5f 100644
--- a/mailbox/file_stream.c
+++ b/mailbox/file_stream.c
@@ -148,10 +148,10 @@ fd_open (struct _mu_stream *str)
}
int
-fd_seek (struct _mu_stream *str, mu_off_t off, int whence, mu_off_t *presult)
+fd_seek (struct _mu_stream *str, mu_off_t off, mu_off_t *presult)
{
struct _mu_file_stream *fstr = (struct _mu_file_stream *) str;
- off = lseek (fstr->fd, off, whence);
+ off = lseek (fstr->fd, off, SEEK_SET);
if (off < 0)
return errno;
*presult = off;
diff --git a/mailbox/filter_iconv.c b/mailbox/filter_iconv.c
index 802c35df7..8d3428552 100644
--- a/mailbox/filter_iconv.c
+++ b/mailbox/filter_iconv.c
@@ -415,11 +415,12 @@ _icvt_wait (mu_stream_t stream, int *pflags, struct timeval *tvp)
return mu_stream_wait (s->transport, pflags, tvp);
}
+/* FIXME: Seeks in the *transport* stream. */
int
-_icvt_seek (mu_stream_t stream, mu_off_t off, int whence, mu_off_t *presult)
+_icvt_seek (mu_stream_t stream, mu_off_t off, mu_off_t *presult)
{
struct icvt_stream *s = (struct icvt_stream *)stream;
- return mu_stream_seek (s->transport, off, whence, presult);
+ return mu_stream_seek (s->transport, off, MU_SEEK_SET, presult);
}
int
@@ -462,6 +463,6 @@ mu_filter_iconv_create (mu_stream_t *s, mu_stream_t transport,
iptr->stream.ctl = _icvt_ioctl;
iptr->stream.wait = _icvt_wait;
iptr->stream.seek = _icvt_seek;
- *s = iptr;
+ *s = (mu_stream_t)iptr;
return 0;
}
diff --git a/mailbox/fltstream.c b/mailbox/fltstream.c
index 858928b06..5b1bb1376 100644
--- a/mailbox/fltstream.c
+++ b/mailbox/fltstream.c
@@ -313,12 +313,12 @@ filter_wr_flush (mu_stream_t stream)
return rc;
}
+/* FIXME: Seeks in the *transport* stream */
static int
-filter_seek (struct _mu_stream *stream, mu_off_t off, int whence,
- mu_off_t *ppos)
+filter_seek (struct _mu_stream *stream, mu_off_t off, mu_off_t *ppos)
{
struct _mu_filter_stream *fs = (struct _mu_filter_stream *)stream;
- return mu_stream_seek (fs->transport, off, whence, ppos);
+ return mu_stream_seek (fs->transport, off, MU_SEEK_SET, ppos);
}
static int
diff --git a/mailbox/header.c b/mailbox/header.c
index 4ad57ecd3..9c8fb9f94 100644
--- a/mailbox/header.c
+++ b/mailbox/header.c
@@ -931,24 +931,10 @@ mu_hdrent_unroll_fixup (mu_header_t hdr, struct mu_hdrent *ent)
}
int
-header_seek (mu_stream_t str, mu_off_t off, int whence, mu_off_t *presult)
+header_seek (mu_stream_t str, mu_off_t off, mu_off_t *presult)
{
struct _mu_header_stream *hstr = (struct _mu_header_stream *) str;
- switch (whence)
- {
- case MU_SEEK_SET:
- break;
-
- case MU_SEEK_CUR:
- off += hstr->off;
- break;
-
- case MU_SEEK_END:
- off += hstr->hdr->size;
- break;
- }
-
if (off < 0 || off > hstr->hdr->size)
return ESPIPE;
hstr->off = off;
diff --git a/mailbox/mapfile_stream.c b/mailbox/mapfile_stream.c
index a54c65cbb..94d3f524e 100644
--- a/mailbox/mapfile_stream.c
+++ b/mailbox/mapfile_stream.c
@@ -312,25 +312,10 @@ _mapfile_open (mu_stream_t stream)
}
static int
-_mapfile_seek (struct _mu_stream *str, mu_off_t off, int whence, mu_off_t *presult)
+_mapfile_seek (struct _mu_stream *str, mu_off_t off, mu_off_t *presult)
{
struct _mu_mapfile_stream *mfs = (struct _mu_mapfile_stream *) str;
- /* FIXME */
- switch (whence)
- {
- case MU_SEEK_SET:
- break;
-
- case MU_SEEK_CUR:
- off += mfs->offset;
- break;
-
- case MU_SEEK_END:
- off += mfs->size;
- break;
- }
-
if (off < 0 || off >= mfs->size)
return ESPIPE;
mfs->offset = off;
diff --git a/mailbox/memory_stream.c b/mailbox/memory_stream.c
index 8e93e7b6c..ecb091fa9 100644
--- a/mailbox/memory_stream.c
+++ b/mailbox/memory_stream.c
@@ -166,24 +166,9 @@ _memory_ioctl (struct _mu_stream *stream, int code, void *ptr)
}
static int
-_memory_seek (struct _mu_stream *stream, mu_off_t off, int whence,
- mu_off_t *presult)
+_memory_seek (struct _mu_stream *stream, mu_off_t off, mu_off_t *presult)
{
struct _mu_memory_stream *mfs = (struct _mu_memory_stream *) stream;
-
- switch (whence)
- {
- case MU_SEEK_SET:
- break;
-
- case MU_SEEK_CUR:
- off += mfs->offset;
- break;
-
- case MU_SEEK_END:
- off += mfs->size;
- break;
- }
if (off < 0)
return ESPIPE;
diff --git a/mailbox/message.c b/mailbox/message.c
index 4f93fa32c..8111b4872 100644
--- a/mailbox/message.c
+++ b/mailbox/message.c
@@ -149,8 +149,7 @@ _message_stream_size (struct _mu_stream *str, mu_off_t *psize)
}
static int
-_message_stream_seek (struct _mu_stream *str, mu_off_t off, int whence,
- mu_off_t *ppos)
+_message_stream_seek (struct _mu_stream *str, mu_off_t off, mu_off_t *ppos)
{
struct _mu_message_stream *sp = (struct _mu_message_stream *)str;
size_t hsize, size;
@@ -163,25 +162,6 @@ _message_stream_seek (struct _mu_stream *str, mu_off_t off, int whence,
mu_body_size (sp->msg->body, &size);
size += hsize;
- switch (whence)
- {
- case MU_SEEK_SET:
- break;
-
- case MU_SEEK_CUR:
- {
- mu_off_t cur;
- rc = mu_stream_seek (sp->transport, 0, MU_SEEK_CUR, &cur);
- if (rc)
- return rc;
- off += cur;
- }
- break;
-
- case MU_SEEK_END:
- off += size;
- break;
- }
if (off < 0 || off >= size)
return ESPIPE;
diff --git a/mailbox/message_stream.c b/mailbox/message_stream.c
index 6b3cb7db9..cfcd2ddbe 100644
--- a/mailbox/message_stream.c
+++ b/mailbox/message_stream.c
@@ -303,27 +303,12 @@ _message_done (mu_stream_t stream)
}
static int
-_message_seek (struct _mu_stream *stream, mu_off_t off, int whence,
- mu_off_t *presult)
+_message_seek (struct _mu_stream *stream, mu_off_t off, mu_off_t *presult)
{
struct _mu_message_stream *s = (struct _mu_message_stream*) stream;
mu_off_t size;
mu_stream_size (stream, &size);
- switch (whence)
- {
- case MU_SEEK_SET:
- break;
-
- case MU_SEEK_CUR:
- off += s->offset;
- break;
-
- case MU_SEEK_END:
- off += size;
- break;
- }
-
if (off < 0 || off >= size)
return ESPIPE;
s->offset = off;
diff --git a/mailbox/mime.c b/mailbox/mime.c
index b5db70c6e..f6f6d75e0 100644
--- a/mailbox/mime.c
+++ b/mailbox/mime.c
@@ -537,24 +537,11 @@ struct _mime_body_stream
/* FIXME: The seek method is defective */
static int
-_mime_body_seek (mu_stream_t stream, mu_off_t off, int whence,
- mu_off_t *presult)
+_mime_body_seek (mu_stream_t stream, mu_off_t off, mu_off_t *presult)
{
struct _mime_body_stream *mstr = (struct _mime_body_stream *)stream;
mu_mime_t mime = mstr->mime;
- switch (whence)
- {
- case MU_SEEK_SET:
- break;
-
- case MU_SEEK_CUR:
- off += mime->cur_offset;
-
- case MU_SEEK_END:
- return ESPIPE;
- }
-
if (off == 0)
{ /* reset message */
mime->cur_offset = 0;
diff --git a/mailbox/stdio_stream.c b/mailbox/stdio_stream.c
index dac196cd6..ae77d1207 100644
--- a/mailbox/stdio_stream.c
+++ b/mailbox/stdio_stream.c
@@ -128,23 +128,9 @@ stdio_size (struct _mu_stream *str, off_t *psize)
}
static int
-stdio_seek (struct _mu_stream *str, mu_off_t off, int whence, mu_off_t *presult)
+stdio_seek (struct _mu_stream *str, mu_off_t off, mu_off_t *presult)
{
struct _mu_stdio_stream *fs = (struct _mu_stdio_stream *) str;
- /* FIXME */
- switch (whence)
- {
- case MU_SEEK_SET:
- break;
-
- case MU_SEEK_CUR:
- off += fs->offset;
- break;
-
- case MU_SEEK_END:
- off += fs->size;
- break;
- }
if (off < 0)
return ESPIPE;
diff --git a/mailbox/stream.c b/mailbox/stream.c
index 4e74caf02..2cb5ff12e 100644
--- a/mailbox/stream.c
+++ b/mailbox/stream.c
@@ -323,7 +323,7 @@ mu_stream_seek (mu_stream_t stream, mu_off_t offset, int whence,
{
if ((rc = _stream_flush_buffer (stream, 1)))
return rc;
- rc = stream->seek (stream, offset, MU_SEEK_SET, &stream->offset);
+ rc = stream->seek (stream, offset, &stream->offset);
if (rc)
return _stream_seterror (stream, rc, 1);
_stream_cleareof (stream);
diff --git a/mailbox/streamref.c b/mailbox/streamref.c
index de5fec8f9..a2f022a99 100644
--- a/mailbox/streamref.c
+++ b/mailbox/streamref.c
@@ -153,8 +153,7 @@ _streamref_done (struct _mu_stream *str)
}
static int
-_streamref_seek (struct _mu_stream *str, mu_off_t off, int whence,
- mu_off_t *ppos)
+_streamref_seek (struct _mu_stream *str, mu_off_t off, mu_off_t *ppos)
{
struct _mu_streamref *sp = (struct _mu_streamref *)str;
mu_off_t cur = sp->offset - sp->start;
@@ -171,25 +170,6 @@ _streamref_seek (struct _mu_stream *str, mu_off_t off, int whence,
size -= sp->start;
}
- switch (whence)
- {
- case MU_SEEK_SET:
- break;
-
- case MU_SEEK_CUR:
- if (off == 0)
- {
- *ppos = sp->offset - sp->start;
- return 0;
- }
- off += cur;
- break;
-
- case MU_SEEK_END:
- off += size;
- break;
- }
-
if (off < 0 || off >= size)
return sp->stream.last_err = ESPIPE;
rc = mu_stream_seek (sp->transport, sp->start + off, MU_SEEK_SET,

Return to:

Send suggestions and report system problems to the System administrator.