X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fstdio%2Fvswscanf.c;h=4c39f80655ddccc8e3599008427710a4da864b16;hb=7650390de8f72822ec0d4a9fb5b52efcf0be4698;hp=2c4ffbe09cbbc1c31431e7cbe2a60f7714d41876;hpb=0b44a0315b47dd8eced9f3b7f31580cf14bbfc01;p=musl diff --git a/src/stdio/vswscanf.c b/src/stdio/vswscanf.c index 2c4ffbe0..4c39f806 100644 --- a/src/stdio/vswscanf.c +++ b/src/stdio/vswscanf.c @@ -1,19 +1,35 @@ -#include -#include -#include -#include +#include "stdio_impl.h" -#include "__scanf.h" - -static void s_read(rctx_t *r) +static size_t wstring_read(FILE *f, unsigned char *buf, size_t len) { - wchar_t *s = r->opaque; - if (!s[r->l]) r->c = -1; - else r->c = s[r->l++]; + const wchar_t *src = f->cookie; + size_t k; + + if (!src) return 0; + + k = wcsrtombs((void *)f->buf, &src, f->buf_size, 0); + if (k==(size_t)-1) { + f->rpos = f->rend = 0; + return 0; + } + + f->rpos = f->buf; + f->rend = f->buf + k; + f->cookie = (void *)src; + + if (!len || !k) return 0; + + *buf = *f->rpos++; + return 1; } int vswscanf(const wchar_t *s, const wchar_t *fmt, va_list ap) { - rctx_t r = { s_read, (void *)s, 1, iswspace }; - return __scanf(&r, fmt, ap); + unsigned char buf[256]; + FILE f = { + .buf = buf, .buf_size = sizeof buf, + .cookie = (void *)s, + .read = wstring_read, .lock = -1 + }; + return vfwscanf(&f, fmt, ap); }