From 5d73ff3a0b529954e5192f892c21a4ad068905c9 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 3 Mar 2012 01:47:50 +0000 Subject: Fix reading of empty files (e.g. /dev/null) test case. git-svn-id: http://svn.drobilla.net/serd/trunk@328 490d8e77-9747-427b-9fa3-0b8f29cee8a0 --- src/reader.c | 14 +++++++------- src/serdi.c | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/reader.c b/src/reader.c index 41e0fb7d..333aabde 100644 --- a/src/reader.c +++ b/src/reader.c @@ -98,7 +98,7 @@ error(SerdReader* reader, const char* fmt, ...) return 0; } -static inline bool +static inline SerdStatus page(SerdReader* reader) { reader->read_head = 0; @@ -106,11 +106,11 @@ page(SerdReader* reader) if (n_read == 0) { reader->read_buf[0] = '\0'; reader->eof = true; - return false; + return ferror(reader->fd) ? SERD_ERR_UNKNOWN : SERD_FAILURE; } else if (n_read < SERD_PAGE_SIZE) { reader->read_buf[n_read] = '\0'; } - return true; + return SERD_SUCCESS; } static inline uint8_t @@ -1461,16 +1461,16 @@ serd_reader_read_file_handle(SerdReader* me, FILE* file, const uint8_t* name) memset(me->read_buf, '\0', SERD_PAGE_SIZE); - bool ret = page(me); - if (ret) { + SerdStatus st = page(me); + if (!st) { skip_bom(me); - ret = read_turtleDoc(me); + st = read_turtleDoc(me) ? SERD_SUCCESS : SERD_ERR_UNKNOWN; } free(me->read_buf); me->fd = 0; me->read_buf = NULL; - return ret ? SERD_SUCCESS : SERD_ERR_UNKNOWN; + return st; } SERD_API diff --git a/src/serdi.c b/src/serdi.c index 63822e94..661b60e0 100644 --- a/src/serdi.c +++ b/src/serdi.c @@ -215,5 +215,5 @@ main(int argc, char** argv) serd_env_free(env); serd_node_free(&base_uri_node); - return (status == SERD_SUCCESS) ? 0 : 1; + return (status > SERD_FAILURE) ? 1 : 0; } -- cgit v1.2.1