diff --git a/vm/image.cpp b/vm/image.cpp index f29ca779a3..c61a0a83cd 100644 --- a/vm/image.cpp +++ b/vm/image.cpp @@ -232,9 +232,9 @@ void factor_vm::load_image(vm_parameters* p) { FILE* file = OPEN_READ(p->image_path); if (file == NULL) { - std::cout << "Cannot open image file: " << p->image_path << std::endl; + std::cout << "Cannot open image file: " << AS_UTF8(p->image_path) << std::endl; char *msg = threadsafe_strerror(errno); - std::cout << "strerror:2: " << msg << std::endl; + std::cout << "strerror: " << msg << std::endl; free(msg); exit(1); } diff --git a/vm/os-unix.hpp b/vm/os-unix.hpp index 33bde83e5b..b89a9bfcd6 100644 --- a/vm/os-unix.hpp +++ b/vm/os-unix.hpp @@ -53,4 +53,5 @@ void check_ENOMEM(const char* msg); static inline void breakpoint() { __builtin_trap(); } +#define AS_UTF8(ptr) ptr } diff --git a/vm/os-windows.hpp b/vm/os-windows.hpp index cca3c7e776..a21a67361b 100644 --- a/vm/os-windows.hpp +++ b/vm/os-windows.hpp @@ -92,4 +92,36 @@ inline static void breakpoint() { DebugBreak(); } extern HANDLE boot_thread; +inline static std::string to_utf8(const wchar_t* buffer, int len) { + int nChars = ::WideCharToMultiByte( + CP_UTF8, + 0, + buffer, + len, + NULL, + 0, + NULL, + NULL); + if (nChars == 0) return ""; + + std::string newbuffer; + newbuffer.resize(nChars) ; + ::WideCharToMultiByte( + CP_UTF8, + 0, + buffer, + len, + const_cast(newbuffer.c_str()), + nChars, + NULL, + NULL); + return newbuffer; +} + +inline static std::string to_utf8(const std::wstring& str) { + return to_utf8(str.c_str(), (int)str.size()); +} + +#define AS_UTF8(ptr) to_utf8(ptr) + }