diff --git a/test/IXTest.cpp b/test/IXTest.cpp index d9c67599..cb289517 100644 --- a/test/IXTest.cpp +++ b/test/IXTest.cpp @@ -139,8 +139,10 @@ namespace ix std::streamoff size = file.tellg(); file.seekg(0, file.beg); - memblock.resize((size_t) size); - file.read((char*) &memblock.front(), static_cast(size)); + memblock.reserve((size_t) size); + memblock.insert(memblock.begin(), + std::istream_iterator(file), + std::istream_iterator()); return memblock; } diff --git a/third_party/cpp-linenoise/linenoise.cpp b/third_party/cpp-linenoise/linenoise.cpp index 56b02374..18522f5e 100644 --- a/third_party/cpp-linenoise/linenoise.cpp +++ b/third_party/cpp-linenoise/linenoise.cpp @@ -1639,7 +1639,10 @@ bool enableRawMode(int fd) { /* Init windows console handles only once */ hOut = GetStdHandle(STD_OUTPUT_HANDLE); - if (hOut==INVALID_HANDLE_VALUE) goto fatal; + if (hOut==INVALID_HANDLE_VALUE) { + errno = ENOTTY; + return false; + } } DWORD consolemodeOut; diff --git a/ws/ws.cpp b/ws/ws.cpp index fc64a60c..34e56d44 100644 --- a/ws/ws.cpp +++ b/ws/ws.cpp @@ -55,16 +55,18 @@ namespace std::pair> load(const std::string& path) { std::vector memblock; - std::ifstream file(path); + if (!file.is_open()) return std::make_pair(false, memblock); file.seekg(0, file.end); std::streamoff size = file.tellg(); file.seekg(0, file.beg); - memblock.resize((size_t) size); - file.read((char*) &memblock.front(), static_cast(size)); + memblock.reserve((size_t) size); + memblock.insert(memblock.begin(), + std::istream_iterator(file), + std::istream_iterator()); return std::make_pair(true, memblock); } @@ -86,9 +88,10 @@ namespace std::streamoff size = file.tellg(); file.seekg(0, file.beg); - memblock.resize(size); - - file.read((char*) &memblock.front(), static_cast(size)); + memblock.reserve((size_t) size); + memblock.insert(memblock.begin(), + std::istream_iterator(file), + std::istream_iterator()); std::string bytes(memblock.begin(), memblock.end()); return bytes;