diff --git a/Makefile.am b/Makefile.am index b8cbb4a..2cd345b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -31,17 +31,6 @@ libxml2_la_LDFLAGS = @CYGWIN_EXTRA_LDFLAGS@ @WIN32_EXTRA_LDFLAGS@ \ -version-info @LIBXML_VERSION_INFO@ \ @MODULE_PLATFORM_LIBS@ -if WITH_TRIO_SOURCES -libxml2_la_SOURCES = SAX.c entities.c encoding.c error.c parserInternals.c \ - parser.c tree.c hash.c list.c xmlIO.c xmlmemory.c uri.c \ - valid.c xlink.c HTMLparser.c HTMLtree.c debugXML.c xpath.c \ - xpointer.c xinclude.c nanohttp.c nanoftp.c DOCBparser.c \ - catalog.c globals.c threads.c c14n.c xmlstring.c \ - xmlregexp.c xmlschemas.c xmlschemastypes.c xmlunicode.c \ - triostr.c trio.c xmlreader.c relaxng.c dict.c SAX2.c \ - xmlwriter.c legacy.c chvalid.c pattern.c xmlsave.c \ - xmlmodule.c schematron.c -else libxml2_la_SOURCES = SAX.c entities.c encoding.c error.c parserInternals.c \ parser.c tree.c hash.c list.c xmlIO.c xmlmemory.c uri.c \ valid.c xlink.c HTMLparser.c HTMLtree.c debugXML.c xpath.c \ @@ -51,6 +40,8 @@ libxml2_la_SOURCES = SAX.c entities.c encoding.c error.c parserInternals.c \ xmlreader.c relaxng.c dict.c SAX2.c \ xmlwriter.c legacy.c chvalid.c pattern.c xmlsave.c \ xmlmodule.c schematron.c +if WITH_TRIO_SOURCES +libxml2_la_SOURCES += trio.c triostr.c endif DEPS = $(top_builddir)/libxml2.la diff --git a/configure.in b/configure.in index a1d2c89..346b7df 100644 --- a/configure.in +++ b/configure.in @@ -479,6 +479,25 @@ AC_CHECK_FUNCS(stat _stat signal) dnl Checking the standard string functions availability AC_CHECK_FUNCS(printf sprintf fprintf snprintf vfprintf vsprintf vsnprintf sscanf,, NEED_TRIO=1) +AC_CACHE_CHECK([if vsnprintf is POSIX compliant],[xml_cv_working_vsnprintf], +[xml_cv_working_vsnprintf=yes +AC_RUN_IFELSE([AC_LANG_PROGRAM([[#include +#include +static int printit(const char *format, ...) { +int retcode = 0; +va_list ap; +char buf[2]; +va_start(ap,format); +retcode = vsnprintf(buf,1,format,ap); +va_end(ap); +return retcode; +}]],[ +return printit("%s","hello") != 5; +])],,[xml_cv_working_vsnprintf=no])]) +if test "X$xml_cv_working_vsnprintf" = "Xno"; then + NEED_TRIO=1 + AC_DEFINE([BROKEN_VSNPRINTF],[1],[if vsnprintf does not work properly]) +fi dnl Checking for va_copy availability AC_MSG_CHECKING([for va_copy]) diff --git a/libxml.h b/libxml.h index dfc6c64..a78611a 100644 --- a/libxml.h +++ b/libxml.h @@ -51,6 +51,9 @@ int vfprintf(FILE *, const char *, va_list); */ #define TRIO_REPLACE_STDIO #include "trio.h" +#ifdef BROKEN_VSNPRINTF +#define vnsprintf trio_vsnprintf +#endif #endif /* diff --git a/xmlreader.c b/xmlreader.c index 97c71ab..1a491d2 100644 --- a/xmlreader.c +++ b/xmlreader.c @@ -4545,6 +4545,11 @@ xmlTextReaderBuildMessage(const char *msg, va_list ap) { char *str = NULL; va_list aq; + /* While it should work to call vsnprintf(NULL, it does not work + * on Solaris < 10, HP-UX, AIX 5.1, IRIX, or Tru64 Unix, so we + * allocate a string to start with */ + size = 64; + str = xmlMalloc(size); while (1) { VA_COPY(aq, ap); chars = vsnprintf(str, size, msg, aq);