1 /*
2 Copyright (c) 2002 Thomas Fitzsimmons <fitzsim@redhat.com>
3  */
4 #include <wchar.h>
5 #include <stdio.h>
6 #include <string.h>
7 #include <limits.h>
8 #include "local.h"
9 
10 int
wctob(wint_t wc)11 wctob (wint_t wc)
12 {
13   mbstate_t mbs;
14   unsigned char pmb[MB_LEN_MAX];
15 
16   if (wc == WEOF)
17     return EOF;
18 
19   /* Put mbs in initial state. */
20   memset (&mbs, '\0', sizeof (mbs));
21 
22   return __WCTOMB ((char *) pmb, wc, &mbs) == 1 ? (int) pmb[0] : EOF;
23 }
24