mingw: fix compile errors with linenoise and fstream

This commit is contained in:
Benjamin Sergeant 2021-03-19 11:18:55 -07:00
parent b36a2d1faa
commit 48166a9a72
3 changed files with 17 additions and 9 deletions

View File

@ -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<std::streamsize>(size));
memblock.reserve((size_t) size);
memblock.insert(memblock.begin(),
std::istream_iterator<char>(file),
std::istream_iterator<char>());
return memblock;
}

View File

@ -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;

View File

@ -55,16 +55,18 @@ namespace
std::pair<bool, std::vector<uint8_t>> load(const std::string& path)
{
std::vector<uint8_t> 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<std::streamsize>(size));
memblock.reserve((size_t) size);
memblock.insert(memblock.begin(),
std::istream_iterator<char>(file),
std::istream_iterator<char>());
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<std::streamsize>(size));
memblock.reserve((size_t) size);
memblock.insert(memblock.begin(),
std::istream_iterator<char>(file),
std::istream_iterator<char>());
std::string bytes(memblock.begin(), memblock.end());
return bytes;