summaryrefslogtreecommitdiff
path: root/src/wchar/fgetws.c
blob: 69990116c05611b7a862be9f40d0b7e32acbee14 (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
38
39
40
41
42
#if 0

#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)
*/


#endif