/* *Internal,unlockedversionofvfscanf
*/ int __svfscanf(FILE* fp, constchar* fmt0, va_list ap) { constunsignedchar* fmt = reinterpret_cast<constunsignedchar*>(fmt0); int c; /* character from format, or conversion */
size_t width; /* field width, or 0 */ char* p; wchar_t* wcp;
size_t n; int flags; /* flags as defined above */ int nassigned; /* number of fields assigned */ int nread; /* number of characters consumed from fp */ int base; /* base argument to strtoimax/strtouimax */ char ccltab[256]; /* character class table for %[...] */ char buf[BUF]; /* buffer for numeric conversions */
size_t nconv; /* length of multibyte sequence converted */
mbstate_t mbs; void* allocation = nullptr; // Allocated but unassigned result for %mc/%ms/%m[.
size_t capacity = 0; // Number of char/wchar_t units allocated in `allocation`.
_SET_ORIENTATION(fp, ORIENT_BYTES);
nassigned = 0;
nread = 0; for (;;) {
c = *fmt++; if (c == 0) return nassigned; if (isspace(c)) { while ((fp->_r > 0 || __srefill(fp) == 0) && isspace(*fp->_p)) nread++, fp->_r--, fp->_p++; continue;
} if (c != '%') goto literal;
width = 0;
flags = 0; /* *switchontheformat.continueifdone; *breakonceformattypeisderived.
*/
again:
c = *fmt++;
reswitch: switch (c) { case'%':
literal: if (fp->_r <= 0 && __srefill(fp)) goto input_failure; if (*fp->_p != c) goto match_failure;
fp->_r--, fp->_p++;
nread++; continue;
default: /* compat */ if (isupper(c)) flags |= LONG;
c = CT_INT;
base = 10; break;
}
if ((flags & ALLOCATE) != 0 && c > CT_STRING) {
__fortify_fatal("scanf 'm' only works with %%c/%%s/%%[");
} if ((flags & (ALLOCATE|SUPPRESS)) == (ALLOCATE|SUPPRESS)) {
__fortify_fatal("scanf 'm' makes no sense with '*'");
}
case CT_FLOAT: /* scan a floating point number as if by strtod */ if (width == 0 || width > sizeof(buf) - 1) width = sizeof(buf) - 1; if ((width = parsefloat(fp, buf, buf + width)) == 0) goto match_failure; if ((flags & SUPPRESS) == 0) { if (flags & LONGDBL) { longdouble res = strtold(buf, &p);
*va_arg(ap, longdouble*) = res;
} elseif (flags & LONG) { double res = strtod(buf, &p);
*va_arg(ap, double*) = res;
} else { float res = strtof(buf, &p);
*va_arg(ap, float*) = res;
} if (static_cast<size_t>(p - buf) != width) abort();
nassigned++;
}
nread += width; break;
}
}
allocation_failure:
input_failure:
free(allocation); if (nassigned == 0) nassigned = -1;
match_failure: return nassigned;
}
/* *Fillinthegiventablefromthescansetatthegivenformat *(justafter`[').Returnapointertothecharacterpastthe *closing`]'.Thetablehasa1wherevercharactersshouldbe *consideredpartofthescanset.
*/ staticconstunsignedchar* __sccl(char* tab, constunsignedchar* fmt) { int c, n, v;
/* first `clear' the whole table */
c = *fmt++; /* first char hat => negated scanset */ if (c == '^') {
v = 1; /* default => accept */
c = *fmt++; /* get new first char */
} else {
v = 0; /* default => reject */
}
memset(tab, v, 256); if (c == 0) return (fmt - 1); /* format ended before closing ] */
/* *Nowsettheentriescorrespondingtotheactualscanset *totheoppositeoftheabove. * *Thefirstcharactermaybe']'(or'-')withoutbeingspecial; *thelastcharactermaybe'-'.
*/
v = 1 - v; for (;;) {
tab[c] = v; /* take character c */
doswitch:
n = *fmt++; /* and examine the next */ switch (n) { case0: /* format ended too soon */ return (fmt - 1);
case'-': /* *Ascansetoftheform *[01+-] *isdefinedas`thedigit0,thedigit1, *thecharacter+,thecharacter-',but *theeffectofascansetsuchas *[a-zA-Z0-9] *isimplementationdefined.TheV7Unix *scanftreats`a-z'as`thelettersathrough *z',buttreats`a-a'as`thelettera,the *character-,andthelettera'. * *Forcompatibility,the`-'isnotconsiderd *todefinearangeifthecharacterfollowing *itiseitheraclosebracket(requiredbyANSI) *orisnotnumericallygreaterthanthecharacter *wejuststoredinthetable(c).
*/
n = *fmt; if (n == ']' || n < c) {
c = '-'; break; /* resume the for(;;) */
}
fmt++; do { /* fill in the range */
tab[++c] = v;
} while (c < n); #if1/* XXX another disgusting compatibility hack */ /* *Alas,theV7Unixscanfalsotreatsformats *suchas[a-c-e]as`thelettersathroughe'. *Thistooispermittedbythestandard....
*/ goto doswitch; #else
c = *fmt++; if (c == 0) return (fmt - 1); if (c == ']') return (fmt); #endif break;
case']': /* end of scanset */ return fmt;
default: /* just another character */
c = n; break;
}
} /* NOTREACHED */
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.4 Sekunden
(vorverarbeitet am 2026-06-28)
¤