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