X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fstdio%2Fvfscanf.c;h=b78a374d3a7f4543dacb44832c226b456b7b45dc;hb=dec8f0a4fa7aa533c843e6eaec862be674ff3a1a;hp=6bea6ad8f1d82fa0ec56887f025aaf04c1a70d48;hpb=16a1e0365d83c387d0dddd3c127ac7c8dcdf17fc;p=musl diff --git a/src/stdio/vfscanf.c b/src/stdio/vfscanf.c index 6bea6ad8..b78a374d 100644 --- a/src/stdio/vfscanf.c +++ b/src/stdio/vfscanf.c @@ -5,10 +5,7 @@ #include #include #include -#include -#include -#include -#include +#include #include "stdio_impl.h" #include "shgetc.h" @@ -60,7 +57,7 @@ int vfscanf(FILE *restrict f, const char *restrict fmt, va_list ap) { int width; int size; - int alloc; + int alloc = 0; int base; const unsigned char *p; int c, t; @@ -79,8 +76,13 @@ int vfscanf(FILE *restrict f, const char *restrict fmt, va_list ap) FLOCK(f); + if (!f->rpos) __toread(f); + if (!f->rpos) goto input_fail; + for (p=(const unsigned char *)fmt; *p; p++) { + alloc = 0; + if (isspace(*p)) { while (isspace(p[1])) p++; shlim(f, 0); @@ -90,15 +92,19 @@ int vfscanf(FILE *restrict f, const char *restrict fmt, va_list ap) continue; } if (*p != '%' || p[1] == '%') { - p += *p=='%'; shlim(f, 0); - c = shgetc(f); + if (*p == '%') { + p++; + while (isspace((c=shgetc(f)))); + } else { + c = shgetc(f); + } if (c!=*p) { shunget(f); if (c<0) goto input_fail; goto match_fail; } - pos++; + pos += shcnt(f); continue; } @@ -116,6 +122,8 @@ int vfscanf(FILE *restrict f, const char *restrict fmt, va_list ap) } if (*p=='m') { + wcs = 0; + s = 0; alloc = !!dest; p++; } else { @@ -265,8 +273,10 @@ int vfscanf(FILE *restrict f, const char *restrict fmt, va_list ap) if (size == SIZE_l) *(wchar_t **)dest = wcs; else *(char **)dest = s; } - if (wcs) wcs[i] = 0; - if (s) s[i] = 0; + if (t != 'c') { + if (wcs) wcs[i] = 0; + if (s) s[i] = 0; + } break; case 'p': case 'X': @@ -325,3 +335,5 @@ match_fail: FUNLOCK(f); return matches; } + +weak_alias(vfscanf,__isoc99_vfscanf);