istream-data.c revision 602a0434db30d8e3292d1c161a803d96a879a74f
5f5870385cff47efd2f58e7892f251cf13761528Timo Sirainen/* Copyright (c) 2002-2003 Timo Sirainen */
2201e2cc1b3f744dac61c2bf8095bcb6b5719540Timo Sirainen
2201e2cc1b3f744dac61c2bf8095bcb6b5719540Timo Sirainen#include "lib.h"
2201e2cc1b3f744dac61c2bf8095bcb6b5719540Timo Sirainen#include "istream-internal.h"
6967fa47dde9f2726bd86019a50627dacf2d7509Timo Sirainen
34830cefe1757de0ffca67acdc529d5bc8b06b66Timo Sirainenstatic void _close(struct _iostream *stream __attr_unused__)
2201e2cc1b3f744dac61c2bf8095bcb6b5719540Timo Sirainen{
6967fa47dde9f2726bd86019a50627dacf2d7509Timo Sirainen}
0536ccb51d41e3078c3a9fa33e509fb4b2420f95Timo Sirainen
4499995f7029bafd85094694b6a14752ea34c9b3Timo Sirainenstatic void _destroy(struct _iostream *stream __attr_unused__)
2201e2cc1b3f744dac61c2bf8095bcb6b5719540Timo Sirainen{
2201e2cc1b3f744dac61c2bf8095bcb6b5719540Timo Sirainen}
34830cefe1757de0ffca67acdc529d5bc8b06b66Timo Sirainen
34830cefe1757de0ffca67acdc529d5bc8b06b66Timo Sirainenstatic void _set_max_buffer_size(struct _iostream *stream __attr_unused__,
2201e2cc1b3f744dac61c2bf8095bcb6b5719540Timo Sirainen size_t max_size __attr_unused__)
2201e2cc1b3f744dac61c2bf8095bcb6b5719540Timo Sirainen{
2201e2cc1b3f744dac61c2bf8095bcb6b5719540Timo Sirainen}
252db51b6c0a605163326b3ea5d09e9936ca3b29Timo Sirainen
2201e2cc1b3f744dac61c2bf8095bcb6b5719540Timo Sirainenstatic ssize_t _read(struct _istream *stream __attr_unused__)
fcca16701767c6b92227a9ee125de69d257882f6Timo Sirainen{
2201e2cc1b3f744dac61c2bf8095bcb6b5719540Timo Sirainen stream->istream.eof = TRUE;
d10cb4d7a80571af21f776c65604442bf09b1765Timo Sirainen return -1;
2201e2cc1b3f744dac61c2bf8095bcb6b5719540Timo Sirainen}
fcca16701767c6b92227a9ee125de69d257882f6Timo Sirainen
fcca16701767c6b92227a9ee125de69d257882f6Timo Sirainenstatic void _seek(struct _istream *stream, uoff_t v_offset,
fcca16701767c6b92227a9ee125de69d257882f6Timo Sirainen int mark __attr_unused__)
5702c81e2d788449c3bc207eb9c19e539458ad9eTimo Sirainen{
2201e2cc1b3f744dac61c2bf8095bcb6b5719540Timo Sirainen stream->skip = v_offset;
2201e2cc1b3f744dac61c2bf8095bcb6b5719540Timo Sirainen stream->istream.v_offset = v_offset;
2201e2cc1b3f744dac61c2bf8095bcb6b5719540Timo Sirainen}
2201e2cc1b3f744dac61c2bf8095bcb6b5719540Timo Sirainen
6967fa47dde9f2726bd86019a50627dacf2d7509Timo Sirainenstatic const struct stat *_stat(struct _istream *stream)
2201e2cc1b3f744dac61c2bf8095bcb6b5719540Timo Sirainen{
2201e2cc1b3f744dac61c2bf8095bcb6b5719540Timo Sirainen stream->statbuf.st_size = stream->pos;
a94936bafd127680184da114c6a177b37ff656e5Timo Sirainen return &stream->statbuf;
2201e2cc1b3f744dac61c2bf8095bcb6b5719540Timo Sirainen}
2201e2cc1b3f744dac61c2bf8095bcb6b5719540Timo Sirainen
2201e2cc1b3f744dac61c2bf8095bcb6b5719540Timo Sirainenstruct istream *i_stream_create_from_data(pool_t pool, const void *data,
2201e2cc1b3f744dac61c2bf8095bcb6b5719540Timo Sirainen size_t size)
2201e2cc1b3f744dac61c2bf8095bcb6b5719540Timo Sirainen{
2201e2cc1b3f744dac61c2bf8095bcb6b5719540Timo Sirainen struct _istream *stream;
2201e2cc1b3f744dac61c2bf8095bcb6b5719540Timo Sirainen
2201e2cc1b3f744dac61c2bf8095bcb6b5719540Timo Sirainen stream = p_new(pool, struct _istream, 1);
2201e2cc1b3f744dac61c2bf8095bcb6b5719540Timo Sirainen stream->buffer = data;
2201e2cc1b3f744dac61c2bf8095bcb6b5719540Timo Sirainen stream->pos = size;
2201e2cc1b3f744dac61c2bf8095bcb6b5719540Timo Sirainen
a6f281d078ed03d555802c1a8e15fefce80132dcTimo Sirainen stream->iostream.close = _close;
a6f281d078ed03d555802c1a8e15fefce80132dcTimo Sirainen stream->iostream.destroy = _destroy;
a6f281d078ed03d555802c1a8e15fefce80132dcTimo Sirainen stream->iostream.set_max_buffer_size = _set_max_buffer_size;
a6f281d078ed03d555802c1a8e15fefce80132dcTimo Sirainen
a6f281d078ed03d555802c1a8e15fefce80132dcTimo Sirainen stream->read = _read;
a6f281d078ed03d555802c1a8e15fefce80132dcTimo Sirainen stream->seek = _seek;
a6f281d078ed03d555802c1a8e15fefce80132dcTimo Sirainen stream->stat = _stat;
a6f281d078ed03d555802c1a8e15fefce80132dcTimo Sirainen
a94936bafd127680184da114c6a177b37ff656e5Timo Sirainen stream->istream.seekable = TRUE;
2201e2cc1b3f744dac61c2bf8095bcb6b5719540Timo Sirainen return _i_stream_create(stream, pool, -1, 0);
2201e2cc1b3f744dac61c2bf8095bcb6b5719540Timo Sirainen}
2201e2cc1b3f744dac61c2bf8095bcb6b5719540Timo Sirainen