With modes "w", "w+" and "w+b", I get XML_IO_FLUSH.
With the file open, I can successfully call fputs() and fclose() with proper, expected results.
BTW: I work around the problem using xmlDocDumpFormatMemory() and handling the file IO separate from libxml2.
EDIT: I was able to move beyond the original issue when calling setvbuf() using this code:
MSEXPORT int WriteXMLDocFile(xmlDocPtr doc, char* filename) // Write Doc to file
{
#include <stdio.h>
FILE* fp = fopen(filename, "w+");
if (fp == NULL) return -2;
#define BUFSIZE 1024
char buf[BUFSIZE];
int err = setvbuf(fp, buf, _IOFBF, BUFSIZE);
snprintf(dan, BUFSZ, "err = %d BUFSIZ = %d", err, BUFSIZE); DEBUG_MSG(dan);
int rtn_val = xmlDocDump(fp, doc);
snprintf(dan, BUFSZ, "size = %d", rtn_val); DEBUG_MSG(dan);
fclose(fp);
return rtn_val;
}
Though while it yields the expected length, crashes.
I was able to get around the issue by using xmlSaveFile()
instead of xmlDocDump()