libc-top-half/musl/src/stdio/fgetws.c
raw| 1 | #include "stdio_impl.h" |
| 2 | #include <wchar.h> |
| 3 | |
| 4 | wint_t __fgetwc_unlocked(FILE *); |
| 5 | |
| 6 | wchar_t *fgetws(wchar_t *restrict s, int n, FILE *restrict f) |
| 7 | { |
| 8 | wchar_t *p = s; |
| 9 | |
| 10 | if (!n--) return s; |
| 11 | |
| 12 | FLOCK(f); |
| 13 | |
| 14 | for (; n; n--) { |
| 15 | wint_t c = __fgetwc_unlocked(f); |
| 16 | if (c == WEOF) break; |
| 17 | *p++ = c; |
| 18 | if (c == '\n') break; |
| 19 | } |
| 20 | *p = 0; |
| 21 | if (ferror(f)) p = s; |
| 22 | |
| 23 | FUNLOCK(f); |
| 24 | |
| 25 | return (p == s) ? NULL : s; |
| 26 | } |
| 27 | |
| 28 | weak_alias(fgetws, fgetws_unlocked); |