diff options
author | David Robillard <d@drobilla.net> | 2024-08-03 12:31:51 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2024-08-03 14:21:47 -0400 |
commit | ebe0b8697bca69abb7e7be1c731da4d54b10e462 (patch) | |
tree | 73f5b777ab632b2001a132eea82cd97499f330fa /src | |
parent | f73aae2f97d1faa8e41a8b8627e1e186a1f900f4 (diff) | |
download | serd-ebe0b8697bca69abb7e7be1c731da4d54b10e462.tar.gz serd-ebe0b8697bca69abb7e7be1c731da4d54b10e462.tar.bz2 serd-ebe0b8697bca69abb7e7be1c731da4d54b10e462.zip |
Fix reading chunks from files without trailing newlines
Diffstat (limited to 'src')
-rw-r--r-- | src/byte_source.c | 15 | ||||
-rw-r--r-- | src/byte_source.h | 2 |
2 files changed, 8 insertions, 9 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; diff --git a/src/byte_source.h b/src/byte_source.h index bd6701c9..afd9ccb9 100644 --- a/src/byte_source.h +++ b/src/byte_source.h @@ -83,7 +83,7 @@ serd_byte_source_advance(SerdByteSource* source) if (source->page_size > 1) { if (++source->read_head == source->page_size) { st = serd_byte_source_page(source); - } else if (source->read_head == source->buf_size) { + } else if (source->read_head >= source->buf_size) { source->eof = true; } } else { |