summaryrefslogtreecommitdiffstats
path: root/newlib/libc/stdlib/btowc.c
diff options
context:
space:
mode:
Diffstat (limited to 'newlib/libc/stdlib/btowc.c')
-rw-r--r--newlib/libc/stdlib/btowc.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/newlib/libc/stdlib/btowc.c b/newlib/libc/stdlib/btowc.c
new file mode 100644
index 000000000..a1ea920ef
--- /dev/null
+++ b/newlib/libc/stdlib/btowc.c
@@ -0,0 +1,27 @@
+#include <wchar.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <reent.h>
+
+wint_t
+btowc (int c)
+{
+ mbstate_t mbs;
+ int retval = 0;
+ wchar_t pwc;
+ unsigned char b;
+
+ b = (unsigned char)c;
+
+ /* Put mbs in initial state. */
+ memset (&mbs, '\0', sizeof (mbs));
+
+ _REENT_CHECK_MISC(_REENT);
+
+ retval = _mbtowc_r (_REENT, &pwc, &b, 1, &mbs);
+
+ if (c == EOF || retval != 1)
+ return WEOF;
+ else
+ return (wint_t)pwc;
+}