| 1 |
#include "stdio_impl.h" |
| 2 |
#include <wchar.h> |
| 3 |
|
| 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 |
|
| 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 |
#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) |
| 34 |
.read = wstring_read, .lock = -1 |
| 35 |
#else |
| 36 |
.read = wstring_read |
| 37 |
#endif |
| 38 |
}; |
| 39 |
return vfwscanf(&f, fmt, ap); |
| 40 |
} |
| 41 |
|
| 42 |
weak_alias(vswscanf,__isoc99_vswscanf); |