2 (C) Copyright IBM Corp. 2009
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
9 * Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11 * Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
14 * Neither the name of IBM nor the names of its contributors may be
15 used to endorse or promote products derived from this software without
16 specific prior written permission.
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 POSSIBILITY OF SUCH DAMAGE.
38 #include "../locale/setlocale.h"
41 wcstold_l (const wchar_t *__restrict nptr
, wchar_t **__restrict endptr
,
45 /* On platforms where long double is as wide as double. */
46 return wcstod_l(nptr
, endptr
, loc
);
48 #else /* This is a duplicate of the code in wcstod.c, but converted to long double. */
50 static const mbstate_t initial
;
57 while (iswspace (*nptr
))
60 /* Convert the supplied numeric wide char string to multibyte. */
63 if ((len
= _wcsnrtombs_l (_REENT
, NULL
, &wcp
, (size_t) -1, 0, &mbs
, loc
))
67 *endptr
= (wchar_t *) nptr
;
71 if ((buf
= malloc (len
+ 1)) == NULL
)
75 _wcsnrtombs_l (_REENT
, buf
, &wcp
, (size_t) -1, len
+ 1, &mbs
, loc
);
77 val
= strtold_l (buf
, &end
, loc
);
79 /* We only know where the number ended in the _multibyte_
80 representation of the string. If the caller wants to know
81 where it ended, count multibyte characters to find the
82 corresponding position in the wide char string. */
86 const char *decimal_point
= __get_numeric_locale(loc
)->decimal_point
;
87 /* The only valid multibyte char in a float converted by
88 strtold/wcstold is the radix char. What we do here is,
89 figure out if the radix char was in the valid leading
90 float sequence in the incoming string. If so, the
91 multibyte float string is strlen (radix char) - 1 bytes
92 longer than the incoming wide char string has characters.
93 To fix endptr, reposition end as if the radix char was
94 just one byte long. The resulting difference (end - buf)
95 is then equivalent to the number of valid wide characters
96 in the input string. */
97 len
= strlen (decimal_point
);
100 char *d
= strstr (buf
, decimal_point
);
106 *endptr
= (wchar_t *) nptr
+ (end
- buf
);
112 #endif /* _LDBL_EQ_DBL */
116 wcstold (const wchar_t *__restrict nptr
, wchar_t **__restrict endptr
)
119 /* On platforms where long double is as wide as double. */
120 return wcstod_l(nptr
, endptr
, __get_current_locale ());
122 return wcstold_l(nptr
, endptr
, __get_current_locale ());