From 334efe3383c436d61a8e5dd95b923cb0d5db9652 Mon Sep 17 00:00:00 2001 From: Adrian Kummerländer Date: Sat, 19 Apr 2014 15:01:33 +0200 Subject: Further code style fixes * .. in the face of the planned development of usable external functions using the current proof-of-concept coding * replaced usage of std::shared_ptr in FunctionReadXmlFile class with explicit implementation of default and copy constructor * separated implementation and interfaces --- src/utility.cc | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/utility.cc (limited to 'src/utility.cc') diff --git a/src/utility.cc b/src/utility.cc new file mode 100644 index 0000000..fb6fe61 --- /dev/null +++ b/src/utility.cc @@ -0,0 +1,54 @@ +#include "utility.h" + +#include +#include +#include + +#include +#include + +namespace { + +const int OpenFlags = O_RDONLY; +const mode_t OpenMode = S_IRUSR | S_IWUSR; + +} + +namespace InputXSLT { + +std::string readFile(const std::string& path) { + int descriptor( + open(path.data(), OpenFlags, OpenMode) + ); + + if ( descriptor == -1 ) { + close(descriptor); + + return "io error"; + } else { + struct stat info; + fstat(descriptor, &info); + const std::size_t size(info.st_size); + + char* const buffer(new char[size]); + + ssize_t readSize(read( + descriptor, + static_cast(buffer), + size + )); + + close(descriptor); + + std::string content( + buffer, + readSize + ); + + delete[] buffer; + + return content; + } +} + +} -- cgit v1.2.3