aboutsummaryrefslogtreecommitdiffstats
path: root/src/serd_internal.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/serd_internal.h')
-rw-r--r--src/serd_internal.h22
1 files changed, 10 insertions, 12 deletions
diff --git a/src/serd_internal.h b/src/serd_internal.h
index 601af56c..9200776d 100644
--- a/src/serd_internal.h
+++ b/src/serd_internal.h
@@ -29,7 +29,7 @@
#include "world.h"
-#if defined(HAVE_POSIX_FADVISE) && defined(HAVE_FILENO)
+#if defined(HAVE_FILENO)
# include <fcntl.h>
#endif
@@ -42,19 +42,17 @@
# define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif
-static inline FILE*
-serd_fopen(const char* path, const char* mode)
+/** fread-like wrapper for getc (which is faster). */
+static inline size_t
+serd_file_read_byte(void* buf, size_t size, size_t nmemb, void* stream)
{
- FILE* fd = fopen(path, mode);
- if (!fd) {
- fprintf(stderr, "error: failed to open file %s (%s)\n",
- path, strerror(errno));
- return NULL;
+ const int c = getc((FILE*)stream);
+ if (c == EOF) {
+ *((uint8_t*)buf) = 0;
+ return 0;
}
-#if defined(HAVE_POSIX_FADVISE) && defined(HAVE_FILENO)
- posix_fadvise(fileno(fd), 0, 0, POSIX_FADV_SEQUENTIAL);
-#endif
- return fd;
+ *((uint8_t*)buf) = (uint8_t)c;
+ return 1;
}
static inline void*