summaryrefslogtreecommitdiff
path: root/src/stdio/vfwscanf.c
blob: 491c14031ada99ea2b4675e4e90d76f7ebb85e03 (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
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <wchar.h>
#include <wctype.h>

#include "stdio_impl.h"
#include "__scanf.h"

static void f_read(rctx_t *r)
{
	FILE *f = r->opaque;
	if ((r->c = fgetwc(f)) >= 0) r->l++;
}

int vfwscanf(FILE *f, const wchar_t *fmt, va_list ap)
{
	rctx_t r = { f_read, (void *)f, 1, iswspace };
	int result;

	result = __scanf(&r, fmt, ap);

	if (r.u && r.c >= 0) {
		ungetwc(r.c, f);
	}

	return result;
}