From: Rob Richards Date: Sun, 19 Oct 2003 23:34:39 +0000 (+0000) Subject: add generic default error handling rather than the default stderr X-Git-Tag: RELEASE_1_3b3~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=56ce4a84e7ffb71e5439db805d0070ca9b3357ad;p=php add generic default error handling rather than the default stderr --- diff --git a/ext/libxml/libxml.c b/ext/libxml/libxml.c index 480680e21a..984cc2fc81 100644 --- a/ext/libxml/libxml.c +++ b/ext/libxml/libxml.c @@ -146,6 +146,25 @@ int php_libxml_streams_IO_close(void *context) return php_stream_close((php_stream*)context); } +static void php_libxml_error_handler(void *ctx, const char *msg, ...) +{ + va_list ap; + char *buf; + int len; + + va_start(ap, msg); + len = vspprintf(&buf, 0, msg, ap); + va_end(ap); + + /* remove any trailing \n */ + while (len && buf[--len] == '\n') { + buf[len] = '\0'; + } + + php_error(E_WARNING, "%s", buf); + efree(buf); +} + PHP_LIBXML_API void php_libxml_initialize() { if (!_php_libxml_initialized) { /* we should be the only one's to ever init!! */ @@ -167,12 +186,17 @@ PHP_LIBXML_API void php_libxml_initialize() { php_libxml_streams_IO_write, php_libxml_streams_IO_close); + /* report errors via handler rather than stderr */ + xmlSetGenericErrorFunc(NULL, php_libxml_error_handler); + _php_libxml_initialized = 1; } } PHP_LIBXML_API void php_libxml_shutdown() { if (_php_libxml_initialized) { + /* reset libxml generic error handling */ + xmlSetGenericErrorFunc(NULL, NULL); xmlCleanupParser(); _php_libxml_initialized = 0; }