int wctomb(char *s, wchar_t wchar) { #ifdef MB_CAPABLE static int state; return _wctomb_r(_REENT, s, wchar, &state); #else /* not MB_CAPABLE */ if (s == NULL) return 0; *s = (char)wchar; return 1; #endif /* not MB_CAPABLE */ }
int wctob (wint_t c) { mbstate_t mbs; int retval = 0; unsigned char pwc; /* Put mbs in initial state. */ memset (&mbs, '\0', sizeof (mbs)); _REENT_CHECK_MISC(_REENT); retval = _wctomb_r (_REENT, &pwc, c, &mbs); if (c == EOF || retval != 1) return WEOF; else return (int)pwc; }