From 29fefcad4d5f891e2d4325c482d4242d530aef4a Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 10 May 2018 20:59:45 +0200 Subject: Hide fopen wrapper and use reader interface consistently --- src/world.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/world.c') diff --git a/src/world.c b/src/world.c index 0210760d..7ec483e8 100644 --- a/src/world.c +++ b/src/world.c @@ -14,12 +14,35 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#define _POSIX_C_SOURCE 200809L /* for posix_fadvise */ + #include "serd_internal.h" +#include "serd_config.h" #include +#include +#if defined(HAVE_POSIX_FADVISE) +# include +#endif #include "world.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 defined(HAVE_POSIX_FADVISE) && defined(HAVE_FILENO) + posix_fadvise(fileno(fd), 0, 0, POSIX_FADV_SEQUENTIAL); +#endif + return fd; +} + SerdStatus serd_world_error(const SerdWorld* world, const SerdError* e) { -- cgit v1.2.1