Older Windows versons do not support MB_ERR_INVALID_CHARS flag and signals
either ERROR_INVALID_PARAMETER or ERROR_INVALID_FLAGS error. All fallback
case without the MB_ERR_INVALID_CHARS flag.
---
 mingw-w64-crt/misc/__mingw_mbrtowc_cp.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/mingw-w64-crt/misc/__mingw_mbrtowc_cp.c 
b/mingw-w64-crt/misc/__mingw_mbrtowc_cp.c
index 22bbb062d7b5..3bd6abaa61f1 100644
--- a/mingw-w64-crt/misc/__mingw_mbrtowc_cp.c
+++ b/mingw-w64-crt/misc/__mingw_mbrtowc_cp.c
@@ -133,6 +133,15 @@ size_t __mingw_mbrtowc_cp (
   int ret = MultiByteToWideChar (
     cp, MB_ERR_INVALID_CHARS, conversion_state.bytes, length, &wcOut, 1
   );
+  if (ret == 0) {
+    /* Older Windows versons do not support MB_ERR_INVALID_CHARS.
+     * WinNT 3.x signals ERROR_INVALID_PARAMETER and WinNT 4.0 signals 
ERROR_INVALID_FLAGS.
+     * Fallback case when MB_ERR_INVALID_CHARS is not supported.
+     */
+    DWORD error = GetLastError ();
+    if (error == ERROR_INVALID_PARAMETER || error == ERROR_INVALID_FLAGS)
+      ret = MultiByteToWideChar (cp, 0, conversion_state.bytes, length, 
&wcOut, 1);
+  }
 
   if (ret != 1) {
     goto eilseq;
-- 
2.20.1



_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to