From 828ce83d4c4110bf6eb0f19463900de24da7dac9 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Wed, 8 Oct 2003 19:19:10 +0000 Subject: [PATCH] more cleanup through the I/O error path Daniel * error.c tree.c xmlIO.c xmllint.c: more cleanup through the I/O error path Daniel --- ChangeLog | 5 +++++ error.c | 9 +++++++-- tree.c | 2 +- xmlIO.c | 17 ++++++++++------- xmllint.c | 3 ++- 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 88415747..809e0a24 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Wed Oct 8 21:18:12 CEST 2003 Daniel Veillard + + * error.c tree.c xmlIO.c xmllint.c: more cleanup through the + I/O error path + Wed Oct 8 20:57:27 CEST 2003 Daniel Veillard * xmlIO.c: better handling of error cases diff --git a/error.c b/error.c index c9963658..b5d5fc31 100644 --- a/error.c +++ b/error.c @@ -350,9 +350,14 @@ xmlReportError(xmlErrorPtr err, xmlParserCtxtPtr ctxt, const char *str, if (code == XML_ERR_OK) return; if (str != NULL) { - channel(data, "%s", str); + int len; + len = xmlStrlen((const xmlChar *)str); + if ((len > 0) && (str[len - 1] != '\n')) + channel(data, "%s", str); + else + channel(data, "%s\n", str); } else { - channel(data, "%s", "out of memory error"); + channel(data, "%s\n", "out of memory error"); } if (code == XML_ERR_OK) return; diff --git a/tree.c b/tree.c index b0f55f98..e360c128 100644 --- a/tree.c +++ b/tree.c @@ -8346,7 +8346,7 @@ xmlDocFormatDump(FILE *f, xmlDocPtr cur, int format) { */ int xmlDocDump(FILE *f, xmlDocPtr cur) { - return(xmlDocFormatDump (f, cur, 0)); + return(xmlDocFormatDump (f, cur, 0)); } /** diff --git a/xmlIO.c b/xmlIO.c index 2a353847..ae4aa08a 100644 --- a/xmlIO.c +++ b/xmlIO.c @@ -1974,32 +1974,35 @@ xmlFreeParserInputBuffer(xmlParserInputBufferPtr in) { * Returns the number of byte written or -1 in case of error. */ int -xmlOutputBufferClose(xmlOutputBufferPtr out) { +xmlOutputBufferClose(xmlOutputBufferPtr out) +{ int written; int err_rc = 0; if (out == NULL) - return(-1); + return (-1); if (out->writecallback != NULL) - xmlOutputBufferFlush(out); + xmlOutputBufferFlush(out); if (out->closecallback != NULL) { - err_rc = out->closecallback(out->context); + err_rc = out->closecallback(out->context); } written = out->written; if (out->conv) { xmlBufferFree(out->conv); - out->conv = NULL; + out->conv = NULL; } if (out->encoder != NULL) { xmlCharEncCloseFunc(out->encoder); } if (out->buffer != NULL) { xmlBufferFree(out->buffer); - out->buffer = NULL; + out->buffer = NULL; } + if (out->error) + err_rc = -1; xmlFree(out); - return( ( err_rc == 0 ) ? written : err_rc ); + return ((err_rc == 0) ? written : err_rc); } #endif /* LIBXML_OUTPUT_ENABLED */ diff --git a/xmllint.c b/xmllint.c index a6080992..81c2ea58 100644 --- a/xmllint.c +++ b/xmllint.c @@ -1066,7 +1066,8 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { out = fopen(output,"wb"); } if (out != NULL) { - xmlDocDump(out, doc); + if (xmlDocDump(out, doc) < 0) + progresult = 6; if (output != NULL) fclose(out);