aboutsummaryrefslogtreecommitdiffstats
path: root/src/byte_source.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-10-02 09:08:22 -0400
committerDavid Robillard <d@drobilla.net>2023-12-02 16:27:02 -0500
commit8978501e5cf06f366eb14f6ef5f5f7f2f8e34986 (patch)
tree203504ff9b58fc1ba5b71ed1d066104f6a08ffb9 /src/byte_source.c
parentc2e59da8865a8c5719b8ddaf5f68204729a8ebab (diff)
downloadserd-8978501e5cf06f366eb14f6ef5f5f7f2f8e34986.tar.gz
serd-8978501e5cf06f366eb14f6ef5f5f7f2f8e34986.tar.bz2
serd-8978501e5cf06f366eb14f6ef5f5f7f2f8e34986.zip
Simplify reader interface
Diffstat (limited to 'src/byte_source.c')
-rw-r--r--src/byte_source.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/byte_source.c b/src/byte_source.c
index 3a2f10b6..d6510eb9 100644
--- a/src/byte_source.c
+++ b/src/byte_source.c
@@ -35,6 +35,7 @@ SerdStatus
serd_byte_source_open_source(SerdByteSource* const source,
const SerdReadFunc read_func,
const SerdStreamErrorFunc error_func,
+ const SerdStreamCloseFunc close_func,
void* const stream,
const char* const name,
const size_t page_size)
@@ -42,13 +43,14 @@ serd_byte_source_open_source(SerdByteSource* const source,
const Cursor cur = {name, 1, 1};
memset(source, '\0', sizeof(*source));
+ source->read_func = read_func;
+ source->error_func = error_func;
+ source->close_func = close_func;
source->stream = stream;
- source->from_stream = true;
source->page_size = page_size;
source->buf_size = page_size;
source->cur = cur;
- source->error_func = error_func;
- source->read_func = read_func;
+ source->from_stream = true;
if (page_size > 1) {
source->file_buf = (uint8_t*)serd_allocate_buffer(page_size);
@@ -94,10 +96,15 @@ serd_byte_source_open_string(SerdByteSource* const source,
SerdStatus
serd_byte_source_close(SerdByteSource* const source)
{
+ SerdStatus st = SERD_SUCCESS;
+ if (source->close_func) {
+ st = source->close_func(source->stream) ? SERD_BAD_STREAM : SERD_SUCCESS;
+ }
+
if (source->page_size > 1) {
serd_free_aligned(source->file_buf);
}
memset(source, '\0', sizeof(*source));
- return SERD_SUCCESS;
+ return st;
}