X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=tests%2Futils%2Fxml-utils%2Fpretty_xml.cpp;fp=tests%2Futils%2Fxml-utils%2Fpretty_xml.cpp;h=8a6e967a71da8c73c687fcf6c3cec23d88ce4fad;hb=f59edc7cf8bfcf1450ce2d9e649f70c1e6796da0;hp=7eb4710caf78dcc02c285800a4af02a57b48718a;hpb=0e9cf259c6e7f66b48c07365dca15903cd352164;p=lttng-tools.git diff --git a/tests/utils/xml-utils/pretty_xml.cpp b/tests/utils/xml-utils/pretty_xml.cpp index 7eb4710ca..8a6e967a7 100644 --- a/tests/utils/xml-utils/pretty_xml.cpp +++ b/tests/utils/xml-utils/pretty_xml.cpp @@ -12,34 +12,28 @@ #include "common.hpp" +#include + +#include #include #include +namespace ll = lttng::libxml; + int main() { - xmlDocPtr doc = NULL; - - /* Init libxml. */ - xmlInitParser(); - - { - xml_parser_ctx_uptr parserCtx{ xmlNewParserCtxt() }; - - /* Parse the XML document from stdin. */ - doc = xmlCtxtReadFd( - parserCtx.get(), STDIN_FILENO, nullptr, nullptr, XML_PARSE_NOBLANKS); - if (!doc) { - fprintf(stderr, "ERR parsing: xml input invalid"); - return -1; - } - - xmlDocFormatDump(stdout, doc, 1); - - xmlFreeDoc(doc); + const ll::global_parser_context global_parser_context; + const ll::parser_ctx_uptr parserCtx{ xmlNewParserCtxt() }; + + /* Parse the XML document from stdin. */ + const ll::doc_uptr doc{ xmlCtxtReadFd( + parserCtx.get(), STDIN_FILENO, nullptr, nullptr, XML_PARSE_NOBLANKS) }; + if (!doc) { + std::cerr << "Error: invalid XML input on stdin\n"; + return -1; } - /* Shutdown libxml. */ - xmlCleanupParser(); + xmlDocFormatDump(stdout, doc.get(), 1); return 0; }