From 3318cd969ba826c6b1dadb2d67bc39d2b3423bca Mon Sep 17 00:00:00 2001 From: Brad Parker Date: Sat, 9 Dec 2017 14:26:21 -0500 Subject: [PATCH] win95: fallback to strdup when MultiByteToWideChar fails (it only works with MSLU) --- libretro-common/encodings/encoding_utf.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/libretro-common/encodings/encoding_utf.c b/libretro-common/encodings/encoding_utf.c index 2148fcb470..11cf363de1 100644 --- a/libretro-common/encodings/encoding_utf.c +++ b/libretro-common/encodings/encoding_utf.c @@ -297,6 +297,10 @@ static char* mb_to_mb_string_alloc(const char *str, return strdup(str); #else + /* Windows 95 will return 0 from these functions with a UTF8 codepage set without MSLU. From an unknown MSDN version (others omit this info): + * - CP_UTF8 Windows 98/Me, Windows NT 4.0 and later: Translate using UTF-8. When this is set, dwFlags must be zero. + * - Windows 95: Under the Microsoft Layer for Unicode, MultiByteToWideChar also supports CP_UTF7 and CP_UTF8. + */ path_buf_wide_len = MultiByteToWideChar(cp_in, 0, str, -1, NULL, 0); if (path_buf_wide_len) @@ -334,9 +338,16 @@ static char* mb_to_mb_string_alloc(const char *str, return NULL; } } + else + { + free(path_buf_wide); + return strdup(str); + } } } } + else + return strdup(str); if (path_buf_wide) free(path_buf_wide); @@ -385,6 +396,8 @@ wchar_t* utf8_to_utf16_string_alloc(const char *str) out_len = MultiByteToWideChar(CP_UTF8, 0, str, -1, buf, len); } + else + return strdup(str); if (out_len < 0) { @@ -442,6 +455,8 @@ char* utf16_to_utf8_string_alloc(const wchar_t *str) out_len = WideCharToMultiByte(CP_UTF8, 0, str, -1, buf, len, NULL, NULL); } + else + return strdup(str); if (out_len < 0) {