glsl: add new glsl_strtof() function
authorBrian Paul <brianp@vmware.com>
Wed, 23 Jan 2013 16:05:30 +0000 (09:05 -0700)
committerBrian Paul <brianp@vmware.com>
Fri, 25 Jan 2013 22:41:39 +0000 (15:41 -0700)
Note, we could alternately implement this in terms of glsl_strtod()
with a (float) cast.

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/glsl/strtod.c
src/glsl/strtod.h

index 47c1f0e..5d4346b 100644 (file)
@@ -55,3 +55,25 @@ glsl_strtod(const char *s, char **end)
    return strtod(s, end);
 #endif
 }
+
+
+/**
+ * Wrapper around strtof which uses the "C" locale so the decimal
+ * point is always '.'
+ */
+float
+glsl_strtof(const char *s, char **end)
+{
+#if defined(_GNU_SOURCE) && !defined(__CYGWIN__) && !defined(__FreeBSD__) && \
+   !defined(__HAIKU__) && !defined(__UCLIBC__)
+   static locale_t loc = NULL;
+   if (!loc) {
+      loc = newlocale(LC_CTYPE_MASK, "C", NULL);
+   }
+   return strtof_l(s, end, loc);
+#elif _XOPEN_SOURCE >= 600 || _ISOC99_SOURCE
+   return strtof(s, end);
+#else
+   return (float) strtod(s, end);
+#endif
+}
index 0cf6409..ad847db 100644 (file)
@@ -34,6 +34,9 @@ extern "C" {
 extern double
 glsl_strtod(const char *s, char **end);
 
+extern float
+glsl_strtof(const char *s, char **end);
+
 
 #ifdef __cplusplus
 }