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 /src/utility.cc | |
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
Diffstat (limited to 'src/utility.cc')
-rw-r--r-- | src/utility.cc | 54 |
1 files changed, 0 insertions, 54 deletions
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; - } -} - -} |