From 0b44a0315b47dd8eced9f3b7f31580cf14bbfc01 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 12 Feb 2011 00:22:29 -0500 Subject: initial check-in, version 0.5.0 --- src/stdio/fgetws.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/stdio/fgetws.c (limited to 'src/stdio/fgetws.c') diff --git a/src/stdio/fgetws.c b/src/stdio/fgetws.c new file mode 100644 index 00000000..2e76b565 --- /dev/null +++ b/src/stdio/fgetws.c @@ -0,0 +1,27 @@ +#include "stdio_impl.h" + +wint_t __fgetwc_unlocked(FILE *); + +wchar_t *fgetws(wchar_t *s, int n, FILE *f) +{ + wchar_t *p = s; + + if (!n--) return s; + + FLOCK(f); + + for (; n; n--) { + wint_t c = __fgetwc_unlocked(f); + if (c == WEOF) break; + *p++ = c; + if (c == '\n') break; + } + *p = 0; + if (ferror(f)) p = s; + + FUNLOCK(f); + + return (p == s) ? NULL : s; +} + +weak_alias(fgetws, fgetws_unlocked); -- cgit v1.2.1