diff options
-rw-r--r-- | src/reader.c | 2 | ||||
-rw-r--r-- | src/system.c | 21 | ||||
-rw-r--r-- | src/system.h | 4 | ||||
-rw-r--r-- | src/world.c | 28 | ||||
-rw-r--r-- | src/world.h | 6 |
5 files changed, 35 insertions, 26 deletions
diff --git a/src/reader.c b/src/reader.c index 7b4e5fed..2bcd0969 100644 --- a/src/reader.c +++ b/src/reader.c @@ -276,7 +276,7 @@ serd_reader_start_file(SerdReader* reader, const char* uri, bool bulk) return SERD_ERR_BAD_ARG; } - FILE* fd = serd_fopen(path, "rb"); + FILE* fd = serd_world_fopen(reader->world, path, "rb"); free(path); if (!fd) { return SERD_ERR_UNKNOWN; diff --git a/src/system.c b/src/system.c index e3d8d836..76a39ad2 100644 --- a/src/system.c +++ b/src/system.c @@ -19,35 +19,14 @@ #include "serd_config.h" #include "serd_internal.h" -#if USE_POSIX_FADVISE && USE_FILENO -# include <fcntl.h> -#endif - #ifdef _WIN32 # include <malloc.h> #endif -#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -FILE* -serd_fopen(const char* const path, const char* const mode) -{ - FILE* fd = fopen(path, mode); - if (!fd) { - fprintf( - stderr, "error: failed to open file %s (%s)\n", path, strerror(errno)); - return NULL; - } - -#if USE_POSIX_FADVISE && USE_FILENO - posix_fadvise(fileno(fd), 0, 0, POSIX_FADV_SEQUENTIAL); -#endif - return fd; -} - void* serd_malloc_aligned(const size_t alignment, const size_t size) { diff --git a/src/system.h b/src/system.h index 944c8942..ff8ec7c0 100644 --- a/src/system.h +++ b/src/system.h @@ -22,10 +22,6 @@ #include <stdint.h> #include <stdio.h> -/// Open a file configured for fast sequential reading -FILE* -serd_fopen(const char* path, const char* mode); - /// Allocate a buffer aligned to `alignment` bytes SERD_I_MALLOC_FUNC void* diff --git a/src/world.c b/src/world.c index aa260e37..71fd32c8 100644 --- a/src/world.c +++ b/src/world.c @@ -16,9 +16,37 @@ #include "world.h" +#include "serd_config.h" + +#if defined(USE_POSIX_FADVISE) +# include <fcntl.h> +#endif + +#include <errno.h> #include <stdarg.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> + +FILE* +serd_world_fopen(SerdWorld* world, const char* path, const char* mode) +{ + FILE* fd = fopen(path, mode); + if (!fd) { + serd_world_errorf(world, + SERD_ERR_INTERNAL, + "failed to open file %s (%s)\n", + path, + strerror(errno)); + return NULL; + } + +#if USE_POSIX_FADVISE && USE_FILENO + posix_fadvise(fileno(fd), 0, 0, POSIX_FADV_SEQUENTIAL); +#endif + + return fd; +} SerdStatus serd_world_error(const SerdWorld* const world, const SerdError* const e) diff --git a/src/world.h b/src/world.h index 08c351fe..ab7aad80 100644 --- a/src/world.h +++ b/src/world.h @@ -19,11 +19,17 @@ #include "serd/serd.h" +#include <stdio.h> + struct SerdWorldImpl { SerdErrorFunc error_func; void* error_handle; }; +/// Open a file configured for fast sequential reading +FILE* +serd_world_fopen(SerdWorld* world, const char* path, const char* mode); + SerdStatus serd_world_error(const SerdWorld* world, const SerdError* e); |