From 1a95f759fe3d642e8520e41e691e63f22a2f3b99 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 13 Nov 2020 10:52:56 +0100 Subject: Move fopen wrapper to world --- src/reader.c | 2 +- src/system.c | 21 --------------------- src/system.h | 4 ---- src/world.c | 28 ++++++++++++++++++++++++++++ src/world.h | 6 +++++- 5 files changed, 34 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/reader.c b/src/reader.c index 83f13e8c..90fee2db 100644 --- a/src/reader.c +++ b/src/reader.c @@ -260,7 +260,7 @@ serd_reader_start_file(SerdReader* reader, const char* uri, bool bulk) return SERD_BAD_ARG; } - FILE* fd = serd_fopen(path, "rb"); + FILE* fd = serd_world_fopen(reader->world, path, "rb"); free(path); if (!fd) { return SERD_BAD_STREAM; diff --git a/src/system.c b/src/system.c index efd9c7ae..ae9e11bc 100644 --- a/src/system.c +++ b/src/system.c @@ -6,35 +6,14 @@ #include "serd_config.h" #include "serd_internal.h" -#if USE_POSIX_FADVISE && USE_FILENO -# include -#endif - #ifdef _WIN32 # include #endif -#include #include #include #include -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 - (void)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 315ea681..d8737dae 100644 --- a/src/system.h +++ b/src/system.h @@ -9,10 +9,6 @@ #include #include -/// 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_MALLOC_FUNC void* serd_malloc_aligned(size_t alignment, size_t size); diff --git a/src/world.c b/src/world.c index 4d2e175a..916aa869 100644 --- a/src/world.c +++ b/src/world.c @@ -3,9 +3,37 @@ #include "world.h" +#include "serd_config.h" + +#if defined(USE_POSIX_FADVISE) +# include +#endif + +#include #include #include #include +#include + +FILE* +serd_world_fopen(SerdWorld* world, const char* path, const char* mode) +{ + FILE* fd = fopen(path, mode); + if (!fd) { + serd_world_errorf(world, + SERD_BAD_STREAM, + "failed to open file %s (%s)\n", + path, + strerror(errno)); + return NULL; + } + +#if USE_POSIX_FADVISE && USE_FILENO + (void)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 8281bb5e..dd3d4043 100644 --- a/src/world.h +++ b/src/world.h @@ -8,13 +8,17 @@ #include "serd/status.h" #include "serd/world.h" -#include +#include 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); -- cgit v1.2.1