aboutsummaryrefslogtreecommitdiffstats
path: root/src/byte_source.c
diff options
context:
space:
mode:
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;
}