mirror of git://git.musl-libc.org/musl
handle whitespace before %% in scanf
this is mandated by C and POSIX standards and is in accordance with glibc behavior.
This commit is contained in:
parent
51bdcdc424
commit
9255dad97e
|
@ -89,15 +89,19 @@ int vfscanf(FILE *restrict f, const char *restrict fmt, va_list ap)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (*p != '%' || p[1] == '%') {
|
if (*p != '%' || p[1] == '%') {
|
||||||
p += *p=='%';
|
|
||||||
shlim(f, 0);
|
shlim(f, 0);
|
||||||
c = shgetc(f);
|
if (*p == '%') {
|
||||||
|
p++;
|
||||||
|
while (isspace((c=shgetc(f))));
|
||||||
|
} else {
|
||||||
|
c = shgetc(f);
|
||||||
|
}
|
||||||
if (c!=*p) {
|
if (c!=*p) {
|
||||||
shunget(f);
|
shunget(f);
|
||||||
if (c<0) goto input_fail;
|
if (c<0) goto input_fail;
|
||||||
goto match_fail;
|
goto match_fail;
|
||||||
}
|
}
|
||||||
pos++;
|
pos += shcnt(f);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -117,8 +117,12 @@ int vfwscanf(FILE *restrict f, const wchar_t *restrict fmt, va_list ap)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (*p != '%' || p[1] == '%') {
|
if (*p != '%' || p[1] == '%') {
|
||||||
p += *p=='%';
|
if (*p == '%') {
|
||||||
c = getwc(f);
|
p++;
|
||||||
|
while (iswspace((c=getwc(f)))) pos++;
|
||||||
|
} else {
|
||||||
|
c = getwc(f);
|
||||||
|
}
|
||||||
if (c!=*p) {
|
if (c!=*p) {
|
||||||
ungetwc(c, f);
|
ungetwc(c, f);
|
||||||
if (c<0) goto input_fail;
|
if (c<0) goto input_fail;
|
||||||
|
|
Loading…
Reference in New Issue