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