From 00b0f6ad51e4fe02d6e3955e6bc15f8ee1de6eb3 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 25 Feb 2015 19:10:47 +0100 Subject: fs/io/File{Reader,OutputStream}: convert path to UTF-8 for error message --- src/fs/io/FileOutputStream.cxx | 15 +++++++++++---- src/fs/io/FileReader.cxx | 10 +++++++--- 2 files changed, 18 insertions(+), 7 deletions(-) (limited to 'src/fs') diff --git a/src/fs/io/FileOutputStream.cxx b/src/fs/io/FileOutputStream.cxx index cdaf12ec2..6cec024ad 100644 --- a/src/fs/io/FileOutputStream.cxx +++ b/src/fs/io/FileOutputStream.cxx @@ -43,8 +43,11 @@ FileOutputStream::FileOutputStream(Path _path, Error &error) FILE_ATTRIBUTE_NORMAL|FILE_FLAG_WRITE_THROUGH, nullptr)) { - if (handle == INVALID_HANDLE_VALUE) - error.FormatLastError("Failed to create %s", path.c_str()); + if (handle == INVALID_HANDLE_VALUE) { + const auto path_utf8 = path.ToUTF8(); + error.FormatLastError("Failed to create %s", + path_utf8.c_str()); + } } bool @@ -54,13 +57,17 @@ FileOutputStream::Write(const void *data, size_t size, Error &error) DWORD nbytes; 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; } if (size_t(nbytes) != size) { + const auto path_utf8 = path.ToUTF8(); error.FormatLastError(ERROR_DISK_FULL, - "Failed to write to %s", path.c_str()); + "Failed to write to %s", + path_utf8.c_str()); return false; } diff --git a/src/fs/io/FileReader.cxx b/src/fs/io/FileReader.cxx index 01ffe95f2..a19f472e8 100644 --- a/src/fs/io/FileReader.cxx +++ b/src/fs/io/FileReader.cxx @@ -30,8 +30,10 @@ FileReader::FileReader(Path _path, Error &error) nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr)) { - if (handle == INVALID_HANDLE_VALUE) - error.FormatLastError("Failed to open %s", path.c_str()); + if (handle == INVALID_HANDLE_VALUE) { + const auto path_utf8 = path.ToUTF8(); + error.FormatLastError("Failed to open %s", path_utf8.c_str()); + } } size_t @@ -41,7 +43,9 @@ FileReader::Read(void *data, size_t size, Error &error) DWORD nbytes; 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; } -- cgit v1.2.3