1 /* Copyright (c) 2002 Thomas Fitzsimmons <fitzsim@redhat.com> */
2 #include <wchar.h>
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include <string.h>
6 #include "local.h"
7 
8 wint_t
btowc(int c)9 btowc (int c)
10 {
11   mbstate_t mbs;
12   int retval = 0;
13   wchar_t pwc;
14   unsigned char b;
15 
16   if (c == EOF)
17     return WEOF;
18 
19   b = (unsigned char)c;
20 
21   /* Put mbs in initial state. */
22   memset (&mbs, '\0', sizeof (mbs));
23 
24   retval = __MBTOWC (&pwc, (const char *) &b, 1, &mbs);
25 
26   if (retval != 0 && retval != 1)
27     return WEOF;
28 
29   return (wint_t)pwc;
30 }
31