aboutsummaryrefslogtreecommitdiffstats
path: root/src/reader.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-12-11 22:11:22 +0000
committerDavid Robillard <d@drobilla.net>2011-12-11 22:11:22 +0000
commitea1936a594d7e4e656731223b76d355fc5431ef9 (patch)
tree87393e02793fba4cd44fb8da2db83f24380b509a /src/reader.c
parente08decb5992d6511e6896939a4cd9ad157831b78 (diff)
downloadserd-ea1936a594d7e4e656731223b76d355fc5431ef9.tar.gz
serd-ea1936a594d7e4e656731223b76d355fc5431ef9.tar.bz2
serd-ea1936a594d7e4e656731223b76d355fc5431ef9.zip
Move all #ifdef gunk to serd_internal.h.
Centralise file open and buffer allocation to localize platform tweaks. git-svn-id: http://svn.drobilla.net/serd/trunk@244 490d8e77-9747-427b-9fa3-0b8f29cee8a0
Diffstat (limited to 'src/reader.c')
-rw-r--r--src/reader.c21
1 files changed, 3 insertions, 18 deletions
diff --git a/src/reader.c b/src/reader.c
index 68b5446d..a1ff0d1c 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -14,7 +14,7 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#define _POSIX_C_SOURCE 201112L /* for posix_memalign */
+#include "serd_internal.h"
#include <assert.h>
#include <errno.h>
@@ -25,13 +25,6 @@
#include <stdlib.h>
#include <string.h>
-#if defined(HAVE_POSIX_FADVISE) && defined(HAVE_FILENO)
-# include <fcntl.h>
-#endif
-
-#include "serd_internal.h"
-#include "serd-config.h"
-
#define NS_XSD "http://www.w3.org/2001/XMLSchema#"
#define NS_RDF "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
@@ -1516,14 +1509,10 @@ serd_reader_read_file(SerdReader* reader,
return SERD_ERR_BAD_ARG;
}
- FILE* fd = fopen((const char*)path, "r");
+ FILE* fd = serd_fopen((const char*)path, "r");
if (!fd) {
- fprintf(stderr, "Error opening file %s (%s)\n", path, strerror(errno));
return SERD_ERR_UNKNOWN;
}
-#if defined(HAVE_POSIX_FADVISE) && defined(HAVE_FILENO)
- posix_fadvise(fileno(fd), 0, 0, POSIX_FADV_SEQUENTIAL);
-#endif
SerdStatus ret = serd_reader_read_file_handle(reader, fd, path);
fclose(fd);
@@ -1540,11 +1529,7 @@ serd_reader_read_file_handle(SerdReader* me, FILE* file, const uint8_t* name)
me->cur = cur;
me->from_file = true;
me->eof = false;
-#ifdef HAVE_POSIX_MEMALIGN
- posix_memalign((void**)&me->read_buf, 4096, SERD_PAGE_SIZE * 2);
-#else
- me->read_buf = (uint8_t*)malloc(SERD_PAGE_SIZE * 2);
-#endif
+ me->read_buf = serd_bufalloc(SERD_PAGE_SIZE * 2);
/* Read into the second page of the buffer. Occasionally peek_string
will move the read_head to before this point when readahead causes