aboutsummaryrefslogtreecommitdiffstats
path: root/src/byte_source.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-05-10 20:59:45 +0200
committerDavid Robillard <d@drobilla.net>2018-05-27 18:23:15 +0200
commita3b6babaf0186b34d801a75b62253573ef26a154 (patch)
tree22d0d45a45827da2025073660a38c0a39f5fbba3 /src/byte_source.c
parent8d1dcc05f7072651c0056221d00d8f1bf3fb80a1 (diff)
downloadserd-a3b6babaf0186b34d801a75b62253573ef26a154.tar.gz
serd-a3b6babaf0186b34d801a75b62253573ef26a154.tar.bz2
serd-a3b6babaf0186b34d801a75b62253573ef26a154.zip
Hide fopen wrapper and use reader interface consistently
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 c48d8ef7..25184f13 100644
--- a/src/byte_source.c
+++ b/src/byte_source.c
@@ -39,6 +39,7 @@ SerdStatus
serd_byte_source_open_source(SerdByteSource* source,
SerdSource read_func,
SerdStreamErrorFunc error_func,
+ SerdStreamCloseFunc close_func,
void* stream,
const char* name,
size_t page_size)
@@ -46,12 +47,13 @@ serd_byte_source_open_source(SerdByteSource* 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->cur = cur;
- source->error_func = error_func;
- source->read_func = read_func;
+ source->from_stream = true;
if (page_size > 1) {
source->file_buf = (char*)serd_bufalloc(page_size);
@@ -92,11 +94,16 @@ serd_byte_source_open_string(SerdByteSource* source, const char* utf8)
SerdStatus
serd_byte_source_close(SerdByteSource* source)
{
+ SerdStatus st = SERD_SUCCESS;
+ if (source->close_func) {
+ st = source->close_func(source->stream) ? SERD_ERR_UNKNOWN
+ : SERD_SUCCESS;
+ }
if (source->page_size > 1) {
free(source->file_buf);
}
memset(source, '\0', sizeof(*source));
- return SERD_SUCCESS;
+ return st;
}
SerdStatus