ref: c6b70222cdc837de9ff4734fbdd050b38b34d1b7
parent: 1c3ba16bc1aa24e1736574fbf3f71372c4a5a495
author: Ori Bernstein <ori@eigenstate.org>
date: Fri May 15 12:46:20 EDT 2020
Fix scans of more than one character in %[] This got broken in d8e877a89dae, where we returned 0 on the first mismatch; we want to return 0 only when we consumed no characters.
--- a/sys/src/ape/lib/ap/stdio/vfscanf.c
+++ b/sys/src/ape/lib/ap/stdio/vfscanf.c
@@ -416,7 +416,7 @@
}
if(!match(c, pat)){nungetc(c, f);
- return 0;
+ goto Done;
}
if(store)
*s++=c;
@@ -424,5 +424,5 @@
}
Done:
if(store) *s='\0';
- return 1;
+ return nn > 0;
}
--- a/sys/src/libstdio/vfscanf.c
+++ b/sys/src/libstdio/vfscanf.c
@@ -339,6 +339,7 @@
int c, nn;
register char *s;
register const char *pat;
+
pat=++fmtp;
if(*fmtp=='^') fmtp++;
if(*fmtp!='\0') fmtp++;
@@ -354,7 +355,7 @@
}
if(!match(c, pat)){nungetc(c, f);
- return 0;
+ goto Done;
}
if(store) *s++=c;
nn++;
@@ -361,5 +362,5 @@
}
Done:
if(store) *s='\0';
- return 1;
+ return nn > 0;
}
--
⑨