2017-04-11 21:13:36 +00:00
|
|
|
#include <wchar.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <reent.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "local.h"
|
|
|
|
|
|
|
|
wint_t
|
|
|
|
btowc (int c)
|
|
|
|
{
|
|
|
|
mbstate_t mbs;
|
|
|
|
int retval = 0;
|
|
|
|
wchar_t pwc;
|
|
|
|
unsigned char b;
|
|
|
|
|
|
|
|
if (c == EOF)
|
|
|
|
return WEOF;
|
|
|
|
|
|
|
|
b = (unsigned char)c;
|
|
|
|
|
|
|
|
/* Put mbs in initial state. */
|
|
|
|
memset (&mbs, '\0', sizeof (mbs));
|
|
|
|
|
|
|
|
_REENT_CHECK_MISC(_REENT);
|
|
|
|
|
2017-10-07 00:16:47 +00:00
|
|
|
retval = __MBTOWC (_REENT, &pwc, (const char *) &b, 1, &mbs);
|
2017-04-11 21:13:36 +00:00
|
|
|
|
|
|
|
if (retval != 0 && retval != 1)
|
|
|
|
return WEOF;
|
|
|
|
|
|
|
|
return (wint_t)pwc;
|
|
|
|
}
|