summaryrefslogtreecommitdiff
path: root/xmlwriter.c
diff options
context:
space:
mode:
Diffstat (limited to 'xmlwriter.c')
-rw-r--r--xmlwriter.c75
1 files changed, 31 insertions, 44 deletions
diff --git a/xmlwriter.c b/xmlwriter.c
index 6227398..37b7945 100644
--- a/xmlwriter.c
+++ b/xmlwriter.c
@@ -25,6 +25,25 @@
#define B64CRLF "\r\n"
/*
+ * The following VA_COPY was coded following an example in
+ * the Samba project. It may not be sufficient for some
+ * esoteric implementations of va_list (i.e. it may need
+ * something involving a memcpy) but (hopefully) will be
+ * sufficient for libxml2.
+ */
+#ifndef VA_COPY
+ #ifdef HAVE_VA_COPY
+ #define VA_COPY(dest, src) va_copy(dest, src)
+ #else
+ #ifdef HAVE___VA_COPY
+ #define VA_COPY(dest,src) __va_copy(dest, src)
+ #else
+ #define VA_COPY(dest,src) (dest) = (src)
+ #endif
+ #endif
+#endif
+
+/*
* Types are kept private
*/
typedef enum {
@@ -80,9 +99,6 @@ static int xmlCmpTextWriterStackEntry(const void *data0,
static void xmlFreeTextWriterNsStackEntry(xmlLinkPtr lk);
static int xmlCmpTextWriterNsStackEntry(const void *data0,
const void *data1);
-static int xmlTextWriterWriteMemCallback(void *context,
- const xmlChar * str, int len);
-static int xmlTextWriterCloseMemCallback(void *context);
static int xmlTextWriterWriteDocCallback(void *context,
const xmlChar * str, int len);
static int xmlTextWriterCloseDocCallback(void *context);
@@ -256,11 +272,8 @@ xmlNewTextWriterMemory(xmlBufferPtr buf, int compression ATTRIBUTE_UNUSED)
xmlOutputBufferPtr out;
/*::todo handle compression */
- out = xmlOutputBufferCreateIO((xmlOutputWriteCallback)
- xmlTextWriterWriteMemCallback,
- (xmlOutputCloseCallback)
- xmlTextWriterCloseMemCallback,
- (void *) buf, NULL);
+ out = xmlOutputBufferCreateBuffer(buf, NULL);
+
if (out == NULL) {
xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
"xmlNewTextWriterMemory : out of memory!\n");
@@ -2842,8 +2855,11 @@ xmlTextWriterStartDTD(xmlTextWriterPtr writer,
if (count < 0)
return -1;
sum += count;
- } else if (writer->indent) {
+ } else {
+ if (writer->indent)
count = xmlOutputBufferWriteString(writer->out, "\n ");
+ else
+ count = xmlOutputBufferWrite(writer->out, 1, " ");
if (count < 0)
return -1;
sum += count;
@@ -4275,40 +4291,6 @@ xmlCmpTextWriterNsStackEntry(const void *data0, const void *data1)
}
/**
- * xmlTextWriterWriteMemCallback:
- * @context: the xmlBufferPtr
- * @str: the data to write
- * @len: the length of the data
- *
- * Write callback for the xmlOutputBuffer with target xmlBuffer
- *
- * Returns -1, 0, 1
- */
-static int
-xmlTextWriterWriteMemCallback(void *context, const xmlChar * str, int len)
-{
- xmlBufferPtr buf = (xmlBufferPtr) context;
-
- xmlBufferAdd(buf, str, len);
-
- return len;
-}
-
-/**
- * xmlTextWriterCloseMemCallback:
- * @context: the xmlBufferPtr
- *
- * Close callback for the xmlOutputBuffer with target xmlBuffer
- *
- * Returns -1, 0, 1
- */
-static int
-xmlTextWriterCloseMemCallback(void *context ATTRIBUTE_UNUSED)
-{
- return 0;
-}
-
-/**
* xmlTextWriterWriteDocCallback:
* @context: the xmlBufferPtr
* @str: the data to write
@@ -4373,6 +4355,7 @@ xmlTextWriterVSprintf(const char *format, va_list argptr)
int size;
int count;
xmlChar *buf;
+ va_list locarg;
size = BUFSIZ;
buf = (xmlChar *) xmlMalloc(size);
@@ -4382,8 +4365,10 @@ xmlTextWriterVSprintf(const char *format, va_list argptr)
return NULL;
}
- while (((count = vsnprintf((char *) buf, size, format, argptr)) < 0)
+ VA_COPY(locarg, argptr);
+ while (((count = vsnprintf((char *) buf, size, format, locarg)) < 0)
|| (count == size - 1) || (count == size) || (count > size)) {
+ va_end(locarg);
xmlFree(buf);
size += BUFSIZ;
buf = (xmlChar *) xmlMalloc(size);
@@ -4392,7 +4377,9 @@ xmlTextWriterVSprintf(const char *format, va_list argptr)
"xmlTextWriterVSprintf : out of memory!\n");
return NULL;
}
+ VA_COPY(locarg, argptr);
}
+ va_end(locarg);
return buf;
}