From 96c00508be68962c6d830ce7b78b2e16a63964a3 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Wed, 26 Apr 2023 12:54:10 +0800 Subject: [PATCH] ... --- src/io.h | 10 +++++++--- src/repl.h | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/io.h b/src/io.h index 1275cba8..503f2efa 100644 --- a/src/io.h +++ b/src/io.h @@ -31,12 +31,16 @@ struct FileIO { bool is_text() const { return mode != "rb" && mode != "wb" && mode != "ab"; } FileIO(VM* vm, Str file, Str mode): file(file), mode(mode) { + std::ios_base::openmode extra = 0; + if(mode == "rb" || mode == "wb" || mode == "ab"){ + extra |= std::ios::binary; + } if(mode == "rt" || mode == "r" || mode == "rb"){ - _fs.open(file.sv(), std::ios::in); + _fs.open(file.sv(), std::ios::in | extra); }else if(mode == "wt" || mode == "w" || mode == "wb"){ - _fs.open(file.sv(), std::ios::out); + _fs.open(file.sv(), std::ios::out | extra); }else if(mode == "at" || mode == "a" || mode == "ab"){ - _fs.open(file.sv(), std::ios::app); + _fs.open(file.sv(), std::ios::app | extra); }else{ vm->ValueError("invalid mode"); } diff --git a/src/repl.h b/src/repl.h index 1bf33ae3..f414e11c 100644 --- a/src/repl.h +++ b/src/repl.h @@ -23,7 +23,7 @@ inline std::string getline(bool* eof=nullptr) { std::string output; output.resize(length); WideCharToMultiByte(CP_UTF8, 0, wideInput.c_str(), (int)wideInput.length(), &output[0], length, NULL, NULL); - if(output.size() && output[output.size()-1] == '\r') output.pop_back(); + if(!output.empty() && output.back() == '\r') output.pop_back(); return output; }