diff options
author | Adrian Kummerländer | 2014-04-20 20:37:39 +0200 |
---|---|---|
committer | Adrian Kummerländer | 2014-04-20 20:37:39 +0200 |
commit | ab840f41154f01d85fec769da693035149689c39 (patch) | |
tree | cc758e40330b6ded5dad6690b4de680a81ea46a4 | |
parent | 29a9fb20b4c8414f2590886e43ae86794a53db89 (diff) | |
download | InputXSLT-ab840f41154f01d85fec769da693035149689c39.tar InputXSLT-ab840f41154f01d85fec769da693035149689c39.tar.gz InputXSLT-ab840f41154f01d85fec769da693035149689c39.tar.bz2 InputXSLT-ab840f41154f01d85fec769da693035149689c39.tar.lz InputXSLT-ab840f41154f01d85fec769da693035149689c39.tar.xz InputXSLT-ab840f41154f01d85fec769da693035149689c39.tar.zst InputXSLT-ab840f41154f01d85fec769da693035149689c39.zip |
Replaced c-style file reading with std::ifstream
* there is no reason for performing system-calls instead of using the features offered by the standard library in this situation
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/function/read_file.cc | 13 | ||||
-rw-r--r-- | src/utility.cc | 54 | ||||
-rw-r--r-- | src/utility.h | 15 |
4 files changed, 9 insertions, 74 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 4421841..c87ca68 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,6 @@ include_directories( add_executable( test test.cc - src/utility.cc src/transformer_facade.cc src/function/read_file.cc src/function/read_xml_file.cc diff --git a/src/function/read_file.cc b/src/function/read_file.cc index dcbff25..ea7a758 100644 --- a/src/function/read_file.cc +++ b/src/function/read_file.cc @@ -1,6 +1,6 @@ #include "read_file.h" -#include "utility.h" +#include <fstream> namespace InputXSLT { @@ -33,10 +33,15 @@ xalan::XObjectPtr FunctionReadFile::execute( fileName.end() ); + std::ifstream file(fileName); + + std::string content( + (std::istreambuf_iterator<char>(file)), + (std::istreambuf_iterator<char>()) + ); + return executionContext.getXObjectFactory().createString( - xalan::XalanDOMString( - InputXSLT::readFile(fileName).data() - ) + xalan::XalanDOMString(content.data()) ); } diff --git a/src/utility.cc b/src/utility.cc deleted file mode 100644 index fb6fe61..0000000 --- a/src/utility.cc +++ /dev/null @@ -1,54 +0,0 @@ -#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; - } -} - -} diff --git a/src/utility.h b/src/utility.h deleted file mode 100644 index ee39a25..0000000 --- a/src/utility.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef INPUTXSLT_SRC_UTILITY_H_ -#define INPUTXSLT_SRC_UTILITY_H_ - -#include <string> - -namespace xalanc_1_11 { } -namespace xalan = xalanc_1_11; - -namespace InputXSLT { - -std::string readFile(const std::string&); - -} - -#endif // INPUTXSLT_SRC_UTILITY_H_ |