projects
/
musl
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge remote-tracking branch 'nsz/review'
[musl]
/
src
/
stdio
/
vfwscanf.c
diff --git
a/src/stdio/vfwscanf.c
b/src/stdio/vfwscanf.c
index
4426a12
..
44910b4
100644
(file)
--- a/
src/stdio/vfwscanf.c
+++ b/
src/stdio/vfwscanf.c
@@
-14,6
+14,7
@@
#include "shgetc.h"
#include "intscan.h"
#include "floatscan.h"
#include "shgetc.h"
#include "intscan.h"
#include "floatscan.h"
+#include "libc.h"
#define SIZE_hh -2
#define SIZE_h -1
#define SIZE_hh -2
#define SIZE_h -1
@@
-83,10
+84,10
@@
static int in_set(const wchar_t *set, int c)
#undef ungetwc
#define ungetwc(c,f) \
#undef ungetwc
#define ungetwc(c,f) \
- ((f)->rend && (c)<128 ? *--(f)->rpos : ungetwc((c),(f)))
+ ((f)->rend && (c)<128
U
? *--(f)->rpos : ungetwc((c),(f)))
#endif
#endif
-int vfwscanf(FILE *
f, const wchar_t *
fmt, va_list ap)
+int vfwscanf(FILE *
restrict f, const wchar_t *restrict
fmt, va_list ap)
{
int width;
int size;
{
int width;
int size;
@@
-181,8
+182,11
@@
int vfwscanf(FILE *f, const wchar_t *fmt, va_list ap)
/* Transform ls,lc -> S,C */
if (size==SIZE_l && (t&15)==3) t&=~32;
/* Transform ls,lc -> S,C */
if (size==SIZE_l && (t&15)==3) t&=~32;
- if (t != 'n' && t != '[' && (t|32) != 'c') {
- while (iswspace((c=getwc(f)))) pos++;
+ if (t != 'n') {
+ if (t != '[' && (t|32) != 'c')
+ while (iswspace((c=getwc(f)))) pos++;
+ else
+ c=getwc(f);
if (c < 0) goto input_fail;
ungetwc(c, f);
}
if (c < 0) goto input_fail;
ungetwc(c, f);
}
@@
-214,20
+218,25
@@
int vfwscanf(FILE *f, const wchar_t *fmt, va_list ap)
break;
case 's':
break;
case 's':
+ if (width < 1) width = -1;
s = dest;
s = dest;
- while (!iswspace(c=getwc(f)) && c!=EOF) {
+ while (
width &&
!iswspace(c=getwc(f)) && c!=EOF) {
int l = wctomb(s?s:tmp, c);
if (l<0) goto input_fail;
if (s) s+=l;
pos++;
int l = wctomb(s?s:tmp, c);
if (l<0) goto input_fail;
if (s) s+=l;
pos++;
+ width-=(width>0);
}
}
+ if (width) ungetwc(c, f);
if (s) *s = 0;
break;
case 'S':
wcs = dest;
if (s) *s = 0;
break;
case 'S':
wcs = dest;
- while (!iswspace(c=getwc(f)) && c!=EOF)
- pos++, *wcs++ = c;
+ if (width < 1) width = -1;
+ while (width && !iswspace(c=getwc(f)) && c!=EOF)
+ width-=(width>0), pos++, *wcs++ = c;
+ if (width) ungetwc(c, f);
if (wcs) *wcs = 0;
break;
if (wcs) *wcs = 0;
break;
@@
-240,7
+249,9
@@
int vfwscanf(FILE *f, const wchar_t *fmt, va_list ap)
int gotmatch = 0;
int gotmatch = 0;
- for (;;) {
+ if (width < 1) width = -1;
+
+ while (width) {
if ((c=getwc(f))<0) break;
if (in_set(p, c) == invert)
break;
if ((c=getwc(f))<0) break;
if (in_set(p, c) == invert)
break;
@@
-252,9
+263,10
@@
int vfwscanf(FILE *f, const wchar_t *fmt, va_list ap)
if (s) s+=l;
}
pos++;
if (s) s+=l;
}
pos++;
+ width-=(width>0);
gotmatch=1;
}
gotmatch=1;
}
- ungetwc(c, f);
+
if (width)
ungetwc(c, f);
if (!gotmatch) goto match_fail;
if (!gotmatch) goto match_fail;
@@
-297,3
+309,5
@@
match_fail:
FUNLOCK(f);
return matches;
}
FUNLOCK(f);
return matches;
}
+
+weak_alias(vfwscanf,__isoc99_vfwscanf);