Browse Source

stdlib: Use __get_numeric_locale instead of __localeconv_l for decimal_point

The string/float conversion functions need to get the locale decimal
point. Instead of calling __localeconv_l (which copies locale data
into lconv form from __get_numeric_locale), use __get_numeric_locale
directly.

Signed-off-by: Keith Packard <keithp@keithp.com>
sh3port
Keith Packard 3 years ago
committed by Corinna Vinschen
parent
commit
3b6994ec5f
  1. 4
      newlib/libc/stdlib/gdtoa-gethex.c
  2. 6
      newlib/libc/stdlib/strtod.c
  3. 6
      newlib/libc/stdlib/strtodg.c
  4. 6
      newlib/libc/stdlib/wcstod.c
  5. 5
      newlib/libc/stdlib/wcstold.c

4
newlib/libc/stdlib/gdtoa-gethex.c

@ -149,8 +149,8 @@ gethex (struct _reent *ptr, const char **sp, const FPI *fpi,
int esign, havedig, irv, k, n, nbits, up, zret;
__ULong L, lostbits, *x;
Long e, e1;
unsigned char *decimalpoint = (unsigned char *)
__localeconv_l (loc)->decimal_point;
const unsigned char *decimalpoint = (unsigned char *)
__get_numeric_locale(loc)->decimal_point;
size_t decp_len = strlen ((const char *) decimalpoint);
unsigned char decp_end = decimalpoint[decp_len - 1];

6
newlib/libc/stdlib/strtod.c

@ -263,8 +263,8 @@ _strtod_l (struct _reent *ptr, const char *__restrict s00, char **__restrict se,
#ifdef Honor_FLT_ROUNDS
int rounding;
#endif
struct lconv *lconv = __localeconv_l (loc);
int dec_len = strlen (lconv->decimal_point);
const char *decimal_point = __get_numeric_locale(loc)->decimal_point;
int dec_len = strlen (decimal_point);
delta = bs = bd = NULL;
sign = nz0 = nz = decpt = 0;
@ -344,7 +344,7 @@ _strtod_l (struct _reent *ptr, const char *__restrict s00, char **__restrict se,
else
z = 10*z + c - '0';
nd0 = nd;
if (strncmp (s, lconv->decimal_point, dec_len) == 0)
if (strncmp (s, decimal_point, dec_len) == 0)
{
decpt = 1;
c = *(s += dec_len);

6
newlib/libc/stdlib/strtodg.c

@ -419,8 +419,8 @@ _strtodg_l (struct _reent *p, const char *s00, char **se, FPI *fpi, Long *exp,
Long L;
__ULong y, z;
_Bigint *ab, *bb, *bb1, *bd, *bd0, *bs, *delta, *rvb, *rvb0;
struct lconv *lconv = __localeconv_l (loc);
int dec_len = strlen (lconv->decimal_point);
const char *decimal_point = __get_numeric_locale(loc)->decimal_point;
int dec_len = strlen (decimal_point);
irv = STRTOG_Zero;
denorm = sign = nz0 = nz = 0;
@ -479,7 +479,7 @@ _strtodg_l (struct _reent *p, const char *s00, char **se, FPI *fpi, Long *exp,
z = 10*z + c - '0';
nd0 = nd;
#ifdef USE_LOCALE
if (strncmp (s, lconv->decimal_point, dec_len) == 0)
if (strncmp (s, decimal_point, dec_len) == 0)
#else
if (c == '.')
#endif

6
newlib/libc/stdlib/wcstod.c

@ -188,6 +188,7 @@ _wcstod_l (struct _reent *ptr, const wchar_t *nptr, wchar_t **endptr,
* corresponding position in the wide char string.
*/
if (endptr != NULL) {
const char *decimal_point = __get_numeric_locale(loc)->decimal_point;
/* 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
@ -198,10 +199,9 @@ _wcstod_l (struct _reent *ptr, const wchar_t *nptr, wchar_t **endptr,
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_l (loc)->decimal_point);
len = strlen (decimal_point);
if (len > 1) {
char *d = strstr (buf,
__localeconv_l (loc)->decimal_point);
char *d = strstr (buf, decimal_point);
if (d && d < end)
end -= len - 1;
}

5
newlib/libc/stdlib/wcstold.c

@ -83,6 +83,7 @@ wcstold_l (const wchar_t *__restrict nptr, wchar_t **__restrict endptr,
if (endptr != NULL)
{
const char *decimal_point = __get_numeric_locale(loc)->decimal_point;
/* The only valid multibyte char in a float converted by
strtold/wcstold is the radix char. What we do here is,
figure out if the radix char was in the valid leading
@ -93,10 +94,10 @@ wcstold_l (const wchar_t *__restrict nptr, wchar_t **__restrict endptr,
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_l (loc)->decimal_point);
len = strlen (decimal_point);
if (len > 1)
{
char *d = strstr (buf, __localeconv_l (loc)->decimal_point);
char *d = strstr (buf, decimal_point);
if (d && d < end)
end -= len - 1;

Loading…
Cancel
Save