aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/byte_source.c2
-rw-r--r--src/reader.c18
2 files changed, 12 insertions, 8 deletions
diff --git a/src/byte_source.c b/src/byte_source.c
index af73fbfe..588d258e 100644
--- a/src/byte_source.c
+++ b/src/byte_source.c
@@ -20,7 +20,7 @@ static inline SerdStatus
serd_byte_source_page(SerdByteSource* source)
{
source->read_head = 0;
- size_t n_read = source->read_func(
+ const size_t n_read = source->read_func(
source->file_buf, 1, source->page_size, source->stream);
if (n_read == 0) {
source->file_buf[0] = '\0';
diff --git a/src/reader.c b/src/reader.c
index 0ea95fcc..adb0a9ae 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -1811,18 +1811,19 @@ serd_reader_read_file(SerdReader* reader,
return ret;
}
-static bool
+static SerdStatus
skip_bom(SerdReader* me)
{
if (peek_byte(me) == 0xEF) {
eat_byte_safe(me, 0xEF);
if (eat_byte_check(me, 0xBB) != 0xBB ||
eat_byte_check(me, 0xBF) != 0xBF) {
- return r_err(me, SERD_ERR_BAD_SYNTAX, "corrupt byte order mark\n");
+ r_err(me, SERD_ERR_BAD_SYNTAX, "corrupt byte order mark\n");
+ return SERD_ERR_BAD_SYNTAX;
}
}
- return true;
+ return SERD_SUCCESS;
}
SERD_API
@@ -1860,11 +1861,14 @@ serd_reader_start_source_stream(SerdReader* me,
static SerdStatus
serd_reader_prepare(SerdReader* me)
{
- me->eof = false;
- if ((me->status = serd_byte_source_prepare(&me->source))) {
+ me->eof = false;
+ me->status = serd_byte_source_prepare(&me->source);
+ if (me->status == SERD_SUCCESS) {
+ me->status = skip_bom(me);
+ } else if (me->status == SERD_FAILURE) {
+ me->eof = true;
+ } else {
r_err(me, me->status, "read error: %s\n", strerror(errno));
- } else if (!skip_bom(me)) {
- me->status = SERD_ERR_BAD_SYNTAX;
}
return me->status;
}