~ubuntu-branches/ubuntu/trusty/manaplus/trusty

« back to all changes in this revision

Viewing changes to src/utils/xml.cpp

  • Committer: Package Import Robot
  • Author(s): Patrick Matthäi
  • Date: 2013-11-18 15:19:44 UTC
  • mfrom: (1.1.14)
  • Revision ID: package-import@ubuntu.com-20131118151944-iyd93ut2rmxzp8gg
Tags: 1.3.11.10-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
 
35
35
#include "debug.h"
36
36
 
37
 
static void xmlNullLogger(void *ctx A_UNUSED, const char *msg A_UNUSED, ...)
 
37
static void xmlErrorLogger(void *ctx A_UNUSED, const char *msg A_UNUSED, ...)
 
38
#ifdef __GNUC__
 
39
#ifdef __OpenBSD__
 
40
    __attribute__((__format__(printf, 2, 3)))
 
41
#else
 
42
    __attribute__((__format__(gnu_printf, 2, 3)))
 
43
#endif
 
44
#endif
 
45
;
 
46
 
 
47
static void xmlErrorLogger(void *ctx A_UNUSED, const char *msg, ...)
38
48
{
39
 
    // Does nothing, that's the whole point of it
 
49
    unsigned size = 1024;
 
50
    const unsigned msgSize = strlen(msg);
 
51
    if (msgSize * 3 > size)
 
52
        size = static_cast<unsigned>(msgSize * 3);
 
53
 
 
54
    char* buf = new char[size + 1];
 
55
    va_list ap;
 
56
 
 
57
    // Use a temporary buffer to fill in the variables
 
58
    va_start(ap, msg);
 
59
    vsnprintf(buf, size, msg, ap);
 
60
    buf[size] = 0;
 
61
    va_end(ap);
 
62
 
 
63
    if (logger)
 
64
        logger->log1(buf);
 
65
    else
 
66
        puts(buf);
 
67
 
 
68
    // Delete temporary buffer
 
69
    delete [] buf;
40
70
}
41
71
 
42
72
namespace XML
213
243
        LIBXML_TEST_VERSION;
214
244
 
215
245
        // Suppress libxml2 error messages
216
 
        xmlSetGenericErrorFunc(nullptr, &xmlNullLogger);
 
246
        xmlSetGenericErrorFunc(nullptr, &xmlErrorLogger);
217
247
    }
218
248
 
219
249
    // Shutdown libxml