riscv32: add dlsym
[musl.git] / src / stdio / vswscanf.c
blob00b614bc2f5af24079ebd4f9a793e92090b26647
1 #include "stdio_impl.h"
2 #include <wchar.h>
4 static size_t wstring_read(FILE *f, unsigned char *buf, size_t len)
6 const wchar_t *src = f->cookie;
7 size_t k;
9 if (!src) return 0;
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;
17 f->rpos = f->buf;
18 f->rend = f->buf + k;
19 f->cookie = (void *)src;
21 if (!len || !k) return 0;
23 *buf = *f->rpos++;
24 return 1;
27 int vswscanf(const wchar_t *restrict s, const wchar_t *restrict fmt, va_list ap)
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
35 return vfwscanf(&f, fmt, ap);
38 weak_alias(vswscanf,__isoc99_vswscanf);