diff options
author | David Robillard <d@drobilla.net> | 2020-11-13 10:52:56 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2021-03-08 23:23:05 -0500 |
commit | fd276bcf70bad4520ca1d6f3c73f88073b3b58cf (patch) | |
tree | af2c60324c119f78f85bba30cdb5223d9dcf10c0 /src/world.c | |
parent | a4f6754a4048f2bcb04482938d5a98e9ab77d4fc (diff) | |
download | serd-fd276bcf70bad4520ca1d6f3c73f88073b3b58cf.tar.gz serd-fd276bcf70bad4520ca1d6f3c73f88073b3b58cf.tar.bz2 serd-fd276bcf70bad4520ca1d6f3c73f88073b3b58cf.zip |
Move fopen wrapper to world
Diffstat (limited to 'src/world.c')
-rw-r--r-- | src/world.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/world.c b/src/world.c index f74513da..73bc9927 100644 --- a/src/world.c +++ b/src/world.c @@ -14,11 +14,39 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#define _POSIX_C_SOURCE 200809L /* for posix_fadvise */ + #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 defined(USE_POSIX_FADVISE) && defined(USE_FILENO) + posix_fadvise(fileno(fd), 0, 0, POSIX_FADV_SEQUENTIAL); +#endif + return fd; +} SerdStatus serd_world_error(const SerdWorld* world, const SerdError* e) |