summaryrefslogtreecommitdiff
path: root/src/wchar/fgetws.c
blob: 1e341c186b6348c82b03095e8bca6e0254ee3216 (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
43
44
45
#if 0

#include <wchar.h>
#include <stdio.h>
#include "_safety.h"

wchar_t * fgetws(wchar_t * restrict s, int n, FILE * restrict stream)
{
	SIGNAL_SAFE(0);

	ASSERT_NONNULL(s);
	ASSERT_NONNULL(stream);
	/* TODO: overlap */

	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