diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/byte_source.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/byte_source.c b/src/byte_source.c index c0cb6413..567beee8 100644 --- a/src/byte_source.c +++ b/src/byte_source.c @@ -60,6 +60,18 @@ serd_byte_source_page(SerdByteSource* const source) return SERD_SUCCESS; } +static void +serd_byte_source_init_buffer(SerdByteSource* const source) +{ + if (source->page_size > 1) { + source->file_buf = (uint8_t*)serd_allocate_buffer(source->page_size); + source->read_buf = source->file_buf; + memset(source->file_buf, '\0', source->page_size); + } else { + source->read_buf = &source->read_byte; + } +} + SerdByteSource* serd_byte_source_new_function(const SerdReadFunc read_func, const SerdStreamErrorFunc error_func, @@ -92,13 +104,7 @@ serd_byte_source_new_function(const SerdReadFunc read_func, source->caret.line = 1u; source->caret.col = 1u; - if (page_size > 1) { - source->file_buf = (uint8_t*)serd_allocate_buffer(page_size); - source->read_buf = source->file_buf; - memset(source->file_buf, '\0', page_size); - } else { - source->read_buf = &source->read_byte; - } + serd_byte_source_init_buffer(source); return source; } @@ -145,13 +151,7 @@ serd_byte_source_new_filename(const char* const path, const size_t page_size) source->caret.line = 1u; source->caret.col = 1u; - if (page_size > 1) { - source->file_buf = (uint8_t*)serd_allocate_buffer(page_size); - source->read_buf = source->file_buf; - memset(source->file_buf, '\0', page_size); - } else { - source->read_buf = &source->read_byte; - } + serd_byte_source_init_buffer(source); #if USE_POSIX_FADVISE && USE_FILENO posix_fadvise(fileno(fd), 0, 0, POSIX_FADV_SEQUENTIAL); |