diff options
author | Rob Richards <rrichards@php.net> | 2003-10-19 23:34:39 +0000 |
---|---|---|
committer | Rob Richards <rrichards@php.net> | 2003-10-19 23:34:39 +0000 |
commit | 56ce4a84e7ffb71e5439db805d0070ca9b3357ad (patch) | |
tree | 55a479990ee55502aee1ac34f541772776515ddd | |
parent | 33004a01eeb3f65ab65cdb67fe0dbad8e83f5d8d (diff) | |
download | php-git-56ce4a84e7ffb71e5439db805d0070ca9b3357ad.tar.gz |
add generic default error handling rather than the default stderr
-rw-r--r-- | ext/libxml/libxml.c | 24 |
1 files changed, 24 insertions, 0 deletions
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; } |