aboutsummaryrefslogtreecommitdiffstats
path: root/src/util/strtod.c
diff options
context:
space:
mode:
authorErik Faye-Lund <[email protected]>2015-06-28 14:51:08 +0200
committerMatt Turner <[email protected]>2015-06-29 09:06:40 -0700
commitc61bc6ed844b39e600cc64e3e552c7bf1894d7ba (patch)
tree9339b5149a583451c69d4ddd0117508bd94244ad /src/util/strtod.c
parentde3e323be1bdc40a2a7d724d0f3db7a81a93bbbb (diff)
util: port _mesa_strto[df] to C
_mesa_strtod and _mesa_strtof are only used from the GLSL compiler and the ARB_[vertex|fragment]_program code, meaning that the locale doesn't need to be initialized before the first OpenGL context gets initialized. So let's use explicit initialization from the one-time init code instead of depending on a C++ compiler to initialize at image-load time. Signed-off-by: Erik Faye-Lund <[email protected]> Reviewed-by: Matt Turner <[email protected]> Reviewed-by: Brian Paul <[email protected]>
Diffstat (limited to 'src/util/strtod.c')
-rw-r--r--src/util/strtod.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/util/strtod.c b/src/util/strtod.c
new file mode 100644
index 00000000000..a4a60e0404a
--- /dev/null
+++ b/src/util/strtod.c
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2010 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+#include <stdlib.h>
+
+#ifdef _GNU_SOURCE
+#include <locale.h>
+#ifdef HAVE_XLOCALE_H
+#include <xlocale.h>
+static locale_t loc;
+#endif
+#endif
+
+#include "strtod.h"
+
+
+void
+_mesa_locale_init(void)
+{
+#if defined(_GNU_SOURCE) && defined(HAVE_XLOCALE_H)
+ loc = newlocale(LC_CTYPE_MASK, "C", NULL);
+#endif
+}
+
+/**
+ * Wrapper around strtod which uses the "C" locale so the decimal
+ * point is always '.'
+ */
+double
+_mesa_strtod(const char *s, char **end)
+{
+#if defined(_GNU_SOURCE) && defined(HAVE_XLOCALE_H)
+ return strtod_l(s, end, loc);
+#else
+ return strtod(s, end);
+#endif
+}
+
+
+/**
+ * Wrapper around strtof which uses the "C" locale so the decimal
+ * point is always '.'
+ */
+float
+_mesa_strtof(const char *s, char **end)
+{
+#if defined(_GNU_SOURCE) && defined(HAVE_XLOCALE_H)
+ return strtof_l(s, end, loc);
+#elif defined(HAVE_STRTOF)
+ return strtof(s, end);
+#else
+ return (float) strtod(s, end);
+#endif
+}