From 47b6d3f343e62032508f100d95214514de623db3 Mon Sep 17 00:00:00 2001 From: tjr Date: Wed, 7 Apr 2004 09:47:56 +0000 Subject: Prepare to handle state-dependent encodings. This mainly involves not taking shortcuts when it comes to storing and passing around conversion states. --- lib/libc/locale/wcstod.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'lib/libc/locale/wcstod.c') diff --git a/lib/libc/locale/wcstod.c b/lib/libc/locale/wcstod.c index 1f13e2f..68df1ed 100644 --- a/lib/libc/locale/wcstod.c +++ b/lib/libc/locale/wcstod.c @@ -43,6 +43,8 @@ __FBSDID("$FreeBSD$"); double wcstod(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr) { + static const mbstate_t initial; + mbstate_t mbs; double val; char *buf, *end; const wchar_t *wcp; @@ -60,20 +62,18 @@ wcstod(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr) * the input string contains a lot of text after the number * duplicates a lot of strtod()'s functionality and slows down the * most common cases. - * - * We pass NULL as the state pointer to wcrtomb() because we don't - * support state-dependent encodings and don't want to waste time - * creating a zeroed mbstate_t that will not be used. */ wcp = nptr; - if ((len = wcsrtombs(NULL, &wcp, 0, NULL)) == (size_t)-1) { + mbs = initial; + if ((len = wcsrtombs(NULL, &wcp, 0, &mbs)) == (size_t)-1) { if (endptr != NULL) *endptr = (wchar_t *)nptr; return (0.0); } if ((buf = malloc(len + 1)) == NULL) return (0.0); - wcsrtombs(buf, &wcp, len + 1, NULL); + mbs = initial; + wcsrtombs(buf, &wcp, len + 1, &mbs); /* Let strtod() do most of the work for us. */ val = strtod(buf, &end); -- cgit v1.1