fix output bug reported by Petr Pajas and analyzed by Bill Daniel

* xmlIO.c: fix output bug reported by Petr Pajas and analyzed by Bill
Daniel

svn path=/trunk/; revision=3695
diff --git a/xmlIO.c b/xmlIO.c
index 7782776..dd4f7e7 100644
--- a/xmlIO.c
+++ b/xmlIO.c
@@ -3315,6 +3315,16 @@
 	cons = len;
 	chunk = (out->buffer->size - out->buffer->use) - 1;
 
+        /*
+	 * make sure we have enough room to save first, if this is
+	 * not the case force a flush, but make sure we stay in the loop
+	 */
+	if (chunk < 40) {
+	    nbchars = 0;
+	    oldwritten = -1;
+	    goto flush;
+	}
+
 	/*
 	 * first handle encoding stuff.
 	 */
@@ -3360,6 +3370,7 @@
 	if ((nbchars < MINLEN) && (len <= 0))
 	    goto done;
 
+flush:
 	if (out->writecallback) {
 	    /*
 	     * second write the stuff to the I/O channel