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/world.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/world.c') 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) -- cgit v1.2.1