From 8f7cac4752d427f833969d316542d7a82b4602ea Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 29 May 2016 18:34:09 -0400 Subject: Fix handling of file I/O errors --- src/reader.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/reader.c') diff --git a/src/reader.c b/src/reader.c index e6af0b1c..5465dba6 100644 --- a/src/reader.c +++ b/src/reader.c @@ -87,6 +87,7 @@ struct SerdReaderImpl { bool paging; ///< True iff reading a page at a time bool strict; ///< True iff strict parsing bool eof; + bool error; bool seen_genid; #ifdef SERD_STACK_CHECK Ref* allocs; ///< Stack of push offsets @@ -115,7 +116,13 @@ page(SerdReader* reader) if (n_read == 0) { reader->file_buf[0] = '\0'; reader->eof = true; - return ferror(reader->fd) ? SERD_ERR_UNKNOWN : SERD_FAILURE; + if (ferror(reader->fd)) { + reader->error = true; + return r_err(reader, SERD_ERR_UNKNOWN, + "read error: %s\n", strerror(errno)); + } else { + return SERD_FAILURE; + } } else if (n_read < SERD_PAGE_SIZE) { reader->file_buf[n_read] = '\0'; } @@ -1446,7 +1453,7 @@ read_statement(SerdReader* reader) switch (peek_byte(reader)) { case '\0': reader->eof = true; - return true; + return !reader->error; case '@': TRY_RET(read_directive(reader)); read_ws_star(reader); @@ -1472,7 +1479,7 @@ read_turtleDoc(SerdReader* reader) while (!reader->eof) { TRY_RET(read_statement(reader)); } - return true; + return !reader->error; } SERD_API -- cgit v1.2.1