fs/io/File{Reader,OutputStream}: convert path to UTF-8 for error message

This commit is contained in:
Max Kellermann
2015-02-25 19:10:47 +01:00
parent fe1e467a49
commit 00b0f6ad51
2 changed files with 18 additions and 7 deletions

View File

@@ -43,8 +43,11 @@ FileOutputStream::FileOutputStream(Path _path, Error &error)
FILE_ATTRIBUTE_NORMAL|FILE_FLAG_WRITE_THROUGH, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_WRITE_THROUGH,
nullptr)) nullptr))
{ {
if (handle == INVALID_HANDLE_VALUE) if (handle == INVALID_HANDLE_VALUE) {
error.FormatLastError("Failed to create %s", path.c_str()); const auto path_utf8 = path.ToUTF8();
error.FormatLastError("Failed to create %s",
path_utf8.c_str());
}
} }
bool bool
@@ -54,13 +57,17 @@ FileOutputStream::Write(const void *data, size_t size, Error &error)
DWORD nbytes; DWORD nbytes;
if (!WriteFile(handle, data, size, &nbytes, nullptr)) { if (!WriteFile(handle, data, size, &nbytes, nullptr)) {
error.FormatLastError("Failed to write to %s", path.c_str()); const auto path_utf8 = path.ToUTF8();
error.FormatLastError("Failed to write to %s",
path_utf8.c_str());
return false; return false;
} }
if (size_t(nbytes) != size) { if (size_t(nbytes) != size) {
const auto path_utf8 = path.ToUTF8();
error.FormatLastError(ERROR_DISK_FULL, error.FormatLastError(ERROR_DISK_FULL,
"Failed to write to %s", path.c_str()); "Failed to write to %s",
path_utf8.c_str());
return false; return false;
} }

View File

@@ -30,8 +30,10 @@ FileReader::FileReader(Path _path, Error &error)
nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
nullptr)) nullptr))
{ {
if (handle == INVALID_HANDLE_VALUE) if (handle == INVALID_HANDLE_VALUE) {
error.FormatLastError("Failed to open %s", path.c_str()); const auto path_utf8 = path.ToUTF8();
error.FormatLastError("Failed to open %s", path_utf8.c_str());
}
} }
size_t size_t
@@ -41,7 +43,9 @@ FileReader::Read(void *data, size_t size, Error &error)
DWORD nbytes; DWORD nbytes;
if (!ReadFile(handle, data, size, &nbytes, nullptr)) { if (!ReadFile(handle, data, size, &nbytes, nullptr)) {
error.FormatLastError("Failed to read from %s", path.c_str()); const auto path_utf8 = path.ToUTF8();
error.FormatLastError("Failed to read from %s",
path_utf8.c_str());
nbytes = 0; nbytes = 0;
} }