Commit dfea400b dfea400b082c5eff4f31c4fd0ac9e57756a04866 by Sergey Poznyakoff

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.
1 parent 9b4deb97
......@@ -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 *);
......
......@@ -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;
......
......@@ -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 *
......
......@@ -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;
......
......@@ -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;
}
......
......@@ -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
......
......@@ -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;
......
......@@ -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;
......
......@@ -166,25 +166,10 @@ _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;
mfs->offset = off;
......
......@@ -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;
......
......@@ -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;
......
......@@ -544,24 +544,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;
......
......@@ -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;
......
......@@ -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);
......
......@@ -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,
......