summaryrefslogtreecommitdiff
path: root/src/wchar/fgetwc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/wchar/fgetwc.c')
-rw-r--r--src/wchar/fgetwc.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/wchar/fgetwc.c b/src/wchar/fgetwc.c
new file mode 100644
index 00000000..30d98083
--- /dev/null
+++ b/src/wchar/fgetwc.c
@@ -0,0 +1,35 @@
+#include <wchar.h>
+#include "stdio.h"
+#include "nonstd/io.h"
+#include "limits.h"
+
+wint_t fgetwc(FILE * stream)
+{
+ if (fwide(stream, 1) <= 0) {
+
+ return WEOF;
+ }
+
+ flockfile(stream);
+ stream->orientation = -1;
+
+ char mbr[MB_LEN_MAX+1] = {0};
+ int n = 0;
+ mbstate_t ps = 0;
+ wint_t wc = 0;
+
+ /* FIXME: check for (size_t)-2 and (size_t)-1 from mbrtowc */
+ do {
+ mbr[n++] = getc_unlocked(stream);
+ ps = 0;
+ } while (mbrtowc(&wc, mbr, n, &ps) != 0);
+
+ stream->orientation = 1;
+ funlockfile(stream);
+
+ return wc;
+}
+
+/*
+STDC(199409)
+*/