aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-11-13 10:52:56 +0100
committerDavid Robillard <d@drobilla.net>2021-03-08 23:23:05 -0500
commitfd276bcf70bad4520ca1d6f3c73f88073b3b58cf (patch)
treeaf2c60324c119f78f85bba30cdb5223d9dcf10c0 /src
parenta4f6754a4048f2bcb04482938d5a98e9ab77d4fc (diff)
downloadserd-fd276bcf70bad4520ca1d6f3c73f88073b3b58cf.tar.gz
serd-fd276bcf70bad4520ca1d6f3c73f88073b3b58cf.tar.bz2
serd-fd276bcf70bad4520ca1d6f3c73f88073b3b58cf.zip
Move fopen wrapper to world
Diffstat (limited to 'src')
-rw-r--r--src/reader.c4
-rw-r--r--src/system.c24
-rw-r--r--src/system.h4
-rw-r--r--src/world.c28
-rw-r--r--src/world.h6
5 files changed, 37 insertions, 29 deletions
diff --git a/src/reader.c b/src/reader.c
index cfc43685..3be28a53 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -15,9 +15,9 @@
*/
#include "reader.h"
+
#include "byte_source.h"
#include "serd_internal.h"
-#include "stack.h"
#include "system.h"
#include "world.h"
@@ -260,7 +260,7 @@ serd_reader_start_file(SerdReader* reader, const char* uri, bool bulk)
return SERD_ERR_BAD_ARG;
}
- FILE* fd = serd_fopen(path, "rb");
+ FILE* fd = serd_world_fopen(reader->world, path, "rb");
free(path);
if (!fd) {
return SERD_ERR_UNKNOWN;
diff --git a/src/system.c b/src/system.c
index 6bc93ca6..4f6c37c6 100644
--- a/src/system.c
+++ b/src/system.c
@@ -14,41 +14,19 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#define _POSIX_C_SOURCE 200809L /* for posix_memalign and posix_fadvise */
+#define _POSIX_C_SOURCE 200809L /* for posix_memalign */
#include "system.h"
#include "serd_config.h"
#include "serd_internal.h"
-#if USE_POSIX_FADVISE && USE_FILENO
-# include <fcntl.h>
-#endif
-
#ifdef _WIN32
# include <malloc.h>
#endif
-#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
-#include <string.h>
-
-FILE*
-serd_fopen(const char* path, const char* 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
- 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 66546d6e..a5fb7459 100644
--- a/src/system.h
+++ b/src/system.h
@@ -22,10 +22,6 @@
#include <stdint.h>
#include <stdio.h>
-/// 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_I_MALLOC_FUNC
void*
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)
diff --git a/src/world.h b/src/world.h
index 08c351fe..ab7aad80 100644
--- a/src/world.h
+++ b/src/world.h
@@ -19,11 +19,17 @@
#include "serd/serd.h"
+#include <stdio.h>
+
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);