From ce640e59fdcb178a906cf644f7d45be905e6356d Mon Sep 17 00:00:00 2001 From: John-Mark Bell Date: Sun, 11 Nov 2012 11:31:34 +0000 Subject: Report (and ignore) failure to load non-existent document. (Credit: Chris Young) --- utils/libdom.c | 13 +++++++------ utils/libdom.h | 3 ++- 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'utils') diff --git a/utils/libdom.c b/utils/libdom.c index 756465a02..ee911c3ff 100644 --- a/utils/libdom.c +++ b/utils/libdom.c @@ -259,7 +259,7 @@ static void ignore_dom_msg(uint32_t severity, void *ctx, const char *msg, ...) } /* exported interface documented in libdom.h */ -dom_document *libdom_parse_file(const char *filename, const char *encoding) +nserror libdom_parse_file(const char *filename, const char *encoding, dom_document **doc) { dom_hubbub_error error; dom_hubbub_parser *parser; @@ -270,14 +270,14 @@ dom_document *libdom_parse_file(const char *filename, const char *encoding) fp = fopen(filename, "r"); if (fp == NULL) { - return NULL; + return NSERROR_NOT_FOUND; } parser = dom_hubbub_parser_create(encoding, false, false, ignore_dom_msg, NULL, NULL, &document); if (parser == NULL) { fclose(fp); - return NULL; + return NSERROR_DOM; } while (feof(fp) == 0) { @@ -288,7 +288,7 @@ dom_document *libdom_parse_file(const char *filename, const char *encoding) dom_node_unref(document); dom_hubbub_parser_destroy(parser); fclose(fp); - return NULL; + return NSERROR_DOM; } } @@ -297,10 +297,11 @@ dom_document *libdom_parse_file(const char *filename, const char *encoding) dom_node_unref(document); dom_hubbub_parser_destroy(parser); fclose(fp); - return NULL; + return NSERROR_DOM; } dom_hubbub_parser_destroy(parser); - return document; + *doc = document; + return NSERROR_OK; } diff --git a/utils/libdom.h b/utils/libdom.h index f2da40570..d79c92d81 100644 --- a/utils/libdom.h +++ b/utils/libdom.h @@ -62,6 +62,7 @@ typedef bool (*libdom_iterate_cb)(dom_node *node, void *ctx); void libdom_iterate_child_elements(dom_node *parent, libdom_iterate_cb cb, void *ctx); -dom_document *libdom_parse_file(const char *filename, const char *encoding); +nserror libdom_parse_file(const char *filename, const char *encoding, + dom_document **doc); #endif -- cgit v1.2.3