Both users of this function (mbrlen and mbrtowc) calls it with the current
locale and maximum character length for current locale.
So replace the mbrtowc_cp() usage in mbrlen() directly by mbrtowc().
Also replace MB_CUR_MAX macro by the ___mb_cur_max_func() function to show
that the maximum character length depends on the locale and is not a
constant value.
---
mingw-w64-crt/misc/mbrtowc.c | 48 ++++++++++++++----------------------
1 file changed, 18 insertions(+), 30 deletions(-)
diff --git a/mingw-w64-crt/misc/mbrtowc.c b/mingw-w64-crt/misc/mbrtowc.c
index 200711c8004e..2d89af5132f5 100644
--- a/mingw-w64-crt/misc/mbrtowc.c
+++ b/mingw-w64-crt/misc/mbrtowc.c
@@ -19,14 +19,17 @@ static mbstate_t state_mbrlen = {0};
static mbstate_t state_mbrtowc = {0};
static mbstate_t state_mbsrtowcs = {0};
-static size_t mbrtowc_cp (
+size_t mbrtowc (
wchar_t *__restrict__ wc,
const char *__restrict__ mbs,
size_t count,
- mbstate_t *__restrict__ state,
- unsigned cp,
- int mb_cur_max
+ mbstate_t *__restrict__ state
) {
+ /* Use private `mbstate_t` if caller did not supply one */
+ if (state == NULL) {
+ state = &state_mbrtowc;
+ }
+
/* Set `state` to initial state */
if (mbs == NULL) {
*state = 0;
@@ -43,6 +46,12 @@ static size_t mbrtowc_cp (
return (size_t) -2;
}
+ /* Code page used by current locale */
+ unsigned cp = ___lc_codepage_func ();
+
+ /* Maximum character length used by current locale */
+ int mb_cur_max = ___mb_cur_max_func ();
+
/* Treat `state` as an array of bytes */
union {
mbstate_t state;
@@ -137,25 +146,6 @@ size_t mbrlen (
return mbrtowc (&wc, mbs, count, state);
}
-size_t mbrtowc (
- wchar_t *__restrict__ wc,
- const char *__restrict__ mbs,
- size_t count,
- mbstate_t *__restrict__ state
-) {
- /* Use private `mbstate_t` if caller did not supply one */
- if (state == NULL) {
- state = &state_mbrtowc;
- }
-
- /* Code page used by current locale */
- unsigned cp = ___lc_codepage_func ();
- /* Maximum character length in `cp` */
- int mb_cur_max = MB_CUR_MAX;
-
- return mbrtowc_cp (wc, mbs, count, state, cp, mb_cur_max);
-}
-
size_t mbsrtowcs (
wchar_t *wcs,
const char **__restrict__ mbs,
@@ -167,11 +157,6 @@ size_t mbsrtowcs (
state = &state_mbsrtowcs;
}
- /* Code page used by current locale */
- unsigned cp = ___lc_codepage_func ();
- /* Maximum character length in `cp` */
- int mb_cur_max = MB_CUR_MAX;
-
/* Treat `state` as array of bytes */
union {
mbstate_t state;
@@ -186,9 +171,12 @@ size_t mbsrtowcs (
/* Next multibyte character to convert */
const char *mbc = *mbs;
+ /* Maximum character length in `cp` */
+ int mb_cur_max = ___mb_cur_max_func();
+
while (1) {
- const size_t length = mbrtowc_cp (
- &wc, mbc, mb_cur_max, &conversion_state.state, cp, mb_cur_max
+ const size_t length = mbrtowc (
+ &wc, mbc, mb_cur_max, &conversion_state.state
);
/* Conversion failed */
--
2.20.1
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public