common: fix method name and clarify some behaviour

This commit is contained in:
Tyler Wilding 2022-02-17 23:10:15 -05:00 committed by refractionpcsx2
parent ddfe6ac5c1
commit aa42acfe22
2 changed files with 5 additions and 4 deletions

View File

@ -504,7 +504,7 @@ std::optional<std::vector<u8>> FileSystem::ReadBinaryFile(const char* filename)
std::optional<std::vector<u8>> 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<std::string> FileSystem::ReadFileToString(const char* filename)
std::optional<std::string> 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_t>(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_t>(size), fp) != static_cast<size_t>(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)

View File

@ -142,7 +142,7 @@ namespace FileSystem
std::optional<std::string> ReadFileToString(const char* filename);
std::optional<std::string> 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.