aboutsummaryrefslogtreecommitdiffstats
path: root/src/world.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-11-13 10:52:56 +0100
committerDavid Robillard <d@drobilla.net>2022-01-13 23:03:48 -0500
commitbf4f881c2241fa8ae6459bd9c8ee6cc83ee563a9 (patch)
treefc04015e0566e8c2a1fc94e78274bb2896941034 /src/world.c
parent68769abbf1c7b4ef4f03f93f0c50e016c709a167 (diff)
downloadserd-bf4f881c2241fa8ae6459bd9c8ee6cc83ee563a9.tar.gz
serd-bf4f881c2241fa8ae6459bd9c8ee6cc83ee563a9.tar.bz2
serd-bf4f881c2241fa8ae6459bd9c8ee6cc83ee563a9.zip
Move fopen wrapper to world
Diffstat (limited to 'src/world.c')
-rw-r--r--src/world.c28
1 files changed, 28 insertions, 0 deletions
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)