aboutsummaryrefslogtreecommitdiffstats
path: root/src/byte_source.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2024-08-03 12:31:51 -0400
committerDavid Robillard <d@drobilla.net>2024-08-03 14:21:47 -0400
commitebe0b8697bca69abb7e7be1c731da4d54b10e462 (patch)
tree73f5b777ab632b2001a132eea82cd97499f330fa /src/byte_source.c
parentf73aae2f97d1faa8e41a8b8627e1e186a1f900f4 (diff)
downloadserd-ebe0b8697bca69abb7e7be1c731da4d54b10e462.tar.gz
serd-ebe0b8697bca69abb7e7be1c731da4d54b10e462.tar.bz2
serd-ebe0b8697bca69abb7e7be1c731da4d54b10e462.zip
Fix reading chunks from files without trailing newlines
Diffstat (limited to 'src/byte_source.c')
-rw-r--r--src/byte_source.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/byte_source.c b/src/byte_source.c
index 5443f4dd..122dc0f9 100644
--- a/src/byte_source.c
+++ b/src/byte_source.c
@@ -19,18 +19,17 @@ serd_byte_source_page(SerdByteSource* const source)
const size_t n_read =
source->read_func(source->file_buf, 1, source->page_size, source->stream);
+ source->buf_size = n_read;
+ if (n_read < source->page_size) {
+ source->file_buf[n_read] = '\0';
+ }
+
if (n_read == 0) {
- source->file_buf[0] = '\0';
- source->eof = true;
+ source->eof = true;
return (source->error_func(source->stream) ? SERD_ERR_UNKNOWN
: SERD_FAILURE);
}
- if (n_read < source->page_size) {
- source->file_buf[n_read] = '\0';
- source->buf_size = n_read;
- }
-
return SERD_SUCCESS;
}
@@ -52,7 +51,7 @@ serd_byte_source_open_source(SerdByteSource* const source,
source->stream = stream;
source->from_stream = true;
source->page_size = page_size;
- source->buf_size = page_size;
+ source->buf_size = 0U;
source->cur = cur;
source->error_func = error_func;
source->read_func = read_func;