#include "strtod.h"
+#if defined(_GNU_SOURCE) && defined(HAVE_XLOCALE_H)
+static struct locale_initializer {
+ locale_initializer() { loc = newlocale(LC_CTYPE_MASK, "C", NULL); }
+ locale_t loc;
+} loc_init;
+#endif
/**
* Wrapper around strtod which uses the "C" locale so the decimal
_mesa_strtod(const char *s, char **end)
{
#if defined(_GNU_SOURCE) && defined(HAVE_XLOCALE_H)
- static locale_t loc = NULL;
- if (!loc) {
- loc = newlocale(LC_CTYPE_MASK, "C", NULL);
- }
- return strtod_l(s, end, loc);
+ return strtod_l(s, end, loc_init.loc);
#else
return strtod(s, end);
#endif
_mesa_strtof(const char *s, char **end)
{
#if defined(_GNU_SOURCE) && defined(HAVE_XLOCALE_H)
- static locale_t loc = NULL;
- if (!loc) {
- loc = newlocale(LC_CTYPE_MASK, "C", NULL);
- }
- return strtof_l(s, end, loc);
+ return strtof_l(s, end, loc_init.loc);
#elif defined(HAVE_STRTOF)
return strtof(s, end);
#else