+ rl->__variable = ei;
+ rl->__variable_len = sizeof(_EucInfo);
+- _CurrentRuneLocale = rl;
+- __mb_cur_max = new__mb_cur_max;
+- __mbrtowc = _EUC_mbrtowc;
+- __wcrtomb = _EUC_wcrtomb;
+- __mbsinit = _EUC_mbsinit;
++ xrl->__mb_cur_max = new__mb_cur_max;
++ xrl->__mbrtowc = _EUC_mbrtowc;
++ xrl->__wcrtomb = _EUC_wcrtomb;
++ xrl->__mbsinit = _EUC_mbsinit;
++ xrl->__free_extra = (__free_extra_t)_EUC_free_extra;
+ return (0);
+ }
+
+-int
+-_EUC_mbsinit(const mbstate_t *ps)
++static int
++_EUC_mbsinit(const mbstate_t *ps, locale_t loc)
+ {
+
+ return (ps == NULL || ((const _EucState *)ps)->want == 0);
+ }
+
+-#define CEI ((_EucInfo *)(_CurrentRuneLocale->__variable))
+-
+ #define _SS2 0x008e
+ #define _SS3 0x008f
+
+@@ -140,18 +149,20 @@
+ return ((c & 0x80) ? c == _SS3 ? 3 : c == _SS2 ? 2 : 1 : 0);
+ }
+
+-size_t
++static size_t
+ _EUC_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n,
+- mbstate_t * __restrict ps)
++ mbstate_t * __restrict ps, locale_t loc)
+ {
+ _EucState *es;
+ int i, set, want;
+ wchar_t wc;
+ const char *os;
++ struct __xlocale_st_runelocale *rl = loc->__lc_ctype;
++ _EucInfo *CEI = (_EucInfo *)rl->_CurrentRuneLocale.__variable;
+
+ es = (_EucState *)ps;
+
+- if (es->want < 0 || es->want > MB_CUR_MAX || es->set < 0 ||
++ if (es->want < 0 || es->want > rl->__mb_cur_max || es->set < 0 ||
+ es->set > 3) {
+ errno = EINVAL;
+ return ((size_t)-1);
+@@ -213,12 +224,14 @@
+ return (wc == L'\0' ? 0 : s - os);
+ }
+
+-size_t
+-_EUC_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps)
++static size_t
++_EUC_wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps,
++ locale_t loc)
+ {
+ _EucState *es;
+ wchar_t m, nm;
+ int i, len;
++ _EucInfo *CEI = (_EucInfo *)loc->__lc_ctype->_CurrentRuneLocale.__variable;
+
+ es = (_EucState *)ps;
+