diff --git a/common/FileSystem.cpp b/common/FileSystem.cpp index ef45a74014..8d1485b37b 100644 --- a/common/FileSystem.cpp +++ b/common/FileSystem.cpp @@ -504,7 +504,7 @@ std::optional> FileSystem::ReadBinaryFile(const char* filename) std::optional> FileSystem::ReadBinaryFile(std::FILE* fp) { std::fseek(fp, 0, SEEK_END); - long size = std::ftell(fp); + const long size = std::ftell(fp); std::fseek(fp, 0, SEEK_SET); if (size < 0) return std::nullopt; @@ -528,13 +528,14 @@ std::optional FileSystem::ReadFileToString(const char* filename) std::optional FileSystem::ReadFileToString(std::FILE* fp) { std::fseek(fp, 0, SEEK_END); - long size = std::ftell(fp); + const long size = std::ftell(fp); std::fseek(fp, 0, SEEK_SET); if (size < 0) return std::nullopt; std::string res; res.resize(static_cast(size)); + // NOTE - assumes mode 'rb', for example, this will fail over missing Windows carriage return bytes if (size > 0 && std::fread(res.data(), 1u, static_cast(size), fp) != static_cast(size)) return std::nullopt; @@ -553,7 +554,7 @@ bool FileSystem::WriteBinaryFile(const char* filename, const void* data, size_t return true; } -bool FileSystem::WriteFileToString(const char* filename, const std::string_view& sv) +bool FileSystem::WriteStringToFile(const char* filename, const std::string_view& sv) { ManagedCFilePtr fp = OpenManagedCFile(filename, "wb"); if (!fp) diff --git a/common/FileSystem.h b/common/FileSystem.h index 44e7c40400..25130f1b42 100644 --- a/common/FileSystem.h +++ b/common/FileSystem.h @@ -142,7 +142,7 @@ namespace FileSystem std::optional ReadFileToString(const char* filename); std::optional ReadFileToString(std::FILE* fp); bool WriteBinaryFile(const char* filename, const void* data, size_t data_length); - bool WriteFileToString(const char* filename, const std::string_view& sv); + bool WriteStringToFile(const char* filename, const std::string_view& sv); /// creates a directory in the local filesystem /// if the directory already exists, the return value will be true.