Read config into memory and pass its content to tinyxml2 (#253)

tinyxml2 does not support to read from a named pipe, since it uses seek to
figure out the file size. In the case of a pipe this is not possible.

Reading the file content into memory and passing the content to tinyxml2 allows
to mitigate this problem.
This commit is contained in:
Johannes Bornhold 2017-04-11 21:16:47 +02:00 committed by rfjakob
parent f75854cd31
commit 59378ae7fe

View File

@ -23,6 +23,8 @@
#include <algorithm> // for remove_if
#include <cstring> // for NULL
#include <memory> // for shared_ptr
#include <fstream> // for ifstream
#include <sstream> // for ostringstream
#include <tinyxml2.h> // for XMLElement, XMLNode, XMLDocument (ptr only)
@ -167,7 +169,12 @@ XmlReader::~XmlReader() {}
bool XmlReader::load(const char *fileName) {
pd->doc.reset(new tinyxml2::XMLDocument());
auto err = pd->doc->LoadFile(fileName);
std::ifstream in(fileName);
if (!in) return false;
std::ostringstream fileContent;
fileContent << in.rdbuf();
auto err = pd->doc->Parse(fileContent.str().c_str());
return err == tinyxml2::XML_SUCCESS;
}