blob: 2e76b56547c7a8df43c913825c8ce7e43027cb4d [file] [log] [blame]
Rich Felker0b44a032011-02-12 00:22:29 -05001#include "stdio_impl.h"
2
3wint_t __fgetwc_unlocked(FILE *);
4
5wchar_t *fgetws(wchar_t *s, int n, FILE *f)
6{
7 wchar_t *p = s;
8
9 if (!n--) return s;
10
11 FLOCK(f);
12
13 for (; n; n--) {
14 wint_t c = __fgetwc_unlocked(f);
15 if (c == WEOF) break;
16 *p++ = c;
17 if (c == '\n') break;
18 }
19 *p = 0;
20 if (ferror(f)) p = s;
21
22 FUNLOCK(f);
23
24 return (p == s) ? NULL : s;
25}
26
27weak_alias(fgetws, fgetws_unlocked);