diff options
Diffstat (limited to 'src/system.h')
-rw-r--r-- | src/system.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/system.h b/src/system.h index 15f93363..315ea681 100644 --- a/src/system.h +++ b/src/system.h @@ -6,6 +6,7 @@ #include "serd/attributes.h" +#include <stdint.h> #include <stdio.h> /// Open a file configured for fast sequential reading @@ -28,4 +29,20 @@ serd_allocate_buffer(size_t size); void serd_free_aligned(void* ptr); +/// Wrapper for getc that is compatible with SerdReadFunc +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_SRC_SYSTEM_H |