fix a bug of reading CRLF file on win32

This commit is contained in:
blueloveTH 2023-09-18 23:00:43 +08:00
parent e9b4734004
commit bd351b055f
2 changed files with 6 additions and 0 deletions

View File

@ -1,3 +1,6 @@
if (Test-Path build) {
Remove-Item -Recurse -Force build
}
mkdir build
cd build
cmake ..

View File

@ -58,6 +58,9 @@ Bytes _default_import_handler(const Str& name){
std::vector<char> buffer(ftell(io.fp));
fseek(io.fp, 0, SEEK_SET);
size_t sz = io_fread(buffer.data(), 1, buffer.size(), io.fp);
PK_ASSERT(sz <= buffer.size());
// in text mode, CR may be dropped, which may cause `sz < buffer.size()`
if(sz < buffer.size()) buffer.resize(sz);
PK_UNUSED(sz);
Bytes b(std::move(buffer));
if(io.is_text()) return VAR(b.str());