From e6abc21f9bde66d8f60078493354ba3713f9fcd8 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 25 Feb 2021 15:48:04 -0500 Subject: Simplify reader interface --- src/system.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/system.h') diff --git a/src/system.h b/src/system.h index fdfab4a4..df5827de 100644 --- a/src/system.h +++ b/src/system.h @@ -19,6 +19,7 @@ #include "attributes.h" +#include #include /// Open a file configured for fast sequential reading @@ -37,4 +38,20 @@ serd_allocate_buffer(size_t size); void serd_free_aligned(void* ptr); +/** fread-like wrapper for getc (which is faster). */ +static inline size_t +serd_file_read_byte(void* buf, size_t size, size_t nmemb, void* stream) +{ + (void)size; + (void)nmemb; + + const int c = getc((FILE*)stream); + if (c == EOF) { + *((uint8_t*)buf) = 0; + return 0; + } + *((uint8_t*)buf) = (uint8_t)c; + return 1; +} + #endif // SERD_SYSTEM_H -- cgit v1.2.1