Permalink
Browse files

POSIX.xs: Prefer mbrtowc() over mbtowc()

mbrtowc is reentrant, so use it on threaded perls if available when
POSIX::mbtowc() is called.
  • Loading branch information...
khwilliamson committed Jan 11, 2018
1 parent dfdb9db commit ce313228b8c28feb992253d950cca3761f1bbb07
Showing with 15 additions and 0 deletions.
  1. +15 −0 ext/POSIX/POSIX.xs
View
@@ -3285,6 +3285,21 @@ mbtowc(pwc, s, n)
wchar_t * pwc
char * s
size_t n
PREINIT:
#if defined(USE_ITHREADS) && defined(HAS_MBRTOWC)
mbstate_t ps;
#endif
CODE:
#if defined(USE_ITHREADS) && defined(HAS_MBRTOWC)
memset(&ps, 0, sizeof(ps));;
PERL_UNUSED_RESULT(mbrtowc(pwc, NULL, 0, &ps));/* Reset any shift state */
errno = 0;
RETVAL = mbrtowc(pwc, s, n, &ps); /* Prefer reentrant version */
#else
RETVAL = mbtowc(pwc, s, n);
#endif
OUTPUT:
RETVAL
int
wcstombs(s, pwcs, n)

0 comments on commit ce31322

Please sign in to comment.