aboutsummaryrefslogtreecommitdiff
path: root/posix/regex.c
diff options
context:
space:
mode:
Diffstat (limited to 'posix/regex.c')
-rw-r--r--posix/regex.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/posix/regex.c b/posix/regex.c
index a5c35fecd2..facb833f58 100644
--- a/posix/regex.c
+++ b/posix/regex.c
@@ -4627,9 +4627,16 @@ static unsigned char
truncate_wchar (c)
CHAR_T c;
{
- unsigned char buf[MB_LEN_MAX];
- int retval = wctomb(buf, c);
- return retval > 0 ? buf[0] : (unsigned char)c;
+ unsigned char buf[MB_CUR_MAX];
+ mbstate_t state;
+ int retval;
+ memset (&state, '\0', sizeof (state));
+# ifdef _LIBC
+ retval = __wcrtomb (buf, c, &state);
+# else
+ retval = wcrtomb (buf, c, &state);
+# endif
+ return retval > 0 ? buf[0] : (unsigned char) c;
}
#endif /* WCHAR */