Skip to content

Commit cbfdfca

Browse files
MinGW lacks WC_ERR_INVALID_CHARS
1 parent 21c5581 commit cbfdfca

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/mlib/str.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,7 @@ mstr_inplace_replace (mstr *s, mstr_view find, mstr_view subst)
762762

763763
#ifdef _WIN32
764764
#include "./windows-lean.h"
765+
765766
/**
766767
* @brief The result type of mstr_win32_widen
767768
*/
@@ -814,8 +815,11 @@ typedef struct mstr_narrow_result {
814815
mlib_inline_def mstr_narrow_result
815816
mstr_win32_narrow (const wchar_t *wstring)
816817
{
818+
// Some older versions of MinGW fail to include the WC_ERR_INVALID_CHARS
819+
// flag, so we will specify it manually:
820+
DWORD wcflags = 0x08; // WC_ERR_INVALID_CHARS
817821
int length = WideCharToMultiByte (CP_UTF8,
818-
WC_ERR_INVALID_CHARS,
822+
wcflags,
819823
wstring,
820824
-1 /* wstring is null-terminated */,
821825
NULL,
@@ -827,14 +831,8 @@ mstr_win32_narrow (const wchar_t *wstring)
827831
.error = GetLastError ()};
828832
}
829833
mstr_mut ret = mstr_new ((size_t) length);
830-
int got_len = WideCharToMultiByte (CP_UTF8,
831-
WC_ERR_INVALID_CHARS,
832-
wstring,
833-
-1,
834-
ret.data,
835-
(int) ret.len,
836-
NULL,
837-
NULL);
834+
int got_len = WideCharToMultiByte (
835+
CP_UTF8, wcflags, wstring, -1, ret.data, (int) ret.len, NULL, NULL);
838836
assert (length == got_len);
839837
return (mstr_narrow_result){.string = ret.mstr, .error = 0};
840838
}

0 commit comments

Comments
 (0)