mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-22 05:45:38 +00:00
FileSystem: Add Error to file writing
This commit is contained in:
parent
29b3fa2b95
commit
eba0794b4f
|
@ -1181,26 +1181,32 @@ std::optional<std::string> FileSystem::ReadFileToString(std::FILE* fp)
|
|||
return res;
|
||||
}
|
||||
|
||||
bool FileSystem::WriteBinaryFile(const char* filename, const void* data, size_t data_length)
|
||||
bool FileSystem::WriteBinaryFile(const char* filename, const void* data, size_t data_length, Error* error)
|
||||
{
|
||||
ManagedCFilePtr fp = OpenManagedCFile(filename, "wb");
|
||||
ManagedCFilePtr fp = OpenManagedCFile(filename, "wb", error);
|
||||
if (!fp)
|
||||
return false;
|
||||
|
||||
if (data_length > 0 && std::fwrite(data, 1u, data_length, fp.get()) != data_length)
|
||||
{
|
||||
Error::SetErrno(error, "fwrite() failed: ", errno);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FileSystem::WriteStringToFile(const char* filename, std::string_view sv)
|
||||
bool FileSystem::WriteStringToFile(const char* filename, std::string_view sv, Error* error)
|
||||
{
|
||||
ManagedCFilePtr fp = OpenManagedCFile(filename, "wb");
|
||||
ManagedCFilePtr fp = OpenManagedCFile(filename, "wb", error);
|
||||
if (!fp)
|
||||
return false;
|
||||
|
||||
if (sv.length() > 0 && std::fwrite(sv.data(), 1u, sv.length(), fp.get()) != sv.length())
|
||||
{
|
||||
Error::SetErrno(error, "fwrite() failed: ", errno);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -145,8 +145,8 @@ std::optional<std::vector<u8>> ReadBinaryFile(const char* filename, Error* error
|
|||
std::optional<std::vector<u8>> ReadBinaryFile(std::FILE* fp);
|
||||
std::optional<std::string> ReadFileToString(const char* filename, Error* error = nullptr);
|
||||
std::optional<std::string> ReadFileToString(std::FILE* fp);
|
||||
bool WriteBinaryFile(const char* filename, const void* data, size_t data_length);
|
||||
bool WriteStringToFile(const char* filename, std::string_view sv);
|
||||
bool WriteBinaryFile(const char* filename, const void* data, size_t data_length, Error* error = nullptr);
|
||||
bool WriteStringToFile(const char* filename, std::string_view sv, Error* error = nullptr);
|
||||
|
||||
/// creates a directory in the local filesystem
|
||||
/// if the directory already exists, the return value will be true.
|
||||
|
|
Loading…
Reference in a new issue