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.
Showing
15 changed files
with
24 additions
and
164 deletions
... | @@ -47,7 +47,7 @@ struct _mu_stream | ... | @@ -47,7 +47,7 @@ struct _mu_stream |
47 | int (*open) (struct _mu_stream *); | 47 | int (*open) (struct _mu_stream *); |
48 | int (*close) (struct _mu_stream *); | 48 | int (*close) (struct _mu_stream *); |
49 | void (*done) (struct _mu_stream *); | 49 | void (*done) (struct _mu_stream *); |
50 | int (*seek) (struct _mu_stream *, mu_off_t, int, mu_off_t *); | 50 | int (*seek) (struct _mu_stream *, mu_off_t, mu_off_t *); |
51 | int (*size) (struct _mu_stream *, mu_off_t *); | 51 | int (*size) (struct _mu_stream *, mu_off_t *); |
52 | int (*ctl) (struct _mu_stream *, int, void *); | 52 | int (*ctl) (struct _mu_stream *, int, void *); |
53 | int (*wait) (struct _mu_stream *, int *, struct timeval *); | 53 | int (*wait) (struct _mu_stream *, int *, struct timeval *); | ... | ... |
... | @@ -122,7 +122,7 @@ static int amd_body_stream_readdelim (mu_stream_t is, | ... | @@ -122,7 +122,7 @@ static int amd_body_stream_readdelim (mu_stream_t is, |
122 | int delim, | 122 | int delim, |
123 | size_t *pnread); | 123 | size_t *pnread); |
124 | static int amd_body_stream_size (mu_stream_t str, mu_off_t *psize); | 124 | static int amd_body_stream_size (mu_stream_t str, mu_off_t *psize); |
125 | static int amd_body_stream_seek (mu_stream_t str, mu_off_t off, int whence, | 125 | static int amd_body_stream_seek (mu_stream_t str, mu_off_t off, |
126 | mu_off_t *presult); | 126 | mu_off_t *presult); |
127 | 127 | ||
128 | struct _amd_body_stream | 128 | struct _amd_body_stream |
... | @@ -1703,27 +1703,12 @@ amd_body_stream_readdelim (mu_stream_t is, char *buffer, size_t buflen, | ... | @@ -1703,27 +1703,12 @@ amd_body_stream_readdelim (mu_stream_t is, char *buffer, size_t buflen, |
1703 | } | 1703 | } |
1704 | 1704 | ||
1705 | static int | 1705 | static int |
1706 | amd_body_stream_seek (mu_stream_t str, mu_off_t off, int whence, | 1706 | amd_body_stream_seek (mu_stream_t str, mu_off_t off, mu_off_t *presult) |
1707 | mu_off_t *presult) | ||
1708 | { | 1707 | { |
1709 | size_t size; | 1708 | size_t size; |
1710 | struct _amd_body_stream *amdstr = (struct _amd_body_stream *)str; | 1709 | struct _amd_body_stream *amdstr = (struct _amd_body_stream *)str; |
1711 | mu_message_t msg = mu_body_get_owner (amdstr->body); | ||
1712 | 1710 | ||
1713 | amd_body_size (amdstr->body, &size); | 1711 | amd_body_size (amdstr->body, &size); |
1714 | switch (whence) | ||
1715 | { | ||
1716 | case MU_SEEK_SET: | ||
1717 | break; | ||
1718 | |||
1719 | case MU_SEEK_CUR: | ||
1720 | off += amdstr->off; | ||
1721 | break; | ||
1722 | |||
1723 | case MU_SEEK_END: | ||
1724 | off += size; | ||
1725 | break; | ||
1726 | } | ||
1727 | 1712 | ||
1728 | if (off < 0 || off >= size) | 1713 | if (off < 0 || off >= size) |
1729 | return ESPIPE; | 1714 | return ESPIPE; | ... | ... |
... | @@ -44,7 +44,7 @@ static int _body_truncate (mu_stream_t, mu_off_t); | ... | @@ -44,7 +44,7 @@ static int _body_truncate (mu_stream_t, mu_off_t); |
44 | static int _body_size (mu_stream_t, mu_off_t *); | 44 | static int _body_size (mu_stream_t, mu_off_t *); |
45 | static int _body_write (mu_stream_t, const char *, size_t, size_t *); | 45 | static int _body_write (mu_stream_t, const char *, size_t, size_t *); |
46 | static int _body_ioctl (mu_stream_t, int, void *); | 46 | static int _body_ioctl (mu_stream_t, int, void *); |
47 | static int _body_seek (mu_stream_t, mu_off_t, int, mu_off_t *); | 47 | static int _body_seek (mu_stream_t, mu_off_t, mu_off_t *); |
48 | static const char *_body_error_string (mu_stream_t, int); | 48 | static const char *_body_error_string (mu_stream_t, int); |
49 | 49 | ||
50 | /* Our own defaults for the body. */ | 50 | /* 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 | ... | @@ -281,11 +281,11 @@ mu_body_set_size (mu_body_t body, int (*_size)(mu_body_t, size_t*) , void *owner |
281 | /* Stub function for the body stream. */ | 281 | /* Stub function for the body stream. */ |
282 | 282 | ||
283 | static int | 283 | static int |
284 | _body_seek (mu_stream_t stream, mu_off_t off, int whence, mu_off_t *presult) | 284 | _body_seek (mu_stream_t stream, mu_off_t off, mu_off_t *presult) |
285 | { | 285 | { |
286 | struct _mu_body_stream *str = (struct _mu_body_stream*) stream; | 286 | struct _mu_body_stream *str = (struct _mu_body_stream*) stream; |
287 | mu_body_t body = str->body; | 287 | mu_body_t body = str->body; |
288 | return mu_stream_seek (body->fstream, off, whence, presult); | 288 | return mu_stream_seek (body->fstream, off, MU_SEEK_SET, presult); |
289 | } | 289 | } |
290 | 290 | ||
291 | static const char * | 291 | static const char * | ... | ... |
... | @@ -148,10 +148,10 @@ fd_open (struct _mu_stream *str) | ... | @@ -148,10 +148,10 @@ fd_open (struct _mu_stream *str) |
148 | } | 148 | } |
149 | 149 | ||
150 | int | 150 | int |
151 | fd_seek (struct _mu_stream *str, mu_off_t off, int whence, mu_off_t *presult) | 151 | fd_seek (struct _mu_stream *str, mu_off_t off, mu_off_t *presult) |
152 | { | 152 | { |
153 | struct _mu_file_stream *fstr = (struct _mu_file_stream *) str; | 153 | struct _mu_file_stream *fstr = (struct _mu_file_stream *) str; |
154 | off = lseek (fstr->fd, off, whence); | 154 | off = lseek (fstr->fd, off, SEEK_SET); |
155 | if (off < 0) | 155 | if (off < 0) |
156 | return errno; | 156 | return errno; |
157 | *presult = off; | 157 | *presult = off; | ... | ... |
... | @@ -415,11 +415,12 @@ _icvt_wait (mu_stream_t stream, int *pflags, struct timeval *tvp) | ... | @@ -415,11 +415,12 @@ _icvt_wait (mu_stream_t stream, int *pflags, struct timeval *tvp) |
415 | return mu_stream_wait (s->transport, pflags, tvp); | 415 | return mu_stream_wait (s->transport, pflags, tvp); |
416 | } | 416 | } |
417 | 417 | ||
418 | /* FIXME: Seeks in the *transport* stream. */ | ||
418 | int | 419 | int |
419 | _icvt_seek (mu_stream_t stream, mu_off_t off, int whence, mu_off_t *presult) | 420 | _icvt_seek (mu_stream_t stream, mu_off_t off, mu_off_t *presult) |
420 | { | 421 | { |
421 | struct icvt_stream *s = (struct icvt_stream *)stream; | 422 | struct icvt_stream *s = (struct icvt_stream *)stream; |
422 | return mu_stream_seek (s->transport, off, whence, presult); | 423 | return mu_stream_seek (s->transport, off, MU_SEEK_SET, presult); |
423 | } | 424 | } |
424 | 425 | ||
425 | int | 426 | int |
... | @@ -462,6 +463,6 @@ mu_filter_iconv_create (mu_stream_t *s, mu_stream_t transport, | ... | @@ -462,6 +463,6 @@ mu_filter_iconv_create (mu_stream_t *s, mu_stream_t transport, |
462 | iptr->stream.ctl = _icvt_ioctl; | 463 | iptr->stream.ctl = _icvt_ioctl; |
463 | iptr->stream.wait = _icvt_wait; | 464 | iptr->stream.wait = _icvt_wait; |
464 | iptr->stream.seek = _icvt_seek; | 465 | iptr->stream.seek = _icvt_seek; |
465 | *s = iptr; | 466 | *s = (mu_stream_t)iptr; |
466 | return 0; | 467 | return 0; |
467 | } | 468 | } | ... | ... |
... | @@ -313,12 +313,12 @@ filter_wr_flush (mu_stream_t stream) | ... | @@ -313,12 +313,12 @@ filter_wr_flush (mu_stream_t stream) |
313 | return rc; | 313 | return rc; |
314 | } | 314 | } |
315 | 315 | ||
316 | /* FIXME: Seeks in the *transport* stream */ | ||
316 | static int | 317 | static int |
317 | filter_seek (struct _mu_stream *stream, mu_off_t off, int whence, | 318 | filter_seek (struct _mu_stream *stream, mu_off_t off, mu_off_t *ppos) |
318 | mu_off_t *ppos) | ||
319 | { | 319 | { |
320 | struct _mu_filter_stream *fs = (struct _mu_filter_stream *)stream; | 320 | struct _mu_filter_stream *fs = (struct _mu_filter_stream *)stream; |
321 | return mu_stream_seek (fs->transport, off, whence, ppos); | 321 | return mu_stream_seek (fs->transport, off, MU_SEEK_SET, ppos); |
322 | } | 322 | } |
323 | 323 | ||
324 | static int | 324 | static int | ... | ... |
... | @@ -931,24 +931,10 @@ mu_hdrent_unroll_fixup (mu_header_t hdr, struct mu_hdrent *ent) | ... | @@ -931,24 +931,10 @@ mu_hdrent_unroll_fixup (mu_header_t hdr, struct mu_hdrent *ent) |
931 | } | 931 | } |
932 | 932 | ||
933 | int | 933 | int |
934 | header_seek (mu_stream_t str, mu_off_t off, int whence, mu_off_t *presult) | 934 | header_seek (mu_stream_t str, mu_off_t off, mu_off_t *presult) |
935 | { | 935 | { |
936 | struct _mu_header_stream *hstr = (struct _mu_header_stream *) str; | 936 | struct _mu_header_stream *hstr = (struct _mu_header_stream *) str; |
937 | 937 | ||
938 | switch (whence) | ||
939 | { | ||
940 | case MU_SEEK_SET: | ||
941 | break; | ||
942 | |||
943 | case MU_SEEK_CUR: | ||
944 | off += hstr->off; | ||
945 | break; | ||
946 | |||
947 | case MU_SEEK_END: | ||
948 | off += hstr->hdr->size; | ||
949 | break; | ||
950 | } | ||
951 | |||
952 | if (off < 0 || off > hstr->hdr->size) | 938 | if (off < 0 || off > hstr->hdr->size) |
953 | return ESPIPE; | 939 | return ESPIPE; |
954 | hstr->off = off; | 940 | hstr->off = off; | ... | ... |
... | @@ -312,25 +312,10 @@ _mapfile_open (mu_stream_t stream) | ... | @@ -312,25 +312,10 @@ _mapfile_open (mu_stream_t stream) |
312 | } | 312 | } |
313 | 313 | ||
314 | static int | 314 | static int |
315 | _mapfile_seek (struct _mu_stream *str, mu_off_t off, int whence, mu_off_t *presult) | 315 | _mapfile_seek (struct _mu_stream *str, mu_off_t off, mu_off_t *presult) |
316 | { | 316 | { |
317 | struct _mu_mapfile_stream *mfs = (struct _mu_mapfile_stream *) str; | 317 | struct _mu_mapfile_stream *mfs = (struct _mu_mapfile_stream *) str; |
318 | 318 | ||
319 | /* FIXME */ | ||
320 | switch (whence) | ||
321 | { | ||
322 | case MU_SEEK_SET: | ||
323 | break; | ||
324 | |||
325 | case MU_SEEK_CUR: | ||
326 | off += mfs->offset; | ||
327 | break; | ||
328 | |||
329 | case MU_SEEK_END: | ||
330 | off += mfs->size; | ||
331 | break; | ||
332 | } | ||
333 | |||
334 | if (off < 0 || off >= mfs->size) | 319 | if (off < 0 || off >= mfs->size) |
335 | return ESPIPE; | 320 | return ESPIPE; |
336 | mfs->offset = off; | 321 | mfs->offset = off; | ... | ... |
... | @@ -166,24 +166,9 @@ _memory_ioctl (struct _mu_stream *stream, int code, void *ptr) | ... | @@ -166,24 +166,9 @@ _memory_ioctl (struct _mu_stream *stream, int code, void *ptr) |
166 | } | 166 | } |
167 | 167 | ||
168 | static int | 168 | static int |
169 | _memory_seek (struct _mu_stream *stream, mu_off_t off, int whence, | 169 | _memory_seek (struct _mu_stream *stream, mu_off_t off, mu_off_t *presult) |
170 | mu_off_t *presult) | ||
171 | { | 170 | { |
172 | struct _mu_memory_stream *mfs = (struct _mu_memory_stream *) stream; | 171 | struct _mu_memory_stream *mfs = (struct _mu_memory_stream *) stream; |
173 | |||
174 | switch (whence) | ||
175 | { | ||
176 | case MU_SEEK_SET: | ||
177 | break; | ||
178 | |||
179 | case MU_SEEK_CUR: | ||
180 | off += mfs->offset; | ||
181 | break; | ||
182 | |||
183 | case MU_SEEK_END: | ||
184 | off += mfs->size; | ||
185 | break; | ||
186 | } | ||
187 | 172 | ||
188 | if (off < 0) | 173 | if (off < 0) |
189 | return ESPIPE; | 174 | return ESPIPE; | ... | ... |
... | @@ -149,8 +149,7 @@ _message_stream_size (struct _mu_stream *str, mu_off_t *psize) | ... | @@ -149,8 +149,7 @@ _message_stream_size (struct _mu_stream *str, mu_off_t *psize) |
149 | } | 149 | } |
150 | 150 | ||
151 | static int | 151 | static int |
152 | _message_stream_seek (struct _mu_stream *str, mu_off_t off, int whence, | 152 | _message_stream_seek (struct _mu_stream *str, mu_off_t off, mu_off_t *ppos) |
153 | mu_off_t *ppos) | ||
154 | { | 153 | { |
155 | struct _mu_message_stream *sp = (struct _mu_message_stream *)str; | 154 | struct _mu_message_stream *sp = (struct _mu_message_stream *)str; |
156 | size_t hsize, size; | 155 | size_t hsize, size; |
... | @@ -163,25 +162,6 @@ _message_stream_seek (struct _mu_stream *str, mu_off_t off, int whence, | ... | @@ -163,25 +162,6 @@ _message_stream_seek (struct _mu_stream *str, mu_off_t off, int whence, |
163 | mu_body_size (sp->msg->body, &size); | 162 | mu_body_size (sp->msg->body, &size); |
164 | size += hsize; | 163 | size += hsize; |
165 | 164 | ||
166 | switch (whence) | ||
167 | { | ||
168 | case MU_SEEK_SET: | ||
169 | break; | ||
170 | |||
171 | case MU_SEEK_CUR: | ||
172 | { | ||
173 | mu_off_t cur; | ||
174 | rc = mu_stream_seek (sp->transport, 0, MU_SEEK_CUR, &cur); | ||
175 | if (rc) | ||
176 | return rc; | ||
177 | off += cur; | ||
178 | } | ||
179 | break; | ||
180 | |||
181 | case MU_SEEK_END: | ||
182 | off += size; | ||
183 | break; | ||
184 | } | ||
185 | if (off < 0 || off >= size) | 165 | if (off < 0 || off >= size) |
186 | return ESPIPE; | 166 | return ESPIPE; |
187 | 167 | ... | ... |
... | @@ -303,27 +303,12 @@ _message_done (mu_stream_t stream) | ... | @@ -303,27 +303,12 @@ _message_done (mu_stream_t stream) |
303 | } | 303 | } |
304 | 304 | ||
305 | static int | 305 | static int |
306 | _message_seek (struct _mu_stream *stream, mu_off_t off, int whence, | 306 | _message_seek (struct _mu_stream *stream, mu_off_t off, mu_off_t *presult) |
307 | mu_off_t *presult) | ||
308 | { | 307 | { |
309 | struct _mu_message_stream *s = (struct _mu_message_stream*) stream; | 308 | struct _mu_message_stream *s = (struct _mu_message_stream*) stream; |
310 | mu_off_t size; | 309 | mu_off_t size; |
311 | 310 | ||
312 | mu_stream_size (stream, &size); | 311 | mu_stream_size (stream, &size); |
313 | switch (whence) | ||
314 | { | ||
315 | case MU_SEEK_SET: | ||
316 | break; | ||
317 | |||
318 | case MU_SEEK_CUR: | ||
319 | off += s->offset; | ||
320 | break; | ||
321 | |||
322 | case MU_SEEK_END: | ||
323 | off += size; | ||
324 | break; | ||
325 | } | ||
326 | |||
327 | if (off < 0 || off >= size) | 312 | if (off < 0 || off >= size) |
328 | return ESPIPE; | 313 | return ESPIPE; |
329 | s->offset = off; | 314 | s->offset = off; | ... | ... |
... | @@ -544,24 +544,11 @@ struct _mime_body_stream | ... | @@ -544,24 +544,11 @@ struct _mime_body_stream |
544 | 544 | ||
545 | /* FIXME: The seek method is defective */ | 545 | /* FIXME: The seek method is defective */ |
546 | static int | 546 | static int |
547 | _mime_body_seek (mu_stream_t stream, mu_off_t off, int whence, | 547 | _mime_body_seek (mu_stream_t stream, mu_off_t off, mu_off_t *presult) |
548 | mu_off_t *presult) | ||
549 | { | 548 | { |
550 | struct _mime_body_stream *mstr = (struct _mime_body_stream *)stream; | 549 | struct _mime_body_stream *mstr = (struct _mime_body_stream *)stream; |
551 | mu_mime_t mime = mstr->mime; | 550 | mu_mime_t mime = mstr->mime; |
552 | 551 | ||
553 | switch (whence) | ||
554 | { | ||
555 | case MU_SEEK_SET: | ||
556 | break; | ||
557 | |||
558 | case MU_SEEK_CUR: | ||
559 | off += mime->cur_offset; | ||
560 | |||
561 | case MU_SEEK_END: | ||
562 | return ESPIPE; | ||
563 | } | ||
564 | |||
565 | if (off == 0) | 552 | if (off == 0) |
566 | { /* reset message */ | 553 | { /* reset message */ |
567 | mime->cur_offset = 0; | 554 | mime->cur_offset = 0; | ... | ... |
... | @@ -128,23 +128,9 @@ stdio_size (struct _mu_stream *str, off_t *psize) | ... | @@ -128,23 +128,9 @@ stdio_size (struct _mu_stream *str, off_t *psize) |
128 | } | 128 | } |
129 | 129 | ||
130 | static int | 130 | static int |
131 | stdio_seek (struct _mu_stream *str, mu_off_t off, int whence, mu_off_t *presult) | 131 | stdio_seek (struct _mu_stream *str, mu_off_t off, mu_off_t *presult) |
132 | { | 132 | { |
133 | struct _mu_stdio_stream *fs = (struct _mu_stdio_stream *) str; | 133 | struct _mu_stdio_stream *fs = (struct _mu_stdio_stream *) str; |
134 | /* FIXME */ | ||
135 | switch (whence) | ||
136 | { | ||
137 | case MU_SEEK_SET: | ||
138 | break; | ||
139 | |||
140 | case MU_SEEK_CUR: | ||
141 | off += fs->offset; | ||
142 | break; | ||
143 | |||
144 | case MU_SEEK_END: | ||
145 | off += fs->size; | ||
146 | break; | ||
147 | } | ||
148 | 134 | ||
149 | if (off < 0) | 135 | if (off < 0) |
150 | return ESPIPE; | 136 | return ESPIPE; | ... | ... |
... | @@ -323,7 +323,7 @@ mu_stream_seek (mu_stream_t stream, mu_off_t offset, int whence, | ... | @@ -323,7 +323,7 @@ mu_stream_seek (mu_stream_t stream, mu_off_t offset, int whence, |
323 | { | 323 | { |
324 | if ((rc = _stream_flush_buffer (stream, 1))) | 324 | if ((rc = _stream_flush_buffer (stream, 1))) |
325 | return rc; | 325 | return rc; |
326 | rc = stream->seek (stream, offset, MU_SEEK_SET, &stream->offset); | 326 | rc = stream->seek (stream, offset, &stream->offset); |
327 | if (rc) | 327 | if (rc) |
328 | return _stream_seterror (stream, rc, 1); | 328 | return _stream_seterror (stream, rc, 1); |
329 | _stream_cleareof (stream); | 329 | _stream_cleareof (stream); | ... | ... |
... | @@ -153,8 +153,7 @@ _streamref_done (struct _mu_stream *str) | ... | @@ -153,8 +153,7 @@ _streamref_done (struct _mu_stream *str) |
153 | } | 153 | } |
154 | 154 | ||
155 | static int | 155 | static int |
156 | _streamref_seek (struct _mu_stream *str, mu_off_t off, int whence, | 156 | _streamref_seek (struct _mu_stream *str, mu_off_t off, mu_off_t *ppos) |
157 | mu_off_t *ppos) | ||
158 | { | 157 | { |
159 | struct _mu_streamref *sp = (struct _mu_streamref *)str; | 158 | struct _mu_streamref *sp = (struct _mu_streamref *)str; |
160 | mu_off_t cur = sp->offset - sp->start; | 159 | mu_off_t cur = sp->offset - sp->start; |
... | @@ -171,25 +170,6 @@ _streamref_seek (struct _mu_stream *str, mu_off_t off, int whence, | ... | @@ -171,25 +170,6 @@ _streamref_seek (struct _mu_stream *str, mu_off_t off, int whence, |
171 | size -= sp->start; | 170 | size -= sp->start; |
172 | } | 171 | } |
173 | 172 | ||
174 | switch (whence) | ||
175 | { | ||
176 | case MU_SEEK_SET: | ||
177 | break; | ||
178 | |||
179 | case MU_SEEK_CUR: | ||
180 | if (off == 0) | ||
181 | { | ||
182 | *ppos = sp->offset - sp->start; | ||
183 | return 0; | ||
184 | } | ||
185 | off += cur; | ||
186 | break; | ||
187 | |||
188 | case MU_SEEK_END: | ||
189 | off += size; | ||
190 | break; | ||
191 | } | ||
192 | |||
193 | if (off < 0 || off >= size) | 173 | if (off < 0 || off >= size) |
194 | return sp->stream.last_err = ESPIPE; | 174 | return sp->stream.last_err = ESPIPE; |
195 | rc = mu_stream_seek (sp->transport, sp->start + off, MU_SEEK_SET, | 175 | rc = mu_stream_seek (sp->transport, sp->start + off, MU_SEEK_SET, | ... | ... |
-
Please register or sign in to post a comment