Fix memory leak in get_system_decimal().
[pspp-builds.git] / src / libpspp / i18n.c
index 70780eff968a6ec62c071da23229a4ebaac49fcc..db851217c80be27ae129a9c6252824929af51785 100644 (file)
 #include <localcharset.h>
 #include "xstrndup.h"
 
+#if HAVE_NL_LANGINFO
+#include <langinfo.h>
+#endif
+
 
 static char *locale = 0;
 static const char *charset;
@@ -213,3 +217,32 @@ i18n_done (void)
     }
 }
 
+
+
+
+/* Return the system local's idea of the
+   decimal seperator character */
+char
+get_system_decimal (void)
+{
+  char radix_char;
+
+  char *ol = setlocale (LC_NUMERIC, NULL);
+  setlocale (LC_NUMERIC, "");
+
+#if HAVE_NL_LANGINFO
+  radix_char = nl_langinfo (RADIXCHAR)[0];
+#else
+  {
+    char buf[10];
+    snprintf (buf, sizeof buf, "%f", 2.5);
+    radix_char = buf[1];
+  }
+#endif
+
+  /* We MUST leave LC_NUMERIC untouched, since it would
+     otherwise interfere with data_{in,out} */
+  setlocale (LC_NUMERIC, ol);
+  return radix_char;
+}
+