blob: a7210445c89b98ad3b1150eb31b28b063442de1a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#include <wchar.h>
#include <stdio.h>
#include "_assert.h"
wchar_t * fgetws(wchar_t * restrict s, int n, FILE * restrict stream)
{
ASSERT_NONNULL(s);
ASSERT_NONNULL(stream);
if (fwide(stream, 1) <= 0) {
/* not a wide stream */
return NULL;
}
int i;
for (i = 0; i < n; i++) {
s[i] = fgetwc(stream);
if (s[i] == WEOF) {
if (feof(stream)) {
s[i] = L'\0';
return s;
}
/* read or encoding error */
return NULL;
}
if (s[i] == L'\0') {
break;
}
}
s[i] = L'\0';
return s;
}
/*
STDC(199409)
*/
|