Browse Source

fix wide scanf to respect field width for strings

rs-1.0
Rich Felker 14 years ago
parent
commit
0072251572
  1. 11
      src/stdio/vfwscanf.c

11
src/stdio/vfwscanf.c

@ -83,7 +83,7 @@ static int in_set(const wchar_t *set, int c)
#undef ungetwc #undef ungetwc
#define ungetwc(c,f) \ #define ungetwc(c,f) \
((f)->rend && (c)<128 ? *--(f)->rpos : ungetwc((c),(f))) ((f)->rend && (c)<128U ? *--(f)->rpos : ungetwc((c),(f)))
#endif #endif
int vfwscanf(FILE *f, const wchar_t *fmt, va_list ap) int vfwscanf(FILE *f, const wchar_t *fmt, va_list ap)
@ -215,19 +215,22 @@ int vfwscanf(FILE *f, const wchar_t *fmt, va_list ap)
case 's': case 's':
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); int l = wctomb(s?s:tmp, c);
if (l<0) goto input_fail; if (l<0) goto input_fail;
if (s) s+=l; if (s) s+=l;
pos++; pos++;
width--;
} }
if (width) ungetwc(c, f);
if (s) *s = 0; if (s) *s = 0;
break; break;
case 'S': case 'S':
wcs = dest; wcs = dest;
while (!iswspace(c=getwc(f)) && c!=EOF) while (width && !iswspace(c=getwc(f)) && c!=EOF)
pos++, *wcs++ = c; width--, pos++, *wcs++ = c;
if (width) ungetwc(c, f);
if (wcs) *wcs = 0; if (wcs) *wcs = 0;
break; break;

Loading…
Cancel
Save