• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "stdio_impl.h"
2 #include <wchar.h>
3 
wstring_read(FILE * f,unsigned char * buf,size_t len)4 static size_t wstring_read(FILE *f, unsigned char *buf, size_t len)
5 {
6 	const wchar_t *src = f->cookie;
7 	size_t k;
8 
9 	if (!src) return 0;
10 
11 	k = wcsrtombs((void *)f->buf, &src, f->buf_size, 0);
12 	if (k==(size_t)-1) {
13 		f->rpos = f->rend = 0;
14 		return 0;
15 	}
16 
17 	f->rpos = f->buf;
18 	f->rend = f->buf + k;
19 	f->cookie = (void *)src;
20 
21 	if (!len || !k) return 0;
22 
23 	*buf = *f->rpos++;
24 	return 1;
25 }
26 
vswscanf(const wchar_t * restrict s,const wchar_t * restrict fmt,va_list ap)27 int vswscanf(const wchar_t *restrict s, const wchar_t *restrict fmt, va_list ap)
28 {
29 	unsigned char buf[256];
30 	FILE f = {
31 		.buf = buf, .buf_size = sizeof buf,
32 		.cookie = (void *)s,
33 		.read = wstring_read, .lock = -1
34 	};
35 	return vfwscanf(&f, fmt, ap);
36 }
37 
38 weak_alias(vswscanf,__isoc99_vswscanf);
39