diff options
author | Adrian Kummerländer | 2014-04-19 15:01:33 +0200 |
---|---|---|
committer | Adrian Kummerländer | 2014-04-19 15:01:33 +0200 |
commit | 334efe3383c436d61a8e5dd95b923cb0d5db9652 (patch) | |
tree | 591f2ab70e64fef5e74077000cfb010365fc5ce9 /src/utility.cc | |
parent | 6c205f4859588fc8dad786dce5f2fa32c75fd3f3 (diff) | |
download | InputXSLT-334efe3383c436d61a8e5dd95b923cb0d5db9652.tar InputXSLT-334efe3383c436d61a8e5dd95b923cb0d5db9652.tar.gz InputXSLT-334efe3383c436d61a8e5dd95b923cb0d5db9652.tar.bz2 InputXSLT-334efe3383c436d61a8e5dd95b923cb0d5db9652.tar.lz InputXSLT-334efe3383c436d61a8e5dd95b923cb0d5db9652.tar.xz InputXSLT-334efe3383c436d61a8e5dd95b923cb0d5db9652.tar.zst InputXSLT-334efe3383c436d61a8e5dd95b923cb0d5db9652.zip |
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
Diffstat (limited to 'src/utility.cc')
-rw-r--r-- | src/utility.cc | 54 |
1 files changed, 54 insertions, 0 deletions
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 <sys/stat.h> +#include <fcntl.h> +#include <unistd.h> + +#include <cstddef> +#include <cstdio> + +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<void*const>(buffer), + size + )); + + close(descriptor); + + std::string content( + buffer, + readSize + ); + + delete[] buffer; + + return content; + } +} + +} |