diff options
author | Oleg Morozenkov <m@oleg.rocks> | 2018-03-10 15:17:40 +0300 |
---|---|---|
committer | Oleg Morozenkov <m@oleg.rocks> | 2018-03-10 15:17:40 +0300 |
commit | f26e8402cf886fbb49ef7047024d40b3fc2bfe17 (patch) | |
tree | 31e38fa9a2ccefae50bc558e25bad4a98a87c8bf /src/tools | |
parent | 6f8c497df3c45fac58d0da0af8ca1e98f6bf2ed3 (diff) |
Fixes #55
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/FileTools.cpp | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/src/tools/FileTools.cpp b/src/tools/FileTools.cpp index 14c322c..105d80f 100644 --- a/src/tools/FileTools.cpp +++ b/src/tools/FileTools.cpp @@ -11,25 +11,25 @@ using namespace std; namespace FileTools { -std::string read(const std::string& filePath) { +string read(const string& filePath) { ifstream in(filePath, ios::in | ios::binary); - if (in) { - ostringstream contents; - contents << in.rdbuf(); - in.close(); - return contents.str(); + if (!in) { + throw system_error(errno, system_category()); } - throw errno; + ostringstream contents; + contents << in.rdbuf(); + in.close(); + return contents.str(); } -bool write(const std::string& content, const std::string& filePath) { +bool write(const string& content, const string& filePath) { ofstream out(filePath, ios::out | ios::binary); - if (out) { - out << content; - out.close(); - return true; + if (!out) { + return false; } - return false; + out << content; + out.close(); + return true; } }; |