summaryrefslogtreecommitdiff
path: root/xmlsave.c
diff options
context:
space:
mode:
authorMike Hommey <mh@glandium.org>2004-11-11 12:53:54 +0000
committerMike Hommey <mh@glandium.org>2004-11-11 12:53:54 +0000
commitf51dd67f3a3f472af0620391eb588eeca4533689 (patch)
tree9184c396c489196608427d5fa35814e86a1e479f /xmlsave.c
parent9705f1a5e858108d21a0128556f42b25d16833cd (diff)
downloadlibxml2-f51dd67f3a3f472af0620391eb588eeca4533689.tar.gz
Load /tmp/tmp.n9GTkp/libxml2-2.6.16 intoupstream/2.6.16
packages/libxml2/branches/upstream/current.
Diffstat (limited to 'xmlsave.c')
-rw-r--r--xmlsave.c33
1 files changed, 28 insertions, 5 deletions
diff --git a/xmlsave.c b/xmlsave.c
index 398f62a..72ad699 100644
--- a/xmlsave.c
+++ b/xmlsave.c
@@ -445,6 +445,7 @@ xhtmlNodeDumpOutput(xmlSaveCtxtPtr ctxt, xmlNodePtr cur);
static void xmlNodeListDumpOutput(xmlSaveCtxtPtr ctxt, xmlNodePtr cur);
static void xmlNodeDumpOutputInternal(xmlSaveCtxtPtr ctxt, xmlNodePtr cur);
void xmlNsListDumpOutput(xmlOutputBufferPtr buf, xmlNsPtr cur);
+static void xmlDocContentDumpOutput(xmlSaveCtxtPtr ctxt, xmlDocPtr cur);
/**
* xmlNsDumpOutput:
@@ -456,7 +457,7 @@ void xmlNsListDumpOutput(xmlOutputBufferPtr buf, xmlNsPtr cur);
*/
static void
xmlNsDumpOutput(xmlOutputBufferPtr buf, xmlNsPtr cur) {
- if (cur == NULL) return;
+ if ((cur == NULL) || (buf == NULL)) return;
if ((cur->type == XML_LOCAL_NAMESPACE) && (cur->href != NULL)) {
if (xmlStrEqual(cur->prefix, BAD_CAST "xml"))
return;
@@ -557,6 +558,7 @@ xmlAttrDumpOutput(xmlSaveCtxtPtr ctxt, xmlAttrPtr cur) {
if (cur == NULL) return;
buf = ctxt->buf;
+ if (buf == NULL) return;
xmlOutputBufferWrite(buf, 1, " ");
if ((cur->ns != NULL) && (cur->ns->prefix != NULL)) {
xmlOutputBufferWriteString(buf, (const char *)cur->ns->prefix);
@@ -634,6 +636,11 @@ xmlNodeDumpOutputInternal(xmlSaveCtxtPtr ctxt, xmlNodePtr cur) {
return;
if (cur->type == XML_XINCLUDE_END)
return;
+ if ((cur->type == XML_DOCUMENT_NODE) ||
+ (cur->type == XML_HTML_DOCUMENT_NODE)) {
+ xmlDocContentDumpOutput(ctxt, (xmlDocPtr) cur);
+ return;
+ }
if (cur->type == XML_DTD_NODE) {
xmlDtdDumpOutput(ctxt, (xmlDtdPtr) cur);
return;
@@ -1429,6 +1436,7 @@ xmlSaveDoc(xmlSaveCtxtPtr ctxt, xmlDocPtr doc)
{
long ret = 0;
+ if ((ctxt == NULL) || (doc == NULL)) return(-1);
xmlDocContentDumpOutput(ctxt, doc);
return(ret);
}
@@ -1449,6 +1457,7 @@ xmlSaveTree(xmlSaveCtxtPtr ctxt, xmlNodePtr node)
{
long ret = 0;
+ if ((ctxt == NULL) || (node == NULL)) return(-1);
xmlNodeDumpOutputInternal(ctxt, node);
return(ret);
}
@@ -1790,6 +1799,8 @@ xmlNodeDumpOutput(xmlOutputBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur,
xmlInitParser();
+ if ((buf == NULL) || (cur == NULL)) return;
+
memset(&ctxt, 0, sizeof(ctxt));
ctxt.doc = doc;
ctxt.buf = buf;
@@ -2035,6 +2046,8 @@ xmlDocDump(FILE *f, xmlDocPtr cur) {
* @encoding: the encoding if any assuming the I/O layer handles the trancoding
*
* Dump an XML document to an I/O buffer.
+ * Warning ! This call xmlOutputBufferClose() on buf which is not available
+ * after this call.
*
* returns: the number of bytes written or -1 in case of failure.
*/
@@ -2043,7 +2056,11 @@ xmlSaveFileTo(xmlOutputBufferPtr buf, xmlDocPtr cur, const char *encoding) {
xmlSaveCtxt ctxt;
int ret;
- if (buf == NULL) return(0);
+ if (buf == NULL) return(-1);
+ if (cur == NULL) {
+ xmlOutputBufferClose(buf);
+ return(-1);
+ }
memset(&ctxt, 0, sizeof(ctxt));
ctxt.doc = cur;
ctxt.buf = buf;
@@ -2064,7 +2081,8 @@ xmlSaveFileTo(xmlOutputBufferPtr buf, xmlDocPtr cur, const char *encoding) {
* @format: should formatting spaces been added
*
* Dump an XML document to an I/O buffer.
- * NOTE: the I/O buffer is closed as part of the call.
+ * Warning ! This call xmlOutputBufferClose() on buf which is not available
+ * after this call.
*
* returns: the number of bytes written or -1 in case of failure.
*/
@@ -2075,8 +2093,13 @@ xmlSaveFormatFileTo(xmlOutputBufferPtr buf, xmlDocPtr cur,
xmlSaveCtxt ctxt;
int ret;
- if (buf == NULL)
- return (0);
+ if (buf == NULL) return(-1);
+ if ((cur == NULL) ||
+ ((cur->type != XML_DOCUMENT_NODE) &&
+ (cur->type != XML_HTML_DOCUMENT_NODE))) {
+ xmlOutputBufferClose(buf);
+ return(-1);
+ }
memset(&ctxt, 0, sizeof(ctxt));
ctxt.doc = cur;
ctxt.buf = buf;