Loading...
stdio/FreeBSD/vfscanf.c Libc-1725.40.4 Libc-498
--- Libc/Libc-1725.40.4/stdio/FreeBSD/vfscanf.c
+++ Libc/Libc-498/stdio/FreeBSD/vfscanf.c
@@ -13,6 +13,10 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *	This product includes software developed by the University of
+ *	California, Berkeley and its contributors.
  * 4. Neither the name of the University nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
@@ -30,16 +34,11 @@
  * SUCH DAMAGE.
  */
 
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wcomma"
-
 #if defined(LIBC_SCCS) && !defined(lint)
 static char sccsid[] = "@(#)vfscanf.c	8.1 (Berkeley) 6/4/93";
 #endif /* LIBC_SCCS and not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/vfscanf.c,v 1.43 2009/01/19 06:19:51 das Exp $");
-
-#include "xlocale_private.h"
+__FBSDID("$FreeBSD: src/lib/libc/stdio/vfscanf.c,v 1.37 2004/05/02 10:55:05 das Exp $");
 
 #include "namespace.h"
 #include <ctype.h>
@@ -51,13 +50,11 @@
 #include <string.h>
 #include <wchar.h>
 #include <wctype.h>
-#include <pthread.h>
 #include "un-namespace.h"
 
 #include "collate.h"
 #include "libc_private.h"
 #include "local.h"
-#include "libc_hooks_impl.h"
 
 #ifndef NO_FLOATING_POINT
 #include <locale.h>
@@ -100,10 +97,10 @@
 #define	CT_INT		3	/* %[dioupxX] conversion */
 #define	CT_FLOAT	4	/* %[efgEFG] conversion */
 
-static const u_char *__sccl(char *, const u_char *, locale_t);
-#ifndef NO_FLOATING_POINT
-static int parsefloat(FILE *, char **, size_t, locale_t);
-#endif
+static const u_char *__sccl(char *, const u_char *);
+static int parsefloat(FILE *, char *, char *);
+
+int __scanfdebug = 0;
 
 __weak_reference(__vfscanf, vfscanf);
 
@@ -111,37 +108,21 @@
  * __vfscanf - MT-safe version
  */
 int
-__vfscanf(FILE * __restrict fp, char const * __restrict fmt0, va_list ap)
+__vfscanf(FILE *fp, char const *fmt0, va_list ap)
 {
 	int ret;
 
-	libc_hooks_will_write(fp, sizeof(*fp));
-
 	FLOCKFILE(fp);
-	ret = __svfscanf_l(fp, __current_locale(), fmt0, ap);
+	ret = __svfscanf(fp, fmt0, ap);
 	FUNLOCKFILE(fp);
 	return (ret);
 }
 
-int
-vfscanf_l(FILE * __restrict fp, locale_t loc, char const * __restrict fmt0, va_list ap)
-{
-	int ret;
-
-	libc_hooks_will_write(fp, sizeof(*fp));
-
-	NORMALIZE_LOCALE(loc);
-	FLOCKFILE(fp);
-	ret = __svfscanf_l(fp, loc, fmt0, ap);
-	FUNLOCKFILE(fp);
-	return (ret);
-}
-
 /*
  * __svfscanf - non-MT-safe version of __vfscanf
  */
-__private_extern__ int
-__svfscanf_l(FILE * __restrict fp, locale_t loc, const char * __restrict fmt0, va_list ap)
+int
+__svfscanf(FILE *fp, const char *fmt0, va_list ap)
 {
 	const u_char *fmt = (const u_char *)fmt0;
 	int c;			/* character from format, or conversion */
@@ -151,46 +132,37 @@
 	int flags;		/* flags as defined above */
 	char *p0;		/* saves original value of p when necessary */
 	int nassigned;		/* number of fields assigned */
+	int nconversions;	/* number of conversions */
 	int nread;		/* number of characters consumed from fp */
 	int base;		/* base argument to conversion function */
 	char ccltab[256];	/* character class table for %[...] */
 	char buf[BUF];		/* buffer for numeric and mb conversions */
 	wchar_t *wcp;		/* handy wide character pointer */
+	wchar_t *wcp0;		/* saves original value of wcp */
 	size_t nconv;		/* length of multibyte sequence converted */
-	int index;		/* %index$, zero if unset */
-	va_list ap_orig;	/* to reset ap to first argument */
 	static const mbstate_t initial;
 	mbstate_t mbs;
-	int mb_cur_max;
 
 	/* `basefix' is used to avoid `if' tests in the integer scanner */
-	static const short basefix[17] =
+	static short basefix[17] =
 		{ 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
 
-	libc_hooks_will_write(loc, sizeof(*loc));
-	libc_hooks_will_read_cstring(fmt0);
-
-	NORMALIZE_LOCALE(loc);
-	mb_cur_max = MB_CUR_MAX_L(loc);
 	ORIENT(fp, -1);
 
 	nassigned = 0;
+	nconversions = 0;
 	nread = 0;
-	va_copy(ap_orig, ap);
 	for (;;) {
 		c = *fmt++;
 		if (c == 0)
 			return (nassigned);
-		if (isspace_l(c, loc)) {
-			while ((fp->_r > 0 || __srefill(fp) == 0) && isspace_l(*fp->_p, loc))
+		if (isspace(c)) {
+			while ((fp->_r > 0 || __srefill(fp) == 0) && isspace(*fp->_p))
 				nread++, fp->_r--, fp->_p++;
 			continue;
 		}
-		if (c != '%') {
-			if (fp->_r <= 0 && __srefill(fp))
-				goto input_failure;
+		if (c != '%')
 			goto literal;
-		}
 		width = 0;
 		flags = 0;
 		/*
@@ -200,35 +172,15 @@
 again:		c = *fmt++;
 		switch (c) {
 		case '%':
-			/* Consume leading white space */
-			for(;;) {
-				if (fp->_r <= 0 && __srefill(fp))
-					goto input_failure;
-				if (!isspace_l(*fp->_p, loc))
-					break;
-				nread++;
-				fp->_r--;
-				fp->_p++;
-			}
 literal:
+			if (fp->_r <= 0 && __srefill(fp))
+				goto input_failure;
 			if (*fp->_p != c)
 				goto match_failure;
 			fp->_r--, fp->_p++;
 			nread++;
 			continue;
 
-		case '$':
-			index = width;
-			if (index < 1 || index > NL_ARGMAX || fmt[-3] != '%') {
-				goto input_failure;
-			}
-			width = 0;
-			va_end(ap);
-			va_copy(ap, ap_orig); /* reset to %1$ */
-			for (; index > 1; index--) {
-				va_arg(ap, void*);
-			}
-			goto again;
 		case '*':
 			flags |= SUPPRESS;
 			goto again;
@@ -315,7 +267,7 @@
 			break;
 
 		case '[':
-			fmt = __sccl(ccltab, fmt, loc);
+			fmt = __sccl(ccltab, fmt);
 			flags |= NOSKIP;
 			c = CT_CCL;
 			break;
@@ -336,31 +288,27 @@
 			break;
 
 		case 'n':
-		{
+			nconversions++;
 			if (flags & SUPPRESS)	/* ??? */
 				continue;
-			void *ptr = va_arg(ap, void *);
-			if (ptr == NULL) {
-				continue;
-			} else if (flags & SHORTSHORT) {
-				LIBC_HOOKS_WRITE_SIMPLE_TYPE(ptr, char, nread);
-			} else if (flags & SHORT) {
-				LIBC_HOOKS_WRITE_SIMPLE_TYPE(ptr, short, nread);
-			} else if (flags & LONG) {
-				LIBC_HOOKS_WRITE_SIMPLE_TYPE(ptr, long, nread);
-			} else if (flags & LONGLONG) {
-				LIBC_HOOKS_WRITE_SIMPLE_TYPE(ptr, long long, nread);
-			} else if (flags & INTMAXT) {
-				LIBC_HOOKS_WRITE_SIMPLE_TYPE(ptr, intmax_t, nread);
-			} else if (flags & SIZET) {
-				LIBC_HOOKS_WRITE_SIMPLE_TYPE(ptr, size_t, nread);
-			} else if (flags & PTRDIFFT) {
-				LIBC_HOOKS_WRITE_SIMPLE_TYPE(ptr, ptrdiff_t, nread);
-			} else {
-				LIBC_HOOKS_WRITE_SIMPLE_TYPE(ptr, int, nread);
-			}
+			if (flags & SHORTSHORT)
+				*va_arg(ap, char *) = nread;
+			else if (flags & SHORT)
+				*va_arg(ap, short *) = nread;
+			else if (flags & LONG)
+				*va_arg(ap, long *) = nread;
+			else if (flags & LONGLONG)
+				*va_arg(ap, long long *) = nread;
+			else if (flags & INTMAXT)
+				*va_arg(ap, intmax_t *) = nread;
+			else if (flags & SIZET)
+				*va_arg(ap, size_t *) = nread;
+			else if (flags & PTRDIFFT)
+				*va_arg(ap, ptrdiff_t *) = nread;
+			else
+				*va_arg(ap, int *) = nread;
 			continue;
-		}
+
 		default:
 			goto match_failure;
 
@@ -382,7 +330,7 @@
 		 * that suppress this.
 		 */
 		if ((flags & NOSKIP) == 0) {
-			while (isspace_l(*fp->_p, loc)) {
+			while (isspace(*fp->_p)) {
 				nread++;
 				if (--fp->_r > 0)
 					fp->_p++;
@@ -405,7 +353,6 @@
 			/* scan arbitrary characters (sets NOSKIP) */
 			if (width == 0)
 				width = 1;
-			// libc_hooks: TBD checking of wchar_t
 			if (flags & LONG) {
 				if ((flags & SUPPRESS) == 0)
 					wcp = va_arg(ap, wchar_t *);
@@ -413,7 +360,7 @@
 					wcp = NULL;
 				n = 0;
 				while (width != 0) {
-					if (n == mb_cur_max) {
+					if (n == MB_CUR_MAX) {
 						fp->_flags |= __SERR;
 						goto input_failure;
 					}
@@ -421,7 +368,7 @@
 					fp->_p++;
 					fp->_r--;
 					mbs = initial;
-					nconv = mbrtowc_l(wcp, buf, n, &mbs, loc);
+					nconv = mbrtowc(wcp, buf, n, &mbs);
 					if (nconv == (size_t)-1) {
 						fp->_flags |= __SERR;
 						goto input_failure;
@@ -466,8 +413,7 @@
 				}
 				nread += sum;
 			} else {
-				// libc_hooks: __fread() will validate
-				size_t r = __fread((void *)va_arg(ap, char *), 1,
+				size_t r = fread((void *)va_arg(ap, char *), 1,
 				    width, fp);
 
 				if (r == 0)
@@ -475,6 +421,7 @@
 				nread += r;
 				nassigned++;
 			}
+			nconversions++;
 			break;
 
 		case CT_CCL:
@@ -482,19 +429,18 @@
 			if (width == 0)
 				width = (size_t)~0;	/* `infinity' */
 			/* take only those things in the class */
-			// libsanitiers: TBD checking of wchar_t
 			if (flags & LONG) {
 				wchar_t twc;
 				int nchars;
 
 				if ((flags & SUPPRESS) == 0)
-					wcp = va_arg(ap, wchar_t *);
+					wcp = wcp0 = va_arg(ap, wchar_t *);
 				else
-					wcp = &twc;
+					wcp = wcp0 = &twc;
 				n = 0;
 				nchars = 0;
 				while (width != 0) {
-					if (n == mb_cur_max) {
+					if (n == MB_CUR_MAX) {
 						fp->_flags |= __SERR;
 						goto input_failure;
 					}
@@ -502,20 +448,16 @@
 					fp->_p++;
 					fp->_r--;
 					mbs = initial;
-					/*
-					 * Copy the character to destination only
-					 * after all the checks are completed
-					 */
-					nconv = mbrtowc_l(&twc, buf, n, &mbs, loc);
+					nconv = mbrtowc(wcp, buf, n, &mbs);
 					if (nconv == (size_t)-1) {
 						fp->_flags |= __SERR;
 						goto input_failure;
 					}
 					if (nconv == 0)
-						twc = L'\0';
+						*wcp = L'\0';
 					if (nconv != (size_t)-2) {
-						if (wctob_l(twc, loc) != EOF &&
-							!ccltab[wctob_l(twc, loc)]) {
+						if (wctob(*wcp) != EOF &&
+						    !ccltab[wctob(*wcp)]) {
 							while (n != 0) {
 								n--;
 								__ungetc(buf[n],
@@ -525,10 +467,8 @@
 						}
 						nread += n;
 						width--;
-						if (!(flags & SUPPRESS)) {
-							*wcp = twc;
+						if (!(flags & SUPPRESS))
 							wcp++;
-						}
 						nchars++;
 						n = 0;
 					}
@@ -583,17 +523,15 @@
 					goto match_failure;
 				*p = 0;
 				nassigned++;
-				// libc_hooks: Doing a post-check for efficiency
-				libc_hooks_will_read_cstring(p0);
 			}
 			nread += n;
+			nconversions++;
 			break;
 
 		case CT_STRING:
 			/* like CCL, but zero-length string OK, & no NOSKIP */
 			if (width == 0)
 				width = (size_t)~0;
-			// libsanitiers: TBD checking of wchar_t
 			if (flags & LONG) {
 				wchar_t twc;
 
@@ -602,8 +540,8 @@
 				else
 					wcp = &twc;
 				n = 0;
-				while (width != 0) {
-					if (n == mb_cur_max) {
+				while (!isspace(*fp->_p) && width != 0) {
+					if (n == MB_CUR_MAX) {
 						fp->_flags |= __SERR;
 						goto input_failure;
 					}
@@ -611,7 +549,7 @@
 					fp->_p++;
 					fp->_r--;
 					mbs = initial;
-					nconv = mbrtowc_l(wcp, buf, n, &mbs, loc);
+					nconv = mbrtowc(wcp, buf, n, &mbs);
 					if (nconv == (size_t)-1) {
 						fp->_flags |= __SERR;
 						goto input_failure;
@@ -619,7 +557,7 @@
 					if (nconv == 0)
 						*wcp = L'\0';
 					if (nconv != (size_t)-2) {
-						if (iswspace_l(*wcp, loc)) {
+						if (iswspace(*wcp)) {
 							while (n != 0) {
 								n--;
 								__ungetc(buf[n],
@@ -647,7 +585,7 @@
 				}
 			} else if (flags & SUPPRESS) {
 				n = 0;
-				while (!isspace_l(*fp->_p, loc)) {
+				while (!isspace(*fp->_p)) {
 					n++, fp->_r--, fp->_p++;
 					if (--width == 0)
 						break;
@@ -657,7 +595,7 @@
 				nread += n;
 			} else {
 				p0 = p = va_arg(ap, char *);
-				while (!isspace_l(*fp->_p, loc)) {
+				while (!isspace(*fp->_p)) {
 					fp->_r--;
 					*p++ = *fp->_p++;
 					if (--width == 0)
@@ -668,9 +606,8 @@
 				*p = 0;
 				nread += p - p0;
 				nassigned++;
-				// libc_hooks: Doing a post-check for efficiency
-				libc_hooks_will_read_cstring(p0);
-			}
+			}
+			nconversions++;
 			continue;
 
 		case CT_INT:
@@ -801,68 +738,66 @@
 
 				*p = 0;
 				if ((flags & UNSIGNED) == 0)
-				    res = strtoimax_l(buf, (char **)NULL, base, loc);
+				    res = strtoimax(buf, (char **)NULL, base);
 				else
-				    res = strtoumax_l(buf, (char **)NULL, base, loc);
-				void *ptr = va_arg(ap, void *);
-				if (flags & POINTER) {
-					LIBC_HOOKS_WRITE_SIMPLE_TYPE(ptr, uintptr_t, res);
-				} else if (flags & SHORTSHORT) {
-					LIBC_HOOKS_WRITE_SIMPLE_TYPE(ptr, char, res);
-				} else if (flags & SHORT) {
-					LIBC_HOOKS_WRITE_SIMPLE_TYPE(ptr, short, res);
-				} else if (flags & LONG) {
-					LIBC_HOOKS_WRITE_SIMPLE_TYPE(ptr, long, res);
-				} else if (flags & LONGLONG) {
-					LIBC_HOOKS_WRITE_SIMPLE_TYPE(ptr, long long, res);
-				} else if (flags & INTMAXT) {
-					LIBC_HOOKS_WRITE_SIMPLE_TYPE(ptr, intmax_t, res);
-				} else if (flags & PTRDIFFT) {
-					LIBC_HOOKS_WRITE_SIMPLE_TYPE(ptr, ptrdiff_t, res);
-				} else if (flags & SIZET) {
-					LIBC_HOOKS_WRITE_SIMPLE_TYPE(ptr, size_t, res);
-				} else {
-					LIBC_HOOKS_WRITE_SIMPLE_TYPE(ptr, int, res);
-				}
+				    res = strtoumax(buf, (char **)NULL, base);
+				if (flags & POINTER)
+					*va_arg(ap, void **) =
+							(void *)(uintptr_t)res;
+				else if (flags & SHORTSHORT)
+					*va_arg(ap, char *) = res;
+				else if (flags & SHORT)
+					*va_arg(ap, short *) = res;
+				else if (flags & LONG)
+					*va_arg(ap, long *) = res;
+				else if (flags & LONGLONG)
+					*va_arg(ap, long long *) = res;
+				else if (flags & INTMAXT)
+					*va_arg(ap, intmax_t *) = res;
+				else if (flags & PTRDIFFT)
+					*va_arg(ap, ptrdiff_t *) = res;
+				else if (flags & SIZET)
+					*va_arg(ap, size_t *) = res;
+				else
+					*va_arg(ap, int *) = res;
 				nassigned++;
 			}
 			nread += p - buf;
+			nconversions++;
 			break;
 
 #ifndef NO_FLOATING_POINT
 		case CT_FLOAT:
-		{
-			char *pbuf;
 			/* scan a floating point number as if by strtod */
-			if ((width = parsefloat(fp, &pbuf, width, loc)) == 0)
+			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) {
-				void *ptr = va_arg(ap, void *);
 				if (flags & LONGDBL) {
-					LIBC_HOOKS_WRITE_SIMPLE_TYPE(ptr, long double, strtold_l(pbuf, &p, loc));
+					long double res = strtold(buf, &p);
+					*va_arg(ap, long double *) = res;
 				} else if (flags & LONG) {
-					LIBC_HOOKS_WRITE_SIMPLE_TYPE(ptr, double, strtod_l(pbuf, &p, loc));
+					double res = strtod(buf, &p);
+					*va_arg(ap, double *) = res;
 				} else {
-					LIBC_HOOKS_WRITE_SIMPLE_TYPE(ptr, float, strtof_l(pbuf, &p, loc));
-				}
+					float res = strtof(buf, &p);
+					*va_arg(ap, float *) = res;
+				}
+				if (__scanfdebug && p - buf != width)
+					abort();
 				nassigned++;
 			}
 			nread += width;
-			break;
-		}
+			nconversions++;
+			break;
 #endif /* !NO_FLOATING_POINT */
 		}
 	}
 input_failure:
-	return (nassigned ? nassigned : EOF);
+	return (nconversions != 0 ? nassigned : EOF);
 match_failure:
 	return (nassigned);
-}
-
-int
-__svfscanf(FILE * __restrict fp, const char * __restrict fmt0, va_list ap)
-{
-	return __svfscanf_l(fp, __current_locale(), fmt0, ap);
 }
 
 /*
@@ -872,7 +807,9 @@
  * considered part of the scanset.
  */
 static const u_char *
-__sccl(char *tab, const u_char *fmt, locale_t loc)
+__sccl(tab, fmt)
+	char *tab;
+	const u_char *fmt;
 {
 	int c, n, v, i;
 
@@ -908,7 +845,6 @@
 			return (fmt - 1);
 
 		case '-':
-		{
 			/*
 			 * A scanset of the form
 			 *	[01+-]
@@ -929,21 +865,23 @@
 			 */
 			n = *fmt;
 			if (n == ']'
-			    || (XLOCALE_COLLATE(loc)->__collate_load_error ?
-			    n < c : __collate_range_cmp (n, c, loc) < 0)) {
+			    || (__collate_load_error ? n < c :
+				__collate_range_cmp (n, c) < 0
+			       )
+			   ) {
 				c = '-';
 				break;	/* resume the for(;;) */
 			}
 			fmt++;
 			/* fill in the range */
-			if (XLOCALE_COLLATE(loc)->__collate_load_error) {
+			if (__collate_load_error) {
 				do {
 					tab[++c] = v;
 				} while (c < n);
 			} else {
 				for (i = 0; i < 256; i ++)
-					if (   __collate_range_cmp (c, i, loc) < 0
-					    && __collate_range_cmp (i, n, loc) <= 0
+					if (   __collate_range_cmp (c, i) < 0
+					    && __collate_range_cmp (i, n) <= 0
 					   )
 						tab[i] = v;
 			}
@@ -963,7 +901,7 @@
 				return (fmt);
 #endif
 			break;
-		}
+
 		case ']':		/* end of scanset */
 			return (fmt);
 
@@ -976,74 +914,19 @@
 }
 
 #ifndef NO_FLOATING_POINT
-/*
- * Maintain a per-thread parsefloat buffer, shared by __svfscanf_l and
- * __vfwscanf.
- */
-#ifdef BUILDING_VARIANT
-extern char *__parsefloat_buf(size_t s);
-#else /* !BUILDING_VARIANT */
-__private_extern__ char *
-__parsefloat_buf(size_t s)
-{
-	char *b;
-	static pthread_key_t    parsefloat_tsd_key = (pthread_key_t)-1;
-	static pthread_mutex_t  parsefloat_tsd_lock = PTHREAD_MUTEX_INITIALIZER;
-	static size_t bsiz = 0;
-
-	if (parsefloat_tsd_key == (pthread_key_t)-1) {
-		pthread_mutex_lock(&parsefloat_tsd_lock);
-		if (parsefloat_tsd_key == (pthread_key_t)-1) {
-			parsefloat_tsd_key = __LIBC_PTHREAD_KEY_PARSEFLOAT;
-			pthread_key_init_np(parsefloat_tsd_key, free);
-		}
-		pthread_mutex_unlock(&parsefloat_tsd_lock);
-	}
-	if ((b = (char *)pthread_getspecific(parsefloat_tsd_key)) == NULL) {
-		bsiz = s > BUF ? s : BUF;
-		b = (char *)malloc(bsiz);
-		if (b == NULL) {
-			bsiz = 0;
-			return NULL;
-		}
-		pthread_setspecific(parsefloat_tsd_key, b);
-		return b;
-	}
-	if (s > bsiz) {
-		b = (char *)reallocf(b, s);
-		pthread_setspecific(parsefloat_tsd_key, b);
-		if (b == NULL) {
-			bsiz = 0;
-			return NULL;
-		}
-		bsiz = s;
-	}
-	return b;
-}
-#endif /* BUILDING_VARIANT */
-
 static int
-parsefloat(FILE *fp, char **buf, size_t width, locale_t loc)
+parsefloat(FILE *fp, char *buf, char *end)
 {
 	char *commit, *p;
-	int infnanpos = 0, decptpos = 0;
+	int infnanpos = 0;
 	enum {
-		S_START, S_GOTSIGN, S_INF, S_NAN, S_DONE, S_MAYBEHEX,
-		S_DIGITS, S_DECPT, S_FRAC, S_EXP, S_EXPDIGITS
+		S_START, S_GOTSIGN, S_INF, S_NAN, S_MAYBEHEX,
+		S_DIGITS, S_FRAC, S_EXP, S_EXPDIGITS
 	} state = S_START;
 	unsigned char c;
-	const char *decpt = localeconv_l(loc)->decimal_point;
+	char decpt = *localeconv()->decimal_point;
 	_Bool gotmantdig = 0, ishex = 0;
-	char *b;
-	char *e;
-	size_t s;
-
-	s = (width == 0 ? BUF : (width + 1));
-	if ((b = __parsefloat_buf(s)) == NULL) {
-		*buf = NULL;
-		return 0;
-	}
-	e = b + (s - 1);
+
 	/*
 	 * We set commit = p whenever the string we have read so far
 	 * constitutes a valid representation of a floating point
@@ -1053,8 +936,8 @@
 	 * always necessary to read at least one character that doesn't
 	 * match; thus, we can't short-circuit "infinity" or "nan(...)".
 	 */
-	commit = b - 1;
-	for (p = b; width == 0 || p < e; ) {
+	commit = buf - 1;
+	for (p = buf; p < end; ) {
 		c = *fp->_p;
 reswitch:
 		switch (state) {
@@ -1094,6 +977,8 @@
 			break;
 		case S_NAN:
 			switch (infnanpos) {
+			case -1:	/* XXX kludge to deal with nan(...) */
+				goto parsedone;
 			case 0:
 				if (c != 'A' && c != 'a')
 					goto parsedone;
@@ -1111,15 +996,13 @@
 			default:
 				if (c == ')') {
 					commit = p;
-					state = S_DONE;
-				} else if (!isalnum_l(c, loc) && c != '_')
+					infnanpos = -2;
+				} else if (!isalnum(c) && c != '_')
 					goto parsedone;
 				break;
 			}
 			infnanpos++;
 			break;
-		case S_DONE:
-			goto parsedone;
 		case S_MAYBEHEX:
 			state = S_DIGITS;
 			if (c == 'X' || c == 'x') {
@@ -1130,34 +1013,16 @@
 				goto reswitch;
 			}
 		case S_DIGITS:
-			if ((ishex && isxdigit_l(c, loc)) || isdigit_l(c, loc)) {
+			if ((ishex && isxdigit(c)) || isdigit(c))
 				gotmantdig = 1;
+			else {
+				state = S_FRAC;
+				if (c != decpt)
+					goto reswitch;
+			}
+			if (gotmantdig)
 				commit = p;
-				break;
-			} else {
-				state = S_DECPT;
-				goto reswitch;
-			}
-		case S_DECPT:
-			if (c == decpt[decptpos]) {
-				if (decpt[++decptpos] == '\0') {
-					/* We read the complete decpt seq. */
-					state = S_FRAC;
-					if (gotmantdig)
-						commit = p;
-				}
-				break;
-			} else if (!decptpos) {
-				/* We didn't read any decpt characters. */
-				state = S_FRAC;
-				goto reswitch;
-			} else {
-				/*
-				 * We read part of a multibyte decimal point,
-				 * but the rest is invalid, so bail.
-				 */
-				goto parsedone;
-			}
+			break;
 		case S_FRAC:
 			if (((c == 'E' || c == 'e') && !ishex) ||
 			    ((c == 'P' || c == 'p') && ishex)) {
@@ -1165,7 +1030,7 @@
 					goto parsedone;
 				else
 					state = S_EXP;
-			} else if ((ishex && isxdigit_l(c, loc)) || isdigit_l(c, loc)) {
+			} else if ((ishex && isxdigit(c)) || isdigit(c)) {
 				commit = p;
 				gotmantdig = 1;
 			} else
@@ -1178,26 +1043,13 @@
 			else
 				goto reswitch;
 		case S_EXPDIGITS:
-			if (isdigit_l(c, loc))
+			if (isdigit(c))
 				commit = p;
 			else
 				goto parsedone;
 			break;
 		default:
-			LIBC_ABORT("unknown state %d", state);
-		}
-		if (p >= e) {
-			ssize_t diff = (p - b);
-			ssize_t com = (commit - b);
-			s += BUF;
-			b = __parsefloat_buf(s);
-			if (b == NULL) {
-				*buf = NULL;
-				return 0;
-			}
-			e = b + (s - 1);
-			p = b + diff;
-			commit = b + com;
+			abort();
 		}
 		*p++ = c;
 		if (--fp->_r > 0)
@@ -1210,8 +1062,6 @@
 	while (commit < --p)
 		__ungetc(*(u_char *)p, fp);
 	*++commit = '\0';
-	*buf = b;
-	return (commit - b);
+	return (commit - buf);
 }
 #endif
-#pragma clang diagnostic push