1 --- wcstod.c.orig 2007-03-16 01:15:20.000000000 -0700
2 +++ wcstod.c 2007-03-16 03:03:41.000000000 -0700
5 __FBSDID("$FreeBSD: src/lib/libc/locale/wcstod.c,v 1.4 2004/04/07 09:47:56 tjr Exp $");
7 +#include "xlocale_private.h"
15 * Convert a string to a double-precision number.
17 * for at least the digits, radix character and letters.
20 -wcstod(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr)
21 +wcstod_l(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr,
24 static const mbstate_t initial;
32 + char mb[MB_CUR_MAX + 1];
33 + const wchar_t *nptr0 = nptr;
34 + const wchar_t *first;
36 - while (iswspace(*nptr))
37 + NORMALIZE_LOCALE(loc);
38 + ctype = __numeric_ctype(loc);
40 + while (iswspace_l(*nptr, ctype))
44 - * Convert the supplied numeric wide char. string to multibyte.
46 - * We could attempt to find the end of the numeric portion of the
47 - * wide char. string to avoid converting unneeded characters but
48 - * choose not to bother; optimising the uncommon case where
49 - * the input string contains a lot of text after the number
50 - * duplicates a lot of strtod()'s functionality and slows down the
51 - * most common cases.
55 - if ((len = wcsrtombs(NULL, &wcp, 0, &mbs)) == (size_t)-1) {
57 - *endptr = (wchar_t *)nptr;
60 - if ((buf = malloc(len + 1)) == NULL)
61 + if ((b = _simple_salloc()) == NULL)
66 - wcsrtombs(buf, &wcp, len + 1, &mbs);
67 + while (*nptr && (len = wcrtomb_l(mb, *nptr, &mbs, ctype)) != (size_t)-1) {
69 + if (_simple_sappend(b, mb) < 0) { /* no memory */
76 /* Let strtod() do most of the work for us. */
77 - val = strtod(buf, &end);
78 + buf = _simple_string(b);
79 + val = strtod_l(buf, &end, loc);
82 * We only know where the number ended in the _multibyte_
86 /* XXX Assume each wide char is one byte. */
87 - *endptr = (wchar_t *)nptr + (end - buf);
88 + *endptr = (end == buf) ? (wchar_t *)nptr0 : ((wchar_t *)first + (end - buf));
97 +wcstod(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr)
99 + return wcstod_l(nptr, endptr, __current_locale());