mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-03-03 06:40:38 +01:00
util: fall back to strtod if no locale in libc
uClibc-ng has experimental locale support but it's incomplete and disabled by default, for example in Hardened Gentoo. Fixes #63
This commit is contained in:
parent
5f39f0bf6f
commit
99bb0ee7cb
1 changed files with 10 additions and 0 deletions
|
|
@ -31,7 +31,9 @@
|
|||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#ifdef HAVE_LOCALE_H
|
||||
#include <locale.h>
|
||||
#endif
|
||||
#ifdef HAVE_XLOCALE_H
|
||||
#include <xlocale.h>
|
||||
#endif
|
||||
|
|
@ -559,7 +561,9 @@ safe_atod(const char *str, double *val)
|
|||
{
|
||||
char *endptr;
|
||||
double v;
|
||||
#ifdef HAVE_LOCALE_H
|
||||
locale_t c_locale;
|
||||
#endif
|
||||
size_t slen = strlen(str);
|
||||
|
||||
/* We don't have a use-case where we want to accept hex for a double
|
||||
|
|
@ -579,6 +583,7 @@ safe_atod(const char *str, double *val)
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_LOCALE_H
|
||||
/* Create a "C" locale to force strtod to use '.' as separator */
|
||||
c_locale = newlocale(LC_NUMERIC_MASK, "C", (locale_t)0);
|
||||
if (c_locale == (locale_t)0)
|
||||
|
|
@ -587,6 +592,11 @@ safe_atod(const char *str, double *val)
|
|||
errno = 0;
|
||||
v = strtod_l(str, &endptr, c_locale);
|
||||
freelocale(c_locale);
|
||||
#else
|
||||
/* No locale support in provided libc, assume it already uses '.' */
|
||||
errno = 0;
|
||||
v = strtod(str, &endptr);
|
||||
#endif
|
||||
if (errno > 0)
|
||||
return false;
|
||||
if (str == endptr)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue