summaryrefslogtreecommitdiffstats
path: root/newlib/libc/stdlib/wcstod.c
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2009-06-16 17:44:20 +0000
committerCorinna Vinschen <corinna@vinschen.de>2009-06-16 17:44:20 +0000
commit1c5e84dd0870cd463d97f2b9183a807c3f711f2f (patch)
treed85b95c8902bcc48be771c159884be1e4e154713 /newlib/libc/stdlib/wcstod.c
parent1a99b6f85a123a1430ef41a3b2ae79eef7c0f768 (diff)
downloadcygnal-1c5e84dd0870cd463d97f2b9183a807c3f711f2f.tar.gz
cygnal-1c5e84dd0870cd463d97f2b9183a807c3f711f2f.tar.bz2
cygnal-1c5e84dd0870cd463d97f2b9183a807c3f711f2f.zip
* libc/stdio/vfprintf.c (_VFPRINTF_R): Use actual length of
radix char instead of assuming length 1. * libc/stdlib/gdtoa-gethex.c: Remove use of USE_LOCALE. (gethex): Allow multibyte decimal point. Fix compiler warnings due to different signedness of pointer types. * libc/stdlib/strtod.c: Remove use of USE_LOCALE. (_strtod_r): Allow multibyte decimal point. * libc/stdlib/wcstod.c (_wcstod_r): Evaluate correct wide char endptr position if the decimal point is a multibyte char.
Diffstat (limited to 'newlib/libc/stdlib/wcstod.c')
-rw-r--r--newlib/libc/stdlib/wcstod.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/newlib/libc/stdlib/wcstod.c b/newlib/libc/stdlib/wcstod.c
index 11fb922b1..6b8be5e73 100644
--- a/newlib/libc/stdlib/wcstod.c
+++ b/newlib/libc/stdlib/wcstod.c
@@ -116,8 +116,10 @@ Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
#include <_ansi.h>
#include <errno.h>
#include <stdlib.h>
+#include <string.h>
#include <wchar.h>
#include <wctype.h>
+#include <locale.h>
#include <math.h>
double
@@ -167,9 +169,26 @@ _DEFUN (_wcstod_r, (ptr, nptr, endptr),
* where it ended, count multibyte characters to find the
* corresponding position in the wide char string.
*/
- if (endptr != NULL)
- /* XXX Assume each wide char is one byte. */
+ if (endptr != NULL) {
+ /* The only valid multibyte char in a float converted by
+ strtod/wcstod is the radix char. What we do here is,
+ figure out if the radix char was in the valid leading
+ float sequence in the incoming string. If so, the
+ multibyte float string is strlen(radix char) - 1 bytes
+ longer than the incoming wide char string has characters.
+ To fix endptr, reposition end as if the radix char was
+ just one byte long. The resulting difference (end - buf)
+ is then equivalent to the number of valid wide characters
+ in the input string. */
+ len = strlen (_localeconv_r (ptr)->decimal_point);
+ if (len > 1) {
+ char *d = strstr (buf,
+ _localeconv_r (ptr)->decimal_point);
+ if (d && d < end)
+ end -= len - 1;
+ }
*endptr = (wchar_t *)nptr + (end - buf);
+ }
_free_r(ptr, buf);