istream-limit.c revision e50c7afe297ab10e07a8acc816c76ce9d45ef409
f8740ac53310cd28ba4ec6dc9e9ce6e9a3688f39Timo Sirainen/* Copyright (C) 2003 Timo Sirainen */
7000810786f2959f02cd6d2f4151a9eb61ff5db8Timo Sirainenstatic void _close(struct _iostream *stream __attr_unused__)
7000810786f2959f02cd6d2f4151a9eb61ff5db8Timo Sirainen struct limit_istream *lstream = (struct limit_istream *) stream;
7000810786f2959f02cd6d2f4151a9eb61ff5db8Timo Sirainen /* get to same position in parent stream */
7000810786f2959f02cd6d2f4151a9eb61ff5db8Timo Sirainen i_stream_seek(lstream->input, lstream->v_start_offset +
7000810786f2959f02cd6d2f4151a9eb61ff5db8Timo Sirainenstatic void _set_max_buffer_size(struct _iostream *stream, size_t max_size)
7000810786f2959f02cd6d2f4151a9eb61ff5db8Timo Sirainen struct limit_istream *lstream = (struct limit_istream *) stream;
7000810786f2959f02cd6d2f4151a9eb61ff5db8Timo Sirainen i_stream_set_max_buffer_size(lstream->input, max_size);
7000810786f2959f02cd6d2f4151a9eb61ff5db8Timo Sirainen struct limit_istream *lstream = (struct limit_istream *) stream;
7000810786f2959f02cd6d2f4151a9eb61ff5db8Timo Sirainen (stream->pos - stream->skip) >= lstream->v_size) {
7000810786f2959f02cd6d2f4151a9eb61ff5db8Timo Sirainen lstream->v_start_offset + stream->istream.v_offset) {
7000810786f2959f02cd6d2f4151a9eb61ff5db8Timo Sirainen stream->buffer = i_stream_get_data(lstream->input, &pos);
f8740ac53310cd28ba4ec6dc9e9ce6e9a3688f39Timo Sirainen if ((ret = i_stream_read(lstream->input)) == -2) {
f8740ac53310cd28ba4ec6dc9e9ce6e9a3688f39Timo Sirainen stream->buffer = i_stream_get_data(lstream->input, &pos);
f8740ac53310cd28ba4ec6dc9e9ce6e9a3688f39Timo Sirainen left = lstream->v_size - stream->istream.v_offset;
f8740ac53310cd28ba4ec6dc9e9ce6e9a3688f39Timo Sirainen ret = pos > stream->pos ? (ssize_t)(pos - stream->pos) :
f8740ac53310cd28ba4ec6dc9e9ce6e9a3688f39Timo Sirainenstatic void _seek(struct _istream *stream, uoff_t v_offset)
f8740ac53310cd28ba4ec6dc9e9ce6e9a3688f39Timo Sirainen struct limit_istream *lstream = (struct limit_istream *) stream;
f8740ac53310cd28ba4ec6dc9e9ce6e9a3688f39Timo Sirainenstatic const struct stat *_stat(struct _istream *stream)
7000810786f2959f02cd6d2f4151a9eb61ff5db8Timo Sirainen struct limit_istream *lstream = (struct limit_istream *) stream;
7000810786f2959f02cd6d2f4151a9eb61ff5db8Timo Sirainenstruct istream *i_stream_create_limit(pool_t pool, struct istream *input,
7000810786f2959f02cd6d2f4151a9eb61ff5db8Timo Sirainen lstream = p_new(pool, struct limit_istream, 1);
f8740ac53310cd28ba4ec6dc9e9ce6e9a3688f39Timo Sirainen input->v_offset - v_start_offset > v_size ? v_size :
f8740ac53310cd28ba4ec6dc9e9ce6e9a3688f39Timo Sirainen lstream->istream.iostream.set_max_buffer_size = _set_max_buffer_size;
f8740ac53310cd28ba4ec6dc9e9ce6e9a3688f39Timo Sirainen lstream->istream.istream.seekable = input->seekable;