From 1a25e379b3dfcc8716cfbcbac58a7076cffddc3a Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 26 Dec 2018 19:25:51 -0500 Subject: Hide fopen wrapper and use reader interface consistently --- src/serd_internal.h | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'src/serd_internal.h') diff --git a/src/serd_internal.h b/src/serd_internal.h index 81f90e60..64094a88 100644 --- a/src/serd_internal.h +++ b/src/serd_internal.h @@ -22,9 +22,7 @@ #include "serd_config.h" #include "world.h" -#include "serd/serd.h" - -#if defined(HAVE_POSIX_FADVISE) && defined(HAVE_FILENO) +#if defined(HAVE_POSIX_MEMALIGN) # include #endif @@ -44,19 +42,20 @@ # define MIN(a, b) (((a) < (b)) ? (a) : (b)) #endif -static inline FILE* -serd_fopen(const char* path, const char* mode) +/** 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) { - FILE* fd = fopen(path, mode); - if (!fd) { - fprintf(stderr, "error: failed to open file %s (%s)\n", - path, strerror(errno)); - return NULL; + (void)size; + (void)nmemb; + + const int c = getc((FILE*)stream); + if (c == EOF) { + *((uint8_t*)buf) = 0; + return 0; } -#if defined(HAVE_POSIX_FADVISE) && defined(HAVE_FILENO) - posix_fadvise(fileno(fd), 0, 0, POSIX_FADV_SEQUENTIAL); -#endif - return fd; + *((uint8_t*)buf) = (uint8_t)c; + return 1; } static inline void* -- cgit v1.2.1