1 #include <reent.h>
2 #include <wchar.h>
3 #include <stdlib.h>
4 #include <stdio.h>
5 
6 int
wctob(wint_t c)7 wctob (wint_t c)
8 {
9   mbstate_t mbs;
10   int retval = 0;
11   unsigned char pwc;
12 
13   /* Put mbs in initial state. */
14   memset (&mbs, '\0', sizeof (mbs));
15 
16   _REENT_CHECK_MISC(_REENT);
17 
18   retval = _wctomb_r (_REENT, &pwc, c, &mbs);
19 
20   if (c == EOF || retval != 1)
21     return WEOF;
22   else
23     return (int)pwc;
24 }
25