input_stream: make seek(), buffer() optional

Make those two methods optional to implement, and let input_stream.c
provide fallbacks.  The buffer() method will be removed one day, and
there is now only one implementation left (input_curl.c).
This commit is contained in:
Max Kellermann 2009-01-30 00:58:03 +01:00
parent 82cfce76eb
commit 32d6d4499e
5 changed files with 7 additions and 44 deletions

View File

@ -256,19 +256,6 @@ bz2_is_eof(struct input_stream *is)
return false; return false;
} }
static bool
bz2_is_seek(G_GNUC_UNUSED struct input_stream *is,
G_GNUC_UNUSED off_t offset, G_GNUC_UNUSED int whence)
{
return false;
}
static int
bz2_is_buffer(G_GNUC_UNUSED struct input_stream *is)
{
return 0;
}
/* exported structures */ /* exported structures */
static const char *const bz2_extensions[] = { static const char *const bz2_extensions[] = {
@ -280,8 +267,6 @@ static const struct input_plugin bz2_inputplugin = {
.close = bz2_is_close, .close = bz2_is_close,
.read = bz2_is_read, .read = bz2_is_read,
.eof = bz2_is_eof, .eof = bz2_is_eof,
.seek = bz2_is_seek,
.buffer = bz2_is_buffer
}; };
const struct archive_plugin bz2_plugin = { const struct archive_plugin bz2_plugin = {

View File

@ -211,19 +211,6 @@ iso_is_eof(struct input_stream *is)
return (context->cur_ofs == context->statbuf->size); return (context->cur_ofs == context->statbuf->size);
} }
static bool
iso_is_seek(G_GNUC_UNUSED struct input_stream *is,
G_GNUC_UNUSED off_t offset, G_GNUC_UNUSED int whence)
{
return false;
}
static int
iso_is_buffer(G_GNUC_UNUSED struct input_stream *is)
{
return 0;
}
/* exported structures */ /* exported structures */
static const char *const iso_extensions[] = { static const char *const iso_extensions[] = {
@ -235,8 +222,6 @@ static const struct input_plugin iso_inputplugin = {
.close = iso_is_close, .close = iso_is_close,
.read = iso_is_read, .read = iso_is_read,
.eof = iso_is_eof, .eof = iso_is_eof,
.seek = iso_is_seek,
.buffer = iso_is_buffer
}; };
const struct archive_plugin iso_plugin = { const struct archive_plugin iso_plugin = {

View File

@ -167,12 +167,6 @@ zip_is_seek(G_GNUC_UNUSED struct input_stream *is,
return false; return false;
} }
static int
zip_is_buffer(G_GNUC_UNUSED struct input_stream *is)
{
return 0;
}
/* exported structures */ /* exported structures */
static const char *const zip_extensions[] = { static const char *const zip_extensions[] = {
@ -185,7 +179,6 @@ static const struct input_plugin zip_inputplugin = {
.read = zip_is_read, .read = zip_is_read,
.eof = zip_is_eof, .eof = zip_is_eof,
.seek = zip_is_seek, .seek = zip_is_seek,
.buffer = zip_is_buffer
}; };
const struct archive_plugin zip_plugin = { const struct archive_plugin zip_plugin = {

View File

@ -116,16 +116,9 @@ input_file_eof(struct input_stream *is)
return is->offset >= is->size; return is->offset >= is->size;
} }
static int
input_file_buffer(G_GNUC_UNUSED struct input_stream *is)
{
return 0;
}
const struct input_plugin input_plugin_file = { const struct input_plugin input_plugin_file = {
.open = input_file_open, .open = input_file_open,
.close = input_file_close, .close = input_file_close,
.buffer = input_file_buffer,
.read = input_file_read, .read = input_file_read,
.eof = input_file_eof, .eof = input_file_eof,
.seek = input_file_seek, .seek = input_file_seek,

View File

@ -86,6 +86,7 @@ input_stream_open(struct input_stream *is, const char *url)
assert(is->plugin->close != NULL); assert(is->plugin->close != NULL);
assert(is->plugin->read != NULL); assert(is->plugin->read != NULL);
assert(is->plugin->eof != NULL); assert(is->plugin->eof != NULL);
assert(!is->seekable || is->plugin->seek != NULL);
return true; return true;
} }
@ -97,6 +98,9 @@ input_stream_open(struct input_stream *is, const char *url)
bool bool
input_stream_seek(struct input_stream *is, off_t offset, int whence) input_stream_seek(struct input_stream *is, off_t offset, int whence)
{ {
if (is->plugin->seek == NULL)
return false;
return is->plugin->seek(is, offset, whence); return is->plugin->seek(is, offset, whence);
} }
@ -133,5 +137,8 @@ bool input_stream_eof(struct input_stream *is)
int input_stream_buffer(struct input_stream *is) int input_stream_buffer(struct input_stream *is)
{ {
if (is->plugin->buffer == NULL)
return 0;
return is->plugin->buffer(is); return is->plugin->buffer(is);
} }