Skip to content

Commit

Permalink
util: fall back to strtod if no locale in libc
Browse files Browse the repository at this point in the history
uClibc-ng has experimental locale support but it's incomplete and
disabled by default, for example in Hardened Gentoo.

Fixes #63
  • Loading branch information
nykula committed Dec 22, 2018
1 parent 5f39f0b commit 99bb0ee
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/libinput-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 99bb0ee

Please sign in to comment.